Version 1
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / FieldType / AutoIncrementingTestItem.php
1 <?php
2
3 namespace Drupal\entity_test\Plugin\Field\FieldType;
4
5 use Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem;
6
7 /**
8  * Defines the 'field_method_invocation_order_test' entity field type.
9  *
10  * @FieldType(
11  *   id = "auto_incrementing_test",
12  *   label = @Translation("Auto incrementing test field item"),
13  *   description = @Translation("An entity field designed to test the field method invocation order."),
14  *   category = @Translation("Number"),
15  *   no_ui = TRUE,
16  * )
17  */
18 class AutoIncrementingTestItem extends IntegerItem {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function preSave() {
24     parent::preSave();
25     $this->value = static::getIncrementedFieldValue();
26   }
27
28   /**
29    * Gets an incremented field value.
30    *
31    * @return int
32    *   The incremented field value.
33    */
34   private static function getIncrementedFieldValue() {
35     $current_value = &drupal_static(__METHOD__, 0);
36     return ++$current_value;
37   }
38
39 }