You are here

public static function YamlFormEntityReferenceSelectWidget::validateYamlFormEntityReferenceSelectWidget in YAML Form 8

Form element validation handler for entity_select elements.

File

src/Plugin/Field/FieldWidget/YamlFormEntityReferenceSelectWidget.php, line 81

Class

YamlFormEntityReferenceSelectWidget
Plugin implementation of the 'yamlform_entity_reference_select' widget.

Namespace

Drupal\yamlform\Plugin\Field\FieldWidget

Code

public static function validateYamlFormEntityReferenceSelectWidget(array &$element, FormStateInterface $form_state, array &$complete_form) {

  // Below prevents the below error.
  // Fatal error: Call to a member function uuid() on a non-object in
  // core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php.
  $value = !empty($element['target_id']['#value']) ? $element['target_id']['#value'] : NULL;
  $form_state
    ->setValueForElement($element['target_id'], $value);
}