function _metatags_quick_add_head in Meta tags quick 8.3
Same name and namespace in other branches
- 7.2 metatags_quick.module \_metatags_quick_add_head()
- 7 metatags_quick.module \_metatags_quick_add_head()
2 calls to _metatags_quick_add_head()
- MetatagFormatter::viewElements in lib/
Drupal/ metatags_quick/ Plugin/ field/ formatter/ MetatagFormatter.php - Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
- metatags_quick_add_meta_tag in ./
metatags_quick.rules.inc - Rules integraiton function for _metatags_quick_add_head().
File
- ./
metatags_quick.module, line 463 - Meta tags implemented with FieldAPI/EntityAPI
Code
function _metatags_quick_add_head($item = FALSE) {
static $added_meta = array();
static $meta_data = array();
$token_service = \Drupal::service('token');
if (!empty($added_meta[$item['name']])) {
return;
}
// Only output meta if content is not empty.
if ($item['content']) {
$content = $item['content'];
if (!empty($item['entity_type']) && !empty($item['entity'])) {
$token_service
->replace($content, array(
$item['entity_type'] => $item['entity'],
));
}
else {
$content = $token_service
->replace($content);
}
// (Not nice) hack to separate multiple tags returned by token.
$content = preg_replace('/<\\/a><a/', '<\\/a>, <a', $content);
$content = trim(strip_tags($content));
$item['content'] = $content;
$meta_data[] = $item;
if (empty($item['type'])) {
$item['type'] = 'default';
}
switch ($item['type']) {
case 'link':
// Unset an existing html head link with the same rel attribute, assuming that
// the array key has been built by drupal_add_html_head_link().
$head_elements =& drupal_static('drupal_add_html_head');
foreach ($head_elements as $key => $head_element) {
// If an existing key starts with 'drupal_add_html_head_link:[name]', unset it.
if (strpos($key, 'drupal_add_html_head_link:' . $item['name']) === 0) {
$head_elements[$key]['#access'] = FALSE;
}
}
$attributes = array(
'rel' => $item['name'],
'href' => url($item['content']),
);
drupal_add_html_head_link($attributes);
break;
case 'default':
default:
$element = array(
'#tag' => 'meta',
'#attributes' => array(
'name' => $item['name'],
'content' => $item['content'],
),
);
drupal_add_html_head($element, 'metatags_quick_' . $item['name']);
}
if ($item['name'] == 'title') {
$element = array(
'#tag' => 'title',
'#value' => $item['content'],
);
drupal_add_html_head($element, 'metatags_quick_' . $item['name']);
}
}
$added_meta[$item['name']] = TRUE;
}