You are here

public static function YamlFormManagedFileBase::validate in YAML Form 8

Form API callback. Consolidate the array of fids for this field into a single fids.

File

src/Plugin/YamlFormElement/YamlFormManagedFileBase.php, line 512

Class

YamlFormManagedFileBase
Provides a base class form 'managed_file' elements.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

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

  // Call the default managed_element validation handler, which checks
  // the file entity and #required.
  // @see \Drupal\file\Element\ManagedFile::getInfo
  // @see \Drupal\yamlform\Plugin\YamlFormElement\ManagedFile::prepare
  ManagedFileElement::validateManagedFile($element, $form_state, $complete_form);
  if (!empty($element['#files'])) {
    $fids = array_keys($element['#files']);
    if (empty($element['#multiple'])) {
      $form_state
        ->setValueForElement($element, reset($fids));
    }
    else {
      $form_state
        ->setValueForElement($element, $fids);
    }
  }
  else {
    $form_state
      ->setValueForElement($element, NULL);
  }
}