Error message

Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public function Paragraph::isChanged

Returns a flag whether a current revision has been changed.

The current instance is being compared with the latest saved revision.

Return value

bool TRUE in case the current revision changed. Otherwise, FALSE.

Overrides ParagraphInterface::isChanged

See also

\Drupal\Core\Entity\ContentEntityBase::hasTranslationChanges()

File

paragraphs/src/Entity/Paragraph.php, line 600

Class

Paragraph
Defines the Paragraph entity.

Namespace

Drupal\paragraphs\Entity

Code

public function isChanged() {
  if ($this
    ->isNew()) {
    return TRUE;
  }

  // $this->original only exists during save. If it exists we re-use it here
  // for performance reasons.

  /** @var \Drupal\paragraphs\ParagraphInterface $original */
  $original = $this->original ?: NULL;
  if (!$original) {
    $original = $this
      ->entityTypeManager()
      ->getStorage($this
      ->getEntityTypeId())
      ->loadRevision($this
      ->getLoadedRevisionId());
  }

  // If the current revision has just been added, we have a change.
  if ($original
    ->isNewRevision()) {
    return TRUE;
  }

  // The list of fields to skip from the comparision.
  $skip_fields = $this
    ->getFieldsToSkipFromChangedCheck();

  // Compare field item current values with the original ones to determine
  // whether we have changes. We skip also computed fields as comparing them
  // with their original values might not be possible or be meaningless.
  foreach ($this
    ->getFieldDefinitions() as $field_name => $definition) {
    if (in_array($field_name, $skip_fields, TRUE)) {
      continue;
    }
    $field = $this
      ->get($field_name);

    // When saving entities in the user interface, the changed timestamp is
    // automatically incremented by ContentEntityForm::submitForm() even if
    // nothing was actually changed. Thus, the changed time needs to be
    // ignored when determining whether there are any actual changes in the
    // entity.
    if (!$field instanceof ChangedFieldItemList && !$definition
      ->isComputed()) {
      $items = $field
        ->filterEmptyItems();
      $original_items = $original
        ->get($field_name)
        ->filterEmptyItems();
      if (!$items
        ->equals($original_items)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}