public function haveFieldsChanged(ContentEntityInterface $entity, ContentEntityInterface $original) {

    $field_definitions = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle());

    $ignore_list = ['vid' => 1, 'changed' => 1, 'path' => 1];
    $field_definitions = array_diff_key($field_definitions, $ignore_list);

    foreach ($field_definitions as $field_name => $field_definition) {
      $langcodes = array_keys($entity->getTranslationLanguages());

      if ($langcodes !== array_keys($original->getTranslationLanguages())) {
        // If the list of langcodes has changed, we need to save.
        return TRUE;
      }

      foreach ($langcodes as $langcode) {
        $items = $entity
          ->getTranslation($langcode)
          ->get($field_name)
          ->filterEmptyItems();
        $original_items = $original
          ->getTranslation($langcode)
          ->get($field_name)
          ->filterEmptyItems();

        // If the field items are not equal, we need to save.
        if (!$items->equals($original_items)) {
          return TRUE;
        }
      }
    }

    return FALSE;
  }
public function haveFieldsChanged(ContentEntityInterface $entity, ContentEntityInterface $original) {

    $field_definitions = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle());

    $ignore_list = ['vid' => 1, 'changed' => 1, 'path' => 1];
    $field_definitions = array_diff_key($field_definitions, $ignore_list);

    foreach ($field_definitions as $field_name => $field_definition) {
      $langcodes = array_keys($entity->getTranslationLanguages());

      if ($langcodes !== array_keys($original->getTranslationLanguages())) {
        // If the list of langcodes has changed, we need to save.
        return TRUE;
      }

      foreach ($langcodes as $langcode) {
        $items = $entity
          ->getTranslation($langcode)
          ->get($field_name)
          ->filterEmptyItems();
        $original_items = $original
          ->getTranslation($langcode)
          ->get($field_name)
          ->filterEmptyItems();

        // If the field items are not equal, we need to save.
        if (!$items->equals($original_items)) {
          return TRUE;
        }
      }
    }

    return FALSE;
  }
public function haveFieldsChanged ( ContentEntityInterface $ entity , ContentEntityInterface $ original ) { $ field_definitions = $ this -> entityFieldManager -> getFieldDefinitions ( $ entity -> getEntityTypeId ( ) , $ entity -> bundle ( ) ) ; $ ignore_list = [ 'vid' => 1 , 'changed' => 1 , 'path' => 1 ] ; $ field_definitions = array_diff_key ( $ field_definitions , $ ignore_list ) ; foreach ( $ field_definitions as $ field_name => $ field_definition ) { $ langcodes = array_keys ( $ entity -> getTranslationLanguages ( ) ) ; if ( $ langcodes !== array_keys ( $ original -> getTranslationLanguages ( ) ) ) { // If the list of langcodes has changed, we need to save. return TRUE ; } foreach ( $ langcodes as $ langcode ) { $ items = $ entity -> getTranslation ( $ langcode ) -> get ( $ field_name ) -> filterEmptyItems ( ) ; $ original_items = $ original -> getTranslation ( $ langcode ) -> get ( $ field_name ) -> filterEmptyItems ( ) ; // If the field items are not equal, we need to save. if ( ! $ items -> equals ( $ original_items ) ) { return TRUE ; } } } return FALSE ; }
Evaluates if fields have changed between two instances of a ContentEntity.

@param \Drupal\Core\Entity\ContentEntityInterface $entity
The updated entity.
@param \Drupal\Core\Entity\ContentEntityInterface $original
The original entity.

@return bool
TRUE if the fields have changed.
Evaluates if fields have changed between two instances of a ContentEntity .