Version 1
[yaffs-website] / web / core / modules / system / tests / modules / entity_test_update / src / Plugin / Field / FieldType / MultiValueTestItem.php
diff --git a/web/core/modules/system/tests/modules/entity_test_update/src/Plugin/Field/FieldType/MultiValueTestItem.php b/web/core/modules/system/tests/modules/entity_test_update/src/Plugin/Field/FieldType/MultiValueTestItem.php
new file mode 100644 (file)
index 0000000..cb08818
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+namespace Drupal\entity_test_update\Plugin\Field\FieldType;
+
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\TypedData\DataDefinition;
+use Drupal\Core\Field\FieldItemBase;
+
+/**
+ * Defines the 'multi_value_test' field type.
+ *
+ * @FieldType(
+ *   id = "multi_value_test",
+ *   label = @Translation("Multiple values test"),
+ *   description = @Translation("Another dummy field type."),
+ * )
+ */
+class MultiValueTestItem extends FieldItemBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
+    $properties['value1'] = DataDefinition::create('string')
+      ->setLabel(t('First value'));
+
+    $properties['value2'] = DataDefinition::create('string')
+      ->setLabel(t('Second value'));
+
+    return $properties;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function schema(FieldStorageDefinitionInterface $field_definition) {
+    return [
+      'columns' => [
+        'value1' => [
+          'type' => 'varchar',
+          'length' => 64,
+        ],
+        'value2' => [
+          'type' => 'varchar',
+          'length' => 64,
+        ],
+      ],
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isEmpty() {
+    $item = $this->getValue();
+    return empty($item['value1']) && empty($item['value2']);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function mainPropertyName() {
+    return 'value1';
+  }
+
+}