3 namespace Drupal\entity_test\Plugin\Field\FieldType;
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\Core\TypedData\DataDefinition;
7 use Drupal\Core\Field\FieldItemBase;
10 * Defines the 'shape' field type.
14 * label = @Translation("Shape"),
15 * description = @Translation("Another dummy field type."),
18 class ShapeItem extends FieldItemBase {
23 public static function defaultStorageSettings() {
25 'foreign_key_name' => 'shape',
26 ] + parent::defaultStorageSettings();
32 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
33 $properties['shape'] = DataDefinition::create('string')
34 ->setLabel(t('Shape'));
36 $properties['color'] = DataDefinition::create('string')
37 ->setLabel(t('Color'));
45 public static function schema(FieldStorageDefinitionInterface $field_definition) {
47 // The 'foreign keys' key is not always used in tests.
48 if ($field_definition->getSetting('foreign_key_name')) {
49 $foreign_keys['foreign keys'] = [
50 // This is a dummy foreign key definition, references a table that
51 // doesn't exist, but that's not a problem.
52 $field_definition->getSetting('foreign_key_name') => [
53 'table' => $field_definition->getSetting('foreign_key_name'),
54 'columns' => [$field_definition->getSetting('foreign_key_name') => 'id'],
75 public function isEmpty() {
76 $item = $this->getValue();
77 return empty($item['shape']) && empty($item['color']);
83 public static function mainPropertyName() {