Commit f3a8e3e8 authored by Maxim Podorov's avatar Maxim Podorov Committed by Damien McKenna
Browse files

Issue #3001282 by maximpodorov, DamienMcKenna: Support hasAffectingChanges method of FieldItemList.

parent 9459e192
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ By DamienMcKenna: Minor code readability tweak.
  ~160 characters.
#3115634 by DamienMcKenna: Refactor MetatagManager::generateRawElements() to
  create token arguments once per call.
#3001282 by maximpodorov, DamienMcKenna: Support hasAffectingChanges method of
  FieldItemList.


Metatag 8.x-1.11, 2019-12-20
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use Drupal\Core\TypedData\DataDefinition;
 *   id = "metatag",
 *   label = @Translation("Meta tags"),
 *   description = @Translation("This field stores code meta tags."),
 *   list_class = "\Drupal\metatag\Plugin\Field\FieldType\MetatagFieldItemList",
 *   default_widget = "metatag_firehose",
 *   default_formatter = "metatag_empty_formatter",
 *   serialized_property_names = {
+29 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\metatag\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Field\FieldItemListInterface;

/**
 * Represents a list of metatag field item objects.
 */
class MetatagFieldItemList extends FieldItemList {

  /**
   * {@inheritdoc}
   */
  public function hasAffectingChanges(FieldItemListInterface $original_items, $langcode) {
    $normalized_items = clone $this;
    $normalized_original_items = clone $original_items;

    // Remove default metatags.
    $normalized_items->preSave();
    $normalized_items->filterEmptyItems();
    $normalized_original_items->preSave();
    $normalized_original_items->filterEmptyItems();

    return !$normalized_items->equals($normalized_original_items);
  }

}