1 layout.class.inc | Layout::getContexts($include_types = LayoutContext::USAGE_TYPE_ALL) |
Return all contexts (from both the layout and menu item) for this Layout.
Include a specific list of contexts based on how they are used.
This is loaded from the list of constants provided in the LayoutContext class, which includes the following:
- USAGE_TYPE_ALL - All contexts from all possible sources.
- USAGE_TYPE_CUSTOM - Contexts manually specified in configuration.
- USAGE_TYPE_MENU - Contexts automatically provided from a menu path.
- USAGE_TYPE_SYSTEM - Global contexts such as logged-in user.
- USAGE_TYPE_RELATIONSHIP - Contexts added through relationships.
Return value
File
- core/
modules/ layout/ includes/ layout.class.inc, line 799 - Class for loading, modifying, and executing a layout.
Class
- Layout
- @file Class for loading, modifying, and executing a layout.
Code
function getContexts($include_types = LayoutContext::USAGE_TYPE_ALL) {
$contexts_cache = &backdrop_static(__METHOD__, array());
if (isset($contexts_cache[$this->name])) {
return $this->getContextsByType($contexts_cache[$this->name], $include_types);
}
// Initialize a list of contexts if not defined.
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'])) {
$load_arguments = array_values($context->settings);
$context_data = call_user_func_array($context_info['load callback'], $load_arguments);
$context->setData($context_data);
}
}
}
// Load contexts from paths or menu items if available.
if ($this->menu_item || $this->path) {
if ($this->menu_item) {
$this->contexts += $this->menu_item->getContexts();
}
else {
$this->contexts += layout_context_required_by_path($this->path);
}
}
// Load contexts from relationships.
if ($include_types & LayoutContext::USAGE_TYPE_RELATIONSHIP) {
$this->contexts += $this->getContextsFromRelationships();
}
// Add on the current user context, which is always available.
if (!isset($this->contexts['current_user'])) {
$this->contexts['current_user'] = layout_current_user_context();
}
// 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,
));
}
$contexts_cache[$this->name] = $this->contexts;
return $this->getContextsByType($this->contexts, $include_types);
}