' . t('About') . '';
$output .= '
'.t('The Context module lets users define conditions for when certain reactions should take place.').'
';
$output .= ''.t('An example of a condition could be when viewing a certain node type and blocks should be placed as a reaction when viewing a page with this node type.').'
';
$output .= '' . t('Uses') . '
';
$output .= '';
$output .= '- ' . t('Managing context') . '
';
$output .= '- ' . t('Users with Administer contexts permission can add contextual conditions and reactions for different portions of their site. For each context, they can choose the conditions that trigger this context to be active and choose different aspects of their site that should react to this active context.') . '
';
$output .= '- ' . t('Adding new custom reactions') . '
';
$output .= '- ' . t('Reactions for the context module are defined trough the new Drupal 8 Plugin API.', array(':link' =>'https://www.drupal.org/developing/api/8/plugins')) . '
';
$output .= '- ' . t('The Context module defines a plugin type named ContextReaction that users can extend when creating their own plugins.') . '
';
$output .= '- ' . t('A context reaction requires a configuration form and execute method. The execution of the plugin is also something that will have to be handled by the author of the reaction.') . '
';
$output .= '
';
return $output;
}
}
/**
* Run the body class context reactions if there are any and let them add
* classes to the page body.
*
* Implements hook_preprocess_HOOK().
*/
function context_preprocess_html(&$variables) {
/** @var \Drupal\context\ContextManager $context_manager */
$context_manager = \Drupal::service('context.manager');
foreach ($context_manager->getActiveReactions('body_class') as $reaction) {
$variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $reaction->execute());
}
}
/**
* Implements hook_theme_suggestions_page_alter().
*/
function context_theme_suggestions_page_alter(array &$suggestions, array $variables) {
$context_manager = \Drupal::service('context.manager');
foreach ($context_manager->getActiveReactions('page_template_suggestions') as $reaction) {
$template_suggestions = explode(PHP_EOL, $reaction->execute());
$suggestions = array_merge($suggestions, $template_suggestions);
}
}
/**
* Implements hook_preprocess_page().
*/
function context_preprocess_page(&$variables) {
// Active theme for route.
$current_theme = \Drupal::service('theme.negotiator')->determineActiveTheme(Drupal::routeMatch());
// Context manager.
$context_manager = \Drupal::service('context.manager');
// Disable regions based on regions reaction.
foreach ($context_manager->getActiveReactions('regions') as $region_reaction) {
$configuration = $region_reaction->getConfiguration();
if (isset($configuration['regions'][$current_theme])) {
foreach ($configuration['regions'][$current_theme] as $region) {
unset($variables['page'][$region]);
}
}
}
}