5 * Contains \Drupal\behat_test\Plugin\Field\FieldType\AddressFieldItem.
8 namespace Drupal\behat_test\Plugin\Field\FieldType;
10 use Drupal\Core\Field\FieldItemBase;
11 use Drupal\Core\Field\FieldStorageDefinitionInterface;
12 use Drupal\Core\TypedData\DataDefinition;
15 * Plugin implementation of a simulated 'address_field' field type.
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
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"
30 class AddressFieldItem extends FieldItemBase {
35 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
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')),
47 public static function schema(FieldStorageDefinitionInterface $field_definition) {
51 'description' => 'The ISO country code.',
56 'description' => 'The locality.',
61 'description' => 'The thoroughfare.',
66 'description' => 'The postal code.',
77 public function isEmpty() {
79 foreach (['country', 'locality', 'thoroughfare', 'postal_code'] as $column) {
80 $empty &= $this->get($column)->getValue() === NULL;