1 layout.module layout_block_has_required_contexts(Layout $layout, $block_module, $block_delta)

Determine if a block has the necessary contexts.

Parameters

Layout $layout: The layout on which the specified block will be displayed.

string $block_module: The module that provides the block to be checked.

string $block_delta: The identifier for the block within hook_block_info().

Return value

bool: TRUE if the block has required contexts. FALSE otherwise.

File

core/modules/layout/layout.module, line 2223
The Layout module creates pages and wraps existing pages in layouts.

Code

function layout_block_has_required_contexts(Layout $layout, $block_module, $block_delta) {
  $block_info = module_invoke($block_module, 'block_info');
  $required_contexts = array();

  if (isset($block_info[$block_delta]['required contexts'])) {
    $required_contexts = $block_info[$block_delta]['required contexts'];
  }

  $available_contexts = $layout->getContexts();

  foreach ($required_contexts as $key => $required_context_plugin_name) {
    foreach ($available_contexts as $context) {
      if ($context->isA($required_context_plugin_name)) {
        // Matching context available, remove from required list.
        unset($required_contexts[$key]);
      }
    }
  }

  // If there are no missing contexts, all required contexts are available.
  return empty($required_contexts);
}