context_metadata.module in Context Metadata 8.2
Same filename and directory in other branches
Contains context_metadata.module.
File
context_metadata.moduleView source
<?php
/**
* @file
* Contains context_metadata.module.
*/
/**
* Alter the metatags for pages that are not of content entities.
*
* @param array $metatags
* The special metatags to be added to the page.
* @param array $context
* The context, containing the entity used for token replacements.
*/
function context_metadata_metatags_alter(array &$metatags, array $context) {
/** @var \Drupal\context\ContextManager $contextManager */
$contextManager = \Drupal::service('context.manager');
// Start the loopty loop.
foreach ($contextManager
->getActiveReactions('context_metadata') as $reaction) {
// Weed out the chaff.
$contextMetadata = array_filter($reaction
->execute());
// Unset the ID.
unset($contextMetadata['id']);
// Start the loopty loop.
if (!empty($contextMetadata)) {
foreach ($contextMetadata as $key => $value) {
// Deal with arrays such as robots.
if (is_array($value)) {
$values = array_filter($value);
// Only add if there are any values.
if (!empty($values)) {
$originalValues = $metatags[$key];
$metatags[$key] = array_merge($originalValues, $values);
}
}
else {
$metatags[$key] = $value;
}
}
}
}
}
Functions
Name | Description |
---|---|
context_metadata_metatags_alter | Alter the metatags for pages that are not of content entities. |