[ 'location' => [ 'description' => "The actual location reference in the showroom.", 'type' => 'text', 'size' => 'tiny', // 'not null' => FALSE, ], 'target_id' => [ 'description' => 'the id of the target taxonomy term.', 'type' => 'int', 'unsigned' => TRUE ] ], 'indexes' => [ 'target_id' => ['target_id'], ], ]; } /** * {@inheritdoc} */ public function isEmpty() { $value = $this->get('location')->getValue(); return $value === NULL || $value === ''; } /** * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['location'] = DataDefinition::create('string') ->setLabel(t('Reference')); $properties['target_id'] = DataReferenceTargetDefinition::create('integer') // ->setLabel(new TranslatableMarkup('@label ID', ['@label' => $target_type_info->getLabel()])) ->setLabel(new TranslatableMarkup('@label ID', ['@label' => 'Showroom'])) // get voc name from settings ->setSetting('unsigned', TRUE) ->setRequired(TRUE); return $properties; } /** * {@inheritdoc} */ public static function defaultFieldSettings() { return [ // Declare a single setting, 'size', with a default // value of 'large' 'vid' => null, ] + parent::defaultFieldSettings(); } /** * {@inheritdoc} */ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { // dsm($form); // get vocabularies $vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple(); // dsm($vocabularies); $options = [null => "choose"]; foreach ($vocabularies as $vid => $voc) { $options[$voc->id()] = $voc->label(); } // dsm($options); $element = []; // The key of the element should be the setting name $element['vid'] = [ '#title' => $this->t('Vocabulary'), '#type' => 'select', '#options' => $options, '#default_value' => $this->getSetting('vid'), ]; return $element; } /** * Form element validation handler; Invokes selection plugin's validation. * * @param array $form * The form where the settings form is being included in. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the (entire) configuration form. */ public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) { $field = $form_state->getFormObject()->getEntity(); dsm($field); } }