You are here

protected function YamlFormSubmissionForm::hideElements in YAML Form 8

Hide form elements by settings their #access to FALSE.

Parameters

array $elements: An render array representing elements.

1 call to YamlFormSubmissionForm::hideElements()
YamlFormSubmissionForm::displayCurrentPage in src/YamlFormSubmissionForm.php
Set form wizard current page.

File

src/YamlFormSubmissionForm.php, line 1153

Class

YamlFormSubmissionForm
Provides a form to collect and edit submissions.

Namespace

Drupal\yamlform

Code

protected function hideElements(&$elements) {
  foreach ($elements as $key => &$element) {
    if (Element::property($key) || !is_array($element)) {
      continue;
    }

    // Set #access to FALSE which will suppresses form #required validation.
    $element['#access'] = FALSE;

    // ISSUE: Hidden elements still need to call #element_validate because
    // certain elements, including managed_file, checkboxes, password_confirm,
    // etc..., will also massage the submitted values via #element_validate.
    //
    // SOLUTION: Call #element_validate for all hidden elements but suppresses
    // #element_validate errors.
    //
    // Set hidden element #after_build handler.
    $element['#after_build'][] = [
      get_class($this),
      'hiddenElementAfterBuild',
    ];
    $this
      ->hideElements($element);
  }
}