diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index b3782e5..2fd5929 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -371,8 +371,10 @@ function aggregator_save_category($edit) { ->condition('cid', $edit['cid']) ->execute(); // Make sure there is no active block for this category. - if ($block = entity_load('block', 'aggregator_category_block:' . $edit['cid'])) { - $block->delete(); + if (module_exists('block')) { + foreach (entity_load_multiple_by_properties('block', array('plugin' => 'aggregator_category_block:' . $edit['cid'])) as $block) { + $block->delete(); + } } $edit['title'] = ''; $op = 'delete'; @@ -435,8 +437,10 @@ function aggregator_save_feed($edit) { ->condition('fid', $edit['fid']) ->execute(); // Make sure there is no active block for this feed. - if ($block = entity_load('block', 'aggregator_feed_block:' . $edit['fid'])) { - $block->delete(); + if (module_exists('block')) { + foreach (entity_load_multiple_by_properties('block', array('plugin' => 'aggregator_feed_block:' . $edit['fid'])) as $block) { + $block->delete(); + } } } elseif (!empty($edit['title'])) { diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php new file mode 100644 index 0000000..0c19a4a --- /dev/null +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -0,0 +1,105 @@ +getPlugin()->blockAccess()) { + return FALSE; + } + + // Otherwise, check for other access restrictions. + if (!$account) { + global $user; + $account = $user; + } + + // Deny access to disabled blocks. + if (!$entity->get('status')) { + return FALSE; + } + + // User role access handling. + // If a block has no roles associated, it is displayed for every role. + // For blocks with roles associated, if none of the user's roles matches + // the settings from this block, access is denied. + $visibility = $entity->get('visibility'); + if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), array_keys($account->roles))) { + // No match. + return FALSE; + } + + // Page path handling. + // Limited visibility blocks must list at least one page. + if (!empty($visibility['path']['visibility']) && $visibility['path']['visibility'] == BLOCK_VISIBILITY_LISTED && empty($visibility['path']['pages'])) { + return FALSE; + } + + // Match path if necessary. + if (!empty($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($visibility['path']['pages']); + if ($visibility['path']['visibility'] < BLOCK_VISIBILITY_PHP) { + // Compare the lowercase path alias (if any) and internal path. + $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. + $page_match = !($visibility['path']['visibility'] xor $page_match); + } + elseif (module_exists('php')) { + $page_match = php_eval($visibility['path']['pages']); + } + + // If there are page visibility restrictions and this page does not + // match, deny access. + if (!$page_match) { + return FALSE; + } + } + + // Language visibility settings. + if (!empty($visibility['language']['langcodes']) && array_filter($visibility['language']['langcodes'])) { + if (empty($visibility['language']['langcodes'][language($visibility['language']['language_type'])->langcode])) { + return FALSE; + } + } + + // Check other modules for block access rules. + foreach (module_implements('block_access') as $module) { + if (module_invoke($module, 'block_access', $entity) === FALSE) { + return FALSE; + } + } + + // If nothing denied access to the block, it is accessible. + return TRUE; + } + +} diff --git a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php index f3f4727..f23588d 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php @@ -7,7 +7,6 @@ namespace Drupal\block\Plugin\Core\Entity; -use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -20,6 +19,7 @@ * label = @Translation("Block"), * module = "block", * controller_class = "Drupal\block\BlockStorageController", + * access_controller_class = "Drupal\block\BlockAccessController", * form_controller_class = { * "default" = "Drupal\block\BlockFormController" * }, @@ -188,101 +188,6 @@ public function getExportProperties() { } /** - * Adds the user-configured per-role, per-path, and per-language visibility - * settings to all blocks, and invokes hook_block_access(). - * - * Most plugins should not override this method unless they need to remove - * the user-defined access restrictions. To add specific access - * restrictions for a particular block type, override - * BlockBase::blockAccess() instead. - * - * @see hook_block_access() - * @see \Drupal\block\BlockBase::blockAccess() - */ - public function access($operation = 'view', User $account = NULL) { - // If the block-specific access restrictions indicate the block is not - // accessible, always deny access. - if (!$this->getPlugin()->blockAccess()) { - return FALSE; - } - - // Otherwise, check for other access restrictions. - if (!$account) { - global $user; - $account = $user; - } - - // Deny access to disabled blocks. - if (!$this->get('status')) { - return FALSE; - } - - // User role access handling. - // If a block has no roles associated, it is displayed for every role. - // For blocks with roles associated, if none of the user's roles matches - // the settings from this block, access is denied. - $visibility = $this->get('visibility'); - if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), array_keys($account->roles))) { - // No match. - return FALSE; - } - - // Page path handling. - // Limited visibility blocks must list at least one page. - if (!empty($visibility['path']['visibility']) && $visibility['path']['visibility'] == BLOCK_VISIBILITY_LISTED && empty($visibility['path']['pages'])) { - return FALSE; - } - - // Match path if necessary. - if (!empty($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($visibility['path']['pages']); - if ($visibility['path']['visibility'] < BLOCK_VISIBILITY_PHP) { - // Compare the lowercase path alias (if any) and internal path. - $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. - $page_match = !($visibility['path']['visibility'] xor $page_match); - } - elseif (module_exists('php')) { - $page_match = php_eval($visibility['path']['pages']); - } - - // If there are page visibility restrictions and this page does not - // match, deny access. - if (!$page_match) { - return FALSE; - } - } - - // Language visibility settings. - if (!empty($visibility['language']['langcodes']) && array_filter($visibility['language']['langcodes'])) { - if (empty($visibility['language']['langcodes'][language($visibility['language']['language_type'])->langcode])) { - return FALSE; - } - } - - // Check other modules for block access rules. - foreach (module_implements('block_access') as $module) { - if (module_invoke($module, 'block_access', $this) === FALSE) { - return FALSE; - } - } - - // If nothing denied access to the block, it is accessible. - return TRUE; - } - - /** * Implements \Drupal\block\BlockInterface::build(). * * Allows blocks to be altered after they are built. diff --git a/core/modules/node/node.module b/core/modules/node/node.module index c1e4e1c..f6fd1a4 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2011,23 +2011,6 @@ function node_form_block_form_alter(&$form, &$form_state) { } /** - * Implements hook_modules_uninstalled(). - * - * Cleans up the {block_node_type} table from modules' blocks. - */ -function node_modules_uninstalled($modules) { - // Remove the block visibility settings for all node types. - foreach (entity_load_multiple('block') as $block_id => $block) { - $visibility = $block->get('visibility'); - if (!empty($visibility['node_types']['types'])) { - unset($visibility['node_types']); - $block->set('visibility', $visibility); - $block->save(); - } - } -} - -/** * Implements hook_block_access(). * * Checks the content type specific visibility settings and removes the block