AutoIncrementingTestItem.php

Same filename in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/AutoIncrementingTestItem.php
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/AutoIncrementingTestItem.php
  3. 10 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/AutoIncrementingTestItem.php

Namespace

Drupal\entity_test\Plugin\Field\FieldType

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/AutoIncrementingTestItem.php

View source
<?php

declare (strict_types=1);
namespace Drupal\entity_test\Plugin\Field\FieldType;

use Drupal\Core\Field\Attribute\FieldType;
use Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines the 'field_method_invocation_order_test' entity field type.
 */
class AutoIncrementingTestItem extends IntegerItem {
    
    /**
     * {@inheritdoc}
     */
    public function preSave() {
        parent::preSave();
        $this->value = static::getIncrementedFieldValue();
    }
    
    /**
     * Gets an incremented field value.
     *
     * @return int
     *   The incremented field value.
     */
    private static function getIncrementedFieldValue() {
        static $cache = 0;
        return ++$cache;
    }

}

Classes

Title Deprecated Summary
AutoIncrementingTestItem Defines the 'field_method_invocation_order_test' entity field type.

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