function FieldTestItem::preSave

Overrides FieldItemBase::preSave

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php, line 71

Class

FieldTestItem
Defines the 'field_test' entity field type.

Namespace

Drupal\entity_test\Plugin\Field\FieldType

Code

public function preSave() {
  $name = $this->getFieldDefinition()
    ->getName();
  static::$counter[$name]++;
  // Overwrite the field value unless it is going to be overridden, in which
  // case its final value will already be different from the current one.
  if (!$this->getEntity()
    ->isNew() && !$this->mustResave()) {
    $this->setValue('overwritten');
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.