Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-extension / fixtures / drupal8 / modules / behat_test / src / Plugin / Field / FieldType / AddressFieldItem.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\behat_test\Plugin\Field\FieldType\AddressFieldItem.
6  */
7
8 namespace Drupal\behat_test\Plugin\Field\FieldType;
9
10 use Drupal\Core\Field\FieldItemBase;
11 use Drupal\Core\Field\FieldStorageDefinitionInterface;
12 use Drupal\Core\TypedData\DataDefinition;
13
14 /**
15  * Plugin implementation of a simulated 'address_field' field type.
16  *
17  * This is intended as a temporary solution for testing complex fields using
18  * the Behat Extension. Once the AddressField module is ported this will become
19  * obsolete.
20  *
21  * @FieldType(
22  *   id = "behat_test_address_field",
23  *   label = @Translation("Address"),
24  *   module = "behat_test",
25  *   description = @Translation("A simulated address field type, intended for testing the Behat Extension."),
26  *   default_widget = "behat_test_address_field_default",
27  *   default_formatter = "behat_test_address_field"
28  * )
29  */
30 class AddressFieldItem extends FieldItemBase {
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
36     return [
37       'country' => DataDefinition::create('string')->setLabel(t('Country')),
38       'locality' => DataDefinition::create('string')->setLabel(t('Locality')),
39       'thoroughfare' => DataDefinition::create('string')->setLabel(t('Thoroughfare')),
40       'postal_code' => DataDefinition::create('string')->setLabel(t('Postal code')),
41     ];
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public static function schema(FieldStorageDefinitionInterface $field_definition) {
48     return [
49       'columns' => [
50         'country' => [
51           'description' => 'The ISO country code.',
52           'type' => 'varchar',
53           'length' => 2,
54         ],
55         'locality' => [
56           'description' => 'The locality.',
57           'type' => 'varchar',
58           'length' => 255,
59         ],
60         'thoroughfare' => [
61           'description' => 'The thoroughfare.',
62           'type' => 'varchar',
63           'length' => 255,
64         ],
65         'postal_code' => [
66           'description' => 'The postal code.',
67           'type' => 'varchar',
68           'length' => 255,
69         ],
70       ],
71     ];
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function isEmpty() {
78     $empty = TRUE;
79     foreach (['country', 'locality', 'thoroughfare', 'postal_code'] as $column) {
80       $empty &= $this->get($column)->getValue() === NULL;
81     }
82     return (bool) $empty;
83   }
84
85 }