hasAffectingChanges example

    // the default translation.     $skip_untranslatable_fields = !$this->isDefaultTranslation() && $this->isDefaultTranslationAffectedOnly();

    foreach ($this->getFieldDefinitions() as $field_name => $definition) {
      // @todo Avoid special-casing the following fields. See       // https://www.drupal.org/node/2329253.       if (in_array($field_name$skip_fields, TRUE) || ($skip_untranslatable_fields && !$definition->isTranslatable())) {
        continue;
      }
      $items = $this->get($field_name)->filterEmptyItems();
      $original_items = $translation->get($field_name)->filterEmptyItems();
      if ($items->hasAffectingChanges($original_items$langcode)) {
        return TRUE;
      }
    }

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function isDefaultTranslationAffectedOnly() {
    
->method('createFieldItem')
      ->willReturnOnConsecutiveCalls($first_field_item$second_field_item);

    // Set the field item values.     if ($first_field_item instanceof FieldItemInterface) {
      $field_list_a->setValue($first_field_item);
    }
    if ($second_field_item instanceof FieldItemInterface) {
      $field_list_b->setValue($second_field_item);
    }

    $this->assertEquals($expected, !$field_list_a->hasAffectingChanges($field_list_b, ''));
  }

  /** * @covers ::equals */
  public function testEqualsEmptyItems() {
    /** @var \Drupal\Core\Field\FieldItemBase $fv */
    $first_field_item = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
    $first_field_item->setValue(['0' => 1, '1' => 2]);
    $second_field_item = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
    $second_field_item->setValue(['1' => 2, '0' => 1]);
    
->getStorage($entity->getEntityTypeId())
        ->loadRevision($entity->getLoadedRevisionId());
    }

    foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
      if (in_array($field_name$skip_fields, TRUE) || $definition->isTranslatable() || $definition->isComputed()) {
        continue;
      }

      $items = $entity->get($field_name)->filterEmptyItems();
      $original_items = $original->get($field_name)->filterEmptyItems();
      if ($items->hasAffectingChanges($original_items$entity->getUntranslated()->language()->getId())) {
        return TRUE;
      }
    }

    return FALSE;
  }

}
Home | Imprint | This part of the site doesn't use cookies.