You are here

function metatag_entity_diff in Metatag 8

Implements hook_entity_diff().

File

./metatag.module, line 641
Contains metatag.module.

Code

function metatag_entity_diff($old_entity, $new_entity, $context) {
  $result = [];
  $entity_type = $context['entity_type'];
  $options = variable_get('diff_additional_options_' . $entity_type, []);
  if (!empty($options['metatag']) && metatag_entity_supports_metatags($entity_type)) {

    // Find meta tags that are set on either the new or old entity.
    $tags = [];
    foreach ([
      'old' => $old_entity,
      'new' => $new_entity,
    ] as $entity_key => $entity) {
      $language = metatag_entity_get_language($entity_type, $entity);
      if (isset($entity->metatags[$language])) {
        foreach ($entity->metatags[$language] as $key => $value) {
          $tags[$key][$entity_key] = $value['value'];
        }
      }
    }
    $init_weight = 100;
    foreach ($tags as $key => $values) {
      $id = ucwords('Meta ' . $key);

      // @todo Find the default values and show these if not set.
      $result[$id] = [
        '#name' => $id,
        '#old' => [
          empty($values['old']) ? '' : $values['old'],
        ],
        '#new' => [
          empty($values['new']) ? '' : $values['new'],
        ],
        '#weight' => $init_weight++,
        '#settings' => [
          'show_header' => TRUE,
        ],
      ];
    }
  }
  return $result;
}