<commit_before><?php
/**
 * BlocksSiteTreeExtension.
 *
 * @author <NAME> <<EMAIL>>
 */
class BlocksSiteTreeExtension extends SiteTreeExtension
{
	private static $db = array(
		'InheritBlockSets' => 'Boolean',
	);
	private static $many_many = array(
		'Blocks' => 'Block',
		'DisabledBlocks' => 'Block',
	);
	public static $many_many_extraFields = array(
		'Blocks' => array(
			'Sort' => 'Int',
			'BlockArea' => 'Varchar',
		),
	);
	private static $defaults = array(
		'InheritBlockSets' => 1,
	);
	private static $dependencies = array(
		'blockManager' => '%$blockManager',
	);
	public $blockManager;


	/**
	 * Check if the Blocks CMSFields should be displayed for this Page
	 *
	 * @return boolean
	 **/
	public function showBlocksFields()
	{
		$whiteList = $this->blockManager->getWhiteListedPageTypes();
		$blackList = $this->blockManager->getBlackListedPageTypes();

		if (in_array($this->owner->ClassName, $blackList)) {
			return false;
		}

		if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) {
			return false;
		}

		if (!Permission::check('BLOCK_EDIT')) {
			return false;
		}

		return true;
	}

	/**
	 * Block manager for Pages.
	 * */
	public function updateCMSFields(FieldList $fields)
	{
		if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) {
			return;
		}

		$areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);

		if ($areas && count($areas)) {
			$fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME')));
			if (BlockManager::config()->get('block_area_preview')) {
				$fields->addFieldToTab('Root.Blocks',
						LiteralField::create('PreviewLink', $this->areasPreviewButton()));
			}

			// Blocks related directly to this Page
			$gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)
				->addExisting($this->owner->class)
				//->addBulkEditing()
				->addComponent(new GridFieldOrderableRows())<commit_msg>fix blocks tab not showing in some cases. Fixes #98<commit_after><?php
/**
 * BlocksSiteTreeExtension.
 *
 * @author <NAME> <<EMAIL>>
 */
class BlocksSiteTreeExtension extends SiteTreeExtension
{
	private static $db = array(
		'InheritBlockSets' => 'Boolean',
	);
	private static $many_many = array(
		'Blocks' => 'Block',
		'DisabledBlocks' => 'Block',
	);
	public static $many_many_extraFields = array(
		'Blocks' => array(
			'Sort' => 'Int',
			'BlockArea' => 'Varchar',
		),
	);
	private static $defaults = array(
		'InheritBlockSets' => 1,
	);
	private static $dependencies = array(
		'blockManager' => '%$blockManager',
	);
	public $blockManager;


	/**
	 * Check if the Blocks CMSFields should be displayed for this Page
	 *
	 * @return boolean
	 **/
	public function showBlocksFields()
	{
		$whiteList = $this->blockManager->getWhiteListedPageTypes();
		$blackList = $this->blockManager->getBlackListedPageTypes();

		if (in_array($this->owner->ClassName, $blackList)) {
			return false;
		}

		if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) {
			return false;
		}

		if (!Permission::check('BLOCK_EDIT')) {
			return false;
		}

		return true;
	}

	/**
	 * Block manager for Pages.
	 * */
	public function updateCMSFields(FieldList $fields)
	{
		if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) {
			return;
		}

		$areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);

		if ($areas && count($areas)) {
			$fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks')));
			if (BlockManager::config()->get('block_area_preview')) {
				$fields->addFieldToTab('Root.Blocks',
						LiteralField::create('PreviewLink', $this->areasPreviewButton()));
			}

			// Blocks related directly to this Page
			$gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)
				->addExisting($this->owner->class)
				//->addBulkEditing()
				->addComponent(new GridFieldOrderableRows())
{'fraction_non_alphanumeric': 0.1695563488016318, 'fraction_numerical': 0.0010198878123406426, 'mean_word_length': 4.403581267217631, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2879001', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1263, 'n_words': 259}