function FieldTestItem::postSave

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::postSave()
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php \Drupal\entity_test\Plugin\Field\FieldType\FieldTestItem::postSave()
  3. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php \Drupal\entity_test\Plugin\Field\FieldType\FieldTestItem::postSave()

Overrides FieldItemBase::postSave

File

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

Class

FieldTestItem
Defines the 'field_test' entity field type.

Namespace

Drupal\entity_test\Plugin\Field\FieldType

Code

public function postSave($update) {
    // Determine whether the field value should be rewritten to the storage. We
    // always rewrite on create as we need to store a value including the entity
    // id.
    $resave = !$update || $this->mustResave();
    if ($resave) {
        $entity = $this->getEntity();
        $definition = $this->getFieldDefinition();
        $name = $definition->getName();
        $value = 'field_test:' . $name . ':' . $entity->id() . ':' . static::$counter[$name];
        $this->setValue($value);
    }
    return $resave;
}

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