You are here

YamlFormEntitySelect.php in YAML Form 8

File

src/Element/YamlFormEntitySelect.php
View source
<?php

namespace Drupal\yamlform\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Select;

/**
 * Provides a form element for a entity select menu.
 *
 * @FormElement("yamlform_entity_select")
 */
class YamlFormEntitySelect extends Select {
  use YamlFormEntityTrait;

  /**
   * {@inheritdoc}
   */
  public static function processSelect(&$element, FormStateInterface $form_state, &$complete_form) {
    self::setOptions($element);
    $element = parent::processSelect($element, $form_state, $complete_form);

    // Must convert this element['#type'] to a 'select' to prevent
    // "Illegal choice %choice in %name element" validation error.
    // @see \Drupal\Core\Form\FormValidator::performRequiredValidation
    $element['#type'] = 'select';
    return $element;
  }

}

Classes

Namesort descending Description
YamlFormEntitySelect Provides a form element for a entity select menu.