Issue #2102125 followup by tim.plunkett, Gábor Hojtsy: Big Local Task Conversion.

8.0.x
Alex Pott 2013-10-25 10:16:02 -07:00
parent 2a5f1b9b17
commit 270708d58a
19 changed files with 36 additions and 40 deletions

View File

@ -26,7 +26,7 @@ class ActionLocalTasksTest extends LocalTaskIntegrationTest {
}
public function setUp() {
$this->moduleList = array('action' => 'core/modules/action/action.info.yml');
$this->moduleList = array('action' => 'core/modules/action/action.module');
parent::setUp();
}

View File

@ -26,7 +26,7 @@ class AggregatorLocalTasksTest extends LocalTaskIntegrationTest {
}
public function setUp() {
$this->moduleList = array('aggregator' => 'core/modules/aggregator/aggregator.info.yml');
$this->moduleList = array('aggregator' => 'core/modules/aggregator/aggregator.module');
parent::setUp();
}

View File

@ -5,15 +5,11 @@
* Controls the visual building blocks a page is constructed with.
*/
use Drupal\block\BlockInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Utility\NestedArray;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/**
* Denotes that a block is not enabled in any region and should not be shown.
*/
const BLOCK_REGION_NONE = -1;
/**
* Shows this block on every page except the listed pages.
*/
@ -308,15 +304,15 @@ function _block_rehash($theme = NULL) {
$region = $block->get('region');
$status = $block->status();
// Disable blocks in invalid regions.
if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
if (!empty($region) && $region != BlockInterface::BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block_id, '%region' => $region)), 'warning');
// Disabled modules are moved into the BLOCK_REGION_NONE later so no
// need to move the block to another region.
// Disabled modules are moved into the BlockInterface::BLOCK_REGION_NONE
// later so no need to move the block to another region.
$block->disable()->save();
}
// Set region to none if not enabled.
if (!$status) {
$block->set('region', BLOCK_REGION_NONE);
$block->set('region', BlockInterface::BLOCK_REGION_NONE);
$block->save();
}
}

View File

@ -27,8 +27,8 @@ class CustomBlockLocalTasksTest extends LocalTaskIntegrationTest {
public function setUp() {
$this->moduleList = array(
'block' => 'core/modules/block/block.info.yml',
'custom_block' => 'core/modules/block/custom_block/custom_block.info.yml',
'block' => 'core/modules/block/block.module',
'custom_block' => 'core/modules/block/custom_block/custom_block.module',
);
parent::setUp();
}

View File

@ -259,7 +259,7 @@ class BlockFormController extends EntityFormController {
'#title' => $this->t('Region'),
'#description' => $this->t('Select the region where this block should be displayed.'),
'#default_value' => $entity->get('region'),
'#empty_value' => BLOCK_REGION_NONE,
'#empty_value' => BlockInterface::BLOCK_REGION_NONE,
'#options' => system_region_list($theme, REGIONS_VISIBLE),
'#prefix' => '<div id="edit-block-region-wrapper">',
'#suffix' => '</div>',

View File

@ -19,6 +19,11 @@ interface BlockInterface extends ConfigEntityInterface {
*/
const BLOCK_LABEL_VISIBLE = 'visible';
/**
* Denotes that a block is not enabled in any region and should not be shown.
*/
const BLOCK_REGION_NONE = -1;
/**
* Returns the plugin instance.
*

View File

@ -155,7 +155,7 @@ class BlockListController extends ConfigEntityListController implements FormInte
$form['#attributes']['class'][] = 'clearfix';
// Add a last region for disabled blocks.
$block_regions_with_disabled = $this->regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE);
$block_regions_with_disabled = $this->regions + array(BlockInterface::BLOCK_REGION_NONE => BlockInterface::BLOCK_REGION_NONE);
$form['block_regions'] = array(
'#type' => 'value',
'#value' => $block_regions_with_disabled,
@ -219,7 +219,7 @@ class BlockListController extends ConfigEntityListController implements FormInte
),
);
$form['blocks'][$region]['title'] = array(
'#markup' => $region != BLOCK_REGION_NONE ? $title : t('Disabled'),
'#markup' => $region != BlockInterface::BLOCK_REGION_NONE ? $title : t('Disabled'),
'#wrapper_attributes' => array(
'colspan' => 5,
),
@ -263,7 +263,7 @@ class BlockListController extends ConfigEntityListController implements FormInte
$form['blocks'][$entity_id]['region-theme']['region'] = array(
'#type' => 'select',
'#default_value' => $region,
'#empty_value' => BLOCK_REGION_NONE,
'#empty_value' => BlockInterface::BLOCK_REGION_NONE,
'#title' => t('Region for @block block', array('@block' => $info['admin_label'])),
'#title_display' => 'invisible',
'#options' => $this->regions,
@ -404,7 +404,7 @@ class BlockListController extends ConfigEntityListController implements FormInte
foreach ($entities as $entity_id => $entity) {
$entity->set('weight', $form_state['values']['blocks'][$entity_id]['weight']);
$entity->set('region', $form_state['values']['blocks'][$entity_id]['region']);
if ($entity->get('region') == BLOCK_REGION_NONE) {
if ($entity->get('region') == BlockInterface::BLOCK_REGION_NONE) {
$entity->disable();
}
else {

View File

@ -71,7 +71,7 @@ class Block extends ConfigEntityBase implements BlockInterface {
*
* @var string
*/
protected $region = BLOCK_REGION_NONE;
protected $region = self::BLOCK_REGION_NONE;
/**
* The block weight.
@ -163,7 +163,7 @@ class Block extends ConfigEntityBase implements BlockInterface {
return $status;
}
// Sort by weight, unless disabled.
if ($a->get('region') != BLOCK_REGION_NONE) {
if ($a->get('region') != static::BLOCK_REGION_NONE) {
$weight = $a->get('weight') - $b->get('weight');
if ($weight) {
return $weight;

View File

@ -10,11 +10,6 @@ namespace Drupal\Tests\block;
use Drupal\block\BlockFormController;
use Drupal\Tests\UnitTestCase;
// @todo Remove once the constants are replaced with constants on classes.
if (!defined('BLOCK_REGION_NONE')) {
define('BLOCK_REGION_NONE', -1);
}
/**
* Tests the block form controller.
*

View File

@ -26,7 +26,7 @@ class BlockLocalTasksTest extends LocalTaskIntegrationTest {
}
public function setUp() {
$this->moduleList = array('block' => 'core/modules/block/block.info.yml');
$this->moduleList = array('block' => 'core/modules/block/block.module');
parent::setUp();
$config_factory = $this->getConfigFactoryStub(array('system.theme' => array(

View File

@ -27,8 +27,8 @@ class BookLocalTasksTest extends LocalTaskIntegrationTest {
public function setUp() {
$this->moduleList = array(
'book' => 'core/modules/book/book.info.yml',
'node' => 'core/modules/node/node.info.yml',
'book' => 'core/modules/book/book.module',
'node' => 'core/modules/node/node.module',
);
parent::setUp();
}

View File

@ -26,7 +26,7 @@ class ConfigLocalTasksTest extends LocalTaskIntegrationTest {
}
public function setUp() {
$this->moduleList = array('config' => 'core/modules/config/config.info.yml');
$this->moduleList = array('config' => 'core/modules/config/config.module');
parent::setUp();
}

View File

@ -120,15 +120,15 @@ class ContentTranslationLocalTasks extends DerivativeBase implements ContainerDe
* Returns the local task ID of the parent task, otherwise return FALSE.
*/
protected function getTaskFromRoute($route_name, &$local_tasks) {
$local_task = FALSE;
$parent_local_task = FALSE;
foreach ($local_tasks as $plugin_id => $local_task) {
if ($local_task['route_name'] == $route_name) {
$local_task = $plugin_id;
$parent_local_task = $plugin_id;
break;
}
}
return $local_task;
return $parent_local_task;
}
/**

View File

@ -27,8 +27,8 @@ class ContentTranslationLocalTasksTest extends LocalTaskIntegrationTest {
public function setUp() {
$this->moduleList = array(
'content_translation' => 'core/modules/content_translation/content_translation.info.yml',
'node' => 'core/modules/node/node.info.yml',
'content_translation' => 'core/modules/content_translation/content_translation.module',
'node' => 'core/modules/node/node.module',
);
parent::setUp();

View File

@ -27,7 +27,7 @@ class LanguageLocalTasks extends LocalTaskIntegrationTest {
public function setUp() {
$this->moduleList = array(
'language' => 'core/modules/language/language.info.yml',
'language' => 'core/modules/language/language.module',
);
parent::setUp();
}

View File

@ -27,7 +27,7 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTest {
public function setUp() {
$this->moduleList = array(
'locale' => 'core/modules/locale/locale.info.yml',
'locale' => 'core/modules/locale/locale.module',
);
parent::setUp();
}

View File

@ -27,8 +27,8 @@ class ShortcutLocalTasksTest extends LocalTaskIntegrationTest {
public function setUp() {
$this->moduleList = array(
'shortcut' => 'core/modules/shortcut/shortcut.info.yml',
'user' => 'core/modules/user/user.info.yml',
'shortcut' => 'core/modules/shortcut/shortcut.module',
'user' => 'core/modules/user/user.module',
);
parent::setUp();
}

View File

@ -26,7 +26,7 @@ class TaxonomyLocalTasksTest extends LocalTaskIntegrationTest {
}
public function setUp() {
$this->moduleList = array('taxonomy' => 'core/modules/taxonomy/taxonomy.info.yml');
$this->moduleList = array('taxonomy' => 'core/modules/taxonomy/taxonomy.module');
parent::setUp();
}

View File

@ -26,7 +26,7 @@ class UserLocalTasksTest extends LocalTaskIntegrationTest {
}
public function setUp() {
$this->moduleList = array('user' => 'core/modules/user/user.info.yml');
$this->moduleList = array('user' => 'core/modules/user/user.module');
parent::setUp();
}