ZoneItem.php in Address 8
File
src/Plugin/Field/FieldType/ZoneItem.php
View source
<?php
namespace Drupal\address\Plugin\Field\FieldType;
use CommerceGuys\Addressing\Zone\Zone;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
class ZoneItem extends FieldItemBase {
use AvailableCountriesTrait;
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'description' => 'The serialized zone.',
'type' => 'blob',
'not null' => TRUE,
'serialize' => TRUE,
],
],
];
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = [];
$properties['value'] = DataDefinition::create('any')
->setLabel(t('Value'))
->setRequired(TRUE);
return $properties;
}
public static function defaultFieldSettings() {
return self::defaultCountrySettings();
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
return $this
->countrySettingsForm($form, $form_state);
}
public function isEmpty() {
return $this->value === NULL || !$this->value instanceof Zone;
}
public function setValue($values, $notify = TRUE) {
if (is_array($values)) {
$values = reset($values);
}
if (!$values instanceof Zone) {
$values = NULL;
}
parent::setValue($values, $notify);
}
}
Classes
Name |
Description |
ZoneItem |
Plugin implementation of the 'zone' field type. |