diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 578236b..d4d6b7f 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -439,11 +439,10 @@ function block_theme_initialize($theme) { * The name of a region. * * @return - * An array of block objects, indexed with the CMI key that represents the - * configuration. If you are displaying your blocks in one or two sidebars, - * you may check whether this array is empty to see how many columns are - * going to be displayed. - * + * An array of block objects, indexed with the configuration object name + * that represents the configuration. If you are displaying your blocks in + * one or two sidebars, you may check whether this array is empty to see + * how many columns are going to be displayed. */ function block_list($region) { $blocks = &drupal_static(__FUNCTION__); @@ -464,7 +463,7 @@ function block_list($region) { * Loads a block object from the database. * * @param string $plugin_id - * The plugin id to load. + * The plugin ID to load. * @param array $conf * An optional configuration array for creating a block instance from php * instead of relying on configuration xml. @@ -529,9 +528,7 @@ function _block_get_renderable_block($element) { } /** - * Wrapper for $block->build to allow altering of blocks. - * - * @todo Move the alter invocation into a plugin method. + * Allows blocks to be altered after they are built. * * @param \Drupal\block\BlockInterface $block * The block instance. @@ -539,6 +536,8 @@ function _block_get_renderable_block($element) { * @return array $build * A renderable array of data. * - #title: The default localized title of the block. + * + * @todo Move the alter invocation into a plugin method. */ function block_build($block) { // Allow modules to modify the block before it is viewed, via either diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 9e4825d..514fa9e 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -10,8 +10,11 @@ use Drupal\Component\Plugin\PluginBase; /** - * An abstract block implementation to be inherited from to take care of many - * common block setup tasks. + * Defines a base block implementation that most blocks plugins will extend. + * + * This abstract class provides the generic block configuration form, default + * block settings, and handling for general user-defined block visibility + * settings. */ abstract class BlockBase extends PluginBase implements BlockInterface { @@ -89,6 +92,9 @@ public function accessWrapper() { // Match path if necessary. if (!empty($this->configuration['visibility']['path']['pages'])) { + // Assume there are no matches until one is found. + $page_match = FALSE; + // Convert path to lowercase. This allows comparison of the same path // with different case. Ex: /Page, /page, /PAGE. $pages = drupal_strtolower($this->configuration['visibility']['path']['pages']); @@ -97,25 +103,23 @@ public function accessWrapper() { $path = current_path(); $path_alias = drupal_strtolower(drupal_container()->get('path.alias_manager')->getPathAlias($path)); $page_match = drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages)); - // When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED), - // the block is displayed on all pages except those listed in $block->pages. - // When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those - // pages listed in $block->pages. + // When $block->visibility has a value of 0 + // (BLOCK_VISIBILITY_NOTLISTED), the block is displayed on all pages + // except those listed in $block->pages. When set to 1 + // (BLOCK_VISIBILITY_LISTED), it is displayed only on those pages + // listed in $block->pages. $page_match = !($this->configuration['visibility']['path']['visibility'] xor $page_match); } elseif (module_exists('php')) { $page_match = php_eval($this->configuration['visibility']['path']['pages']); } - else { - $page_match = FALSE; + + // If there are page visibility restrictions and this page does not + // match, deny access. + if (!$page_match) { + return FALSE; } } - else { - $page_match = TRUE; - } - if (!$page_match) { - return FALSE; - } // Language visibility settings. if (!empty($this->configuration['visibility']['language']['langcodes']) && array_filter($this->configuration['visibility']['language']['langcodes'])) { diff --git a/core/modules/block/lib/Drupal/block/BlockBundle.php b/core/modules/block/lib/Drupal/block/BlockBundle.php index 4ad19a5..a20d06a 100644 --- a/core/modules/block/lib/Drupal/block/BlockBundle.php +++ b/core/modules/block/lib/Drupal/block/BlockBundle.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * Block dependency injection container. + * Provides the block dependency injection container. */ class BlockBundle extends Bundle { diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index bf89cc4..f5de484 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -22,7 +22,9 @@ class BlockManager extends PluginManagerBase { * Constructs a new \Drupal\block\Plugin\Type\BlockManager object. */ public function __construct() { - $this->discovery = new AlterDecorator(new DerivativeDiscoveryDecorator(new AnnotatedClassDiscovery('block', 'block')), 'block'); + $this->discovery = new AnnotatedClassDiscovery('block', 'block'); + $this->discovery = new DerivativeDiscoveryDecorator($this->discovery) + $this->discovery = new AlterDecorator($this->discovery, 'block'); $this->factory = new DefaultFactory($this); $this->mapper = new ConfigMapper($this); } diff --git a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php index e1c96e4..08b9ffb 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php +++ b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php @@ -11,30 +11,28 @@ use Drupal\Core\Annotation\Translation; /** - * This plugin provides modifications to the system provided base class. Its - * purpose is to provide an overrideable user interface for block selection, - * configuration and placement. + * Defines an overrideable UI for block selection, configuration, and placement. * * @Plugin( * id = "block_plugin_ui", - * title = @Translation("Block Library"), - * title_attribute = "subject", - * menu = TRUE, * module = "block", * all_plugins = @Translation("All Blocks"), - * link_title = @Translation("Configure block"), * config_path = "admin/structure/block/manage", - * path = "admin/structure/block/list", - * suffix = "add", - * type = MENU_LOCAL_ACTION, - * manager = "Drupal\block\Plugin\Type\BlockManager", + * default_task = TRUE, * derivative = "Drupal\block\Plugin\Derivative\BlockPluginUI", * facets = { * "module" = @Translation("Modules") * }, - * default_task = TRUE, - * task_title = @Translation("Library"), + * link_title = @Translation("Configure block"), + * manager = "Drupal\block\Plugin\Type\BlockManager", + * menu = TRUE, + * path = "admin/structure/block/list", + * suffix = "add", * task_suffix = "library" + * task_title = @Translation("Library"), + * title = @Translation("Block Library"), + * title_attribute = "subject", + * type = MENU_LOCAL_ACTION, * ) */ class BlockPluginUI extends PluginUIBase { @@ -144,11 +142,16 @@ public function row($display_plugin_id, array $display_plugin_definition) { } /** + * Creates a facet link for a given facet of a display plugin. + * * Provides individually formatted links for the faceting that happens within * the user interface. Since this is a faceting style procedure, each plugin * may be parsed multiple times in order to extract all facets and their * appropriate labels. * + * The $display_plugin_id and $display_plugin_definition are provided for + * convenience when overriding this method. + * * @param string $facet * A simple string indicating what element of the $display_plugin_definition * to utilize for faceting. @@ -158,14 +161,19 @@ public function row($display_plugin_id, array $display_plugin_definition) { * The plugin definition we are parsing. * * @return array - * Returns a theme_links compatible row array. + * Returns a row array comaptible with theme_links(). */ protected function facetLink($facet, $display_plugin_id, array $display_plugin_definition) { $plugin_definition = $this->getDefinition(); - return array('title' => $display_plugin_definition[$facet], 'href' => $plugin_definition['path'] . '/' . $this->getPluginId() . '/' . $facet . ':' . $display_plugin_definition[$facet]); + return array( + 'title' => $display_plugin_definition[$facet], + 'href' => $plugin_definition['path'] . '/' . $this->getPluginId() . '/' . $facet . ':' . $display_plugin_definition[$facet], + ); } /** + * Determines whether a given facet should be displayed for a plugin. + * * Compares a given plugin definition with the selected facet to determine if * the plugin should be displayed in the user interface. * @@ -187,7 +195,7 @@ protected function facetCompare($facet, $display_plugin_definition) { * Provides an "all" style link to reset the facets. * * The $display_plugin_id and $display_plugin_definition are provided for - * convenience. + * convenience when overriding this method. * * @param string $display_plugin_id * The plugin ID of the plugin we are currently parsing a facet link from. diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php index ecfade3..f33694e 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php @@ -14,7 +14,11 @@ */ class BlockHiddenRegionTest extends WebTestBase { - protected $admin_user; + /** + * An administrative user to configure the test environment. + */ + protected $adminUser; + /** * Modules to enable. * @@ -34,14 +38,14 @@ function setUp() { parent::setUp(); // Create administrative user. - $this->admin_user = $this->drupalCreateUser(array( + $this->adminUser = $this->drupalCreateUser(array( 'administer blocks', 'administer themes', 'search content', ) ); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $default_theme = variable_get('theme_default', 'stark'); @@ -57,7 +61,7 @@ function setUp() { */ public function testBlockNotInHiddenRegion() { - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); // Ensure that the search form block is displayed. $this->drupalGet(''); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php index bf602b4..1bf3543 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php @@ -14,6 +14,9 @@ */ class BlockHtmlIdTest extends WebTestBase { + /** + * An administrative user to configure the test environment. + */ protected $adminUser; /** @@ -51,10 +54,10 @@ function setUp() { } /** - * Test valid HTML id. + * Tests for a valid HTML ID for a block. */ function testHtmlId() { $this->drupalGet(''); - $this->assertRaw('id="block-test-id-block"', 'HTML id for test block is valid.'); + $this->assertRaw('id="block-test-id-block"', 'HTML ID for test block is valid.'); } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php index 927d217..842825d 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php @@ -14,7 +14,11 @@ */ class BlockLanguageTest extends WebTestBase { + /** + * An administrative user to configure the test environment. + */ protected $adminUser; + /** * Modules to enable. * diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php index c72236d..8a1b241 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php @@ -36,12 +36,10 @@ function testBlockThemeHookSuggestions() { // Define a block with a derivative to be preprocessed, which includes both // an underscore (not transformed) and a hyphen (transformed to underscore), // and generates possibilities for each level of derivative. - $data = array( 'region' => 'footer', ); - // $block3 = block_load('system_powered_by_block', $data3); $block = drupal_container()->get('plugin.manager.block')->createInstance('system_menu_block:menu-admin', $data); $variables = array(); $variables['elements']['#block'] = $block; diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index d1c4233..2ba3c55 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -281,7 +281,7 @@ function testBlock() { $instance = block_load($block['config_id']); $config = $instance->getConfig(); - $this->assertEqual($config['subject'], $block['title'], t('Stored block title found.')); + $this->assertEqual($config['subject'], $block['title'], 'Stored block title found.'); // Check whether the block can be moved to all available regions. foreach ($this->regions as $region) { @@ -357,7 +357,7 @@ function testBlockRehash() { $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; $instance = block_load($block['config_id']); $config = $instance->getConfig(); - $this->assertEqual($config['cache'], DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.')); + $this->assertEqual($config['cache'], DRUPAL_CACHE_PER_ROLE, 'Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.'); // Disable caching for this block. $block_config = config($block['config_id']); @@ -368,6 +368,6 @@ function testBlockRehash() { // Verify that block is updated with the new caching mode. $instance = block_load($block['config_id']); $config = $instance->getConfig(); - $this->assertEqual($config['cache'], DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE.")); + $this->assertEqual($config['cache'], DRUPAL_NO_CACHE, "Test block's database entry updated to DRUPAL_NO_CACHE."); } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php index 179464c..383d313 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php @@ -2,13 +2,16 @@ /** * @file - * Definition of Drupal\block\Tests\BlockTest. + * Contains \Drupal\block\Tests\BlockUiTest. */ namespace Drupal\block\Tests; use Drupal\simpletest\WebTestBase; +/** + * Tests the block configuration UI. + */ class BlockUiTest extends WebTestBase { /** @@ -19,6 +22,10 @@ class BlockUiTest extends WebTestBase { public static $modules = array('block'); protected $regions; + + /** + * An administrative user to configure the test environment. + */ protected $adminUser; public static function getInfo() { @@ -28,6 +35,7 @@ public static function getInfo() { 'group' => 'Block', ); } + function setUp() { parent::setUp(); // Create and log in an administrative user. diff --git a/core/modules/block/templates/block.tpl.php b/core/modules/block/templates/block.tpl.php index b4405eb..8c42131 100644 --- a/core/modules/block/templates/block.tpl.php +++ b/core/modules/block/templates/block.tpl.php @@ -41,11 +41,11 @@ * @ingroup themeable */ ?> - -
> - -
> - + +
> + +
> + subject): ?>