1.20.x 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
- modules/
layout/ includes/ layout.class.inc, line 790 - 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) {
// 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'])) {
$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);
}
// 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,
));
}
// Return all contexts if requested.
if ($include_types === LayoutContext::USAGE_TYPE_ALL) {
return $this->contexts;
}
// Otherwise filter down the list of contexts to only those requested.
$return_contexts = array();
foreach ($this->contexts as $key => $context) {
if ($context->usageType & $include_types) {
$return_contexts[$key] = $context;
}
}
return $return_contexts;
}