1 layout.class.inc Layout::getContexts()

Return all contexts (from both the layout and menu item) for this Layout.

return LayoutContext[]

File

core/modules/layout/includes/layout.class.inc, line 776
Class for loading, modifying, and executing a layout.

Class

Layout
@file Class for loading, modifying, and executing a layout.

Code

function getContexts() {
  if (is_null($this->contexts)) {
    $this->contexts = array();
  }

  // Load objects for stored contexts.
  foreach ($this->contexts as $key => $context) {
    if (!isset($context->position) && !is_object($context->data)) {
      $context_info = layout_get_context_info($context->plugin);
      if (isset($context_info['load callback'])) {
        $context_data = call_user_func_array($context_info['load callback'], $context->settings);
        $context->setData($context_data);
      }
    }
  }

  // Load contexts from paths and menu items.
  if ($this->menu_item) {
    $this->contexts += $this->menu_item->getContexts();
  }
  elseif ($this->path) {
    $this->contexts += layout_context_required_by_path($this->path);
  }

  // Add on the current user context, which is always available.
  if (!isset($this->contexts['current_user'])) {
    $this->contexts['current_user'] = layout_create_context('user', array(
      'name' => 'current_user',
      'label' => t('Current user'),
      'locked' => TRUE,
    ));
    $this->contexts['current_user']->setData($GLOBALS['user']);
  }

  // Add on the overrides path context, which is always available.
  if (empty($this->menu_item) && !isset($this->contexts['overrides_path'])) {
    $this->contexts['overrides_path'] = layout_create_context('overrides_path', array(
      'name' => 'overrides_path',
      'locked' => TRUE,
    ));
  }

  return $this->contexts;
}