You are here

function simplemeta_page_attachments in Simple Meta 8.2

Implements hook_page_attachments().

File

./simplemeta.module, line 70
Contains simplemeta.module.

Code

function simplemeta_page_attachments(array &$attachments) {
  if (simplemeta_need_to_inject() && ($entity = simplemeta_get_page_meta())) {
    foreach ([
      'title',
      'description',
      'keywords',
    ] as $element) {
      if ($entity->data->{$element}) {
        $tag = [
          '#tag' => 'meta',
          '#attributes' => [
            'name' => $element,
            'content' => $entity->data->{$element},
          ],
        ];
        $attachments['#attached']['html_head'][] = [
          $tag,
          $element,
        ];
      }
    }
  }
}