function FieldTestItem::preSave

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php \Drupal\entity_test\Plugin\Field\FieldType\FieldTestItem::preSave()
  2. 10 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php \Drupal\entity_test\Plugin\Field\FieldType\FieldTestItem::preSave()
  3. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php \Drupal\entity_test\Plugin\Field\FieldType\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.