You are here

protected function YamlFormSubmissionForm::prepareElements in YAML Form 8

Prepare form elements.

Parameters

array $elements: An render array representing elements.

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 call to YamlFormSubmissionForm::prepareElements()
YamlFormSubmissionForm::form in src/YamlFormSubmissionForm.php
Gets the actual form array to be built.

File

src/YamlFormSubmissionForm.php, line 1216

Class

YamlFormSubmissionForm
Provides a form to collect and edit submissions.

Namespace

Drupal\yamlform

Code

protected function prepareElements(array &$elements, array &$form, FormStateInterface $form_state) {
  foreach ($elements as $key => &$element) {
    if (Element::property($key) || !is_array($element)) {
      continue;
    }

    // Replace default_value tokens
    // Invoke YamlFormElement::prepare.
    $this->elementManager
      ->invokeMethod('prepare', $element, $this->entity);

    // Initialize default values.
    // Invoke YamlFormElement::setDefaultValue.
    $this->elementManager
      ->invokeMethod('setDefaultValue', $element);

    // Allow modules to alter the form element.
    // @see \Drupal\Core\Field\WidgetBase::formSingleElement()
    $hooks = [
      'yamlform_element',
    ];
    if (!empty($element['#type'])) {
      $hooks[] = 'yamlform_element_' . $element['#type'];
    }
    $context = [
      'form' => $form,
    ];
    $this->moduleHandler
      ->alter($hooks, $element, $form_state, $context);

    // Recurse and prepare nested elements.
    $this
      ->prepareElements($element, $form, $form_state);
  }
}