diff -u b/src/Plugin/Field/FieldType/Gender.php b/src/Plugin/Field/FieldType/Gender.php --- b/src/Plugin/Field/FieldType/Gender.php +++ b/src/Plugin/Field/FieldType/Gender.php @@ -2,11 +2,12 @@ namespace Drupal\gender\Plugin\Field\FieldType; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\DataDefinition; -use Drupal\options\Plugin\Field\FieldType\ListStringItem; +use Drupal\options\Plugin\Field\FieldType\ListItemBase; /** * Plugin implementation of the gender field type. @@ -21,7 +22,7 @@ * default_formatter = "list_default" * ) */ -class Gender extends ListStringItem { +class Gender extends ListItemBase { /** * {@inheritdoc} @@ -38,6 +39,23 @@ /** * {@inheritdoc} */ + public static function schema(FieldStorageDefinitionInterface $field_definition) { + return [ + 'columns' => [ + 'value' => [ + 'type' => 'varchar', + 'length' => 255, + ], + ], + 'indexes' => [ + 'value' => ['value'], + ], + ]; + } + + /** + * {@inheritdoc} + */ public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { return []; } @@ -53,2 +71,25 @@ + /** + * {@inheritdoc} + */ + protected static function validateAllowedValue($option) { + if (Unicode::strlen($option) > 255) { + return t('Allowed values list: each key must be a string at most 255 characters long.'); + } + } + + /** + * {@inheritdoc} + */ + protected static function castAllowedValue($value) { + return (string) $value; + } + + /** + * {@inheritdoc} + */ + protected function allowedValuesDescription() { + return ''; + } + }