You are here

trait SubmitButtonFormEnhancerTrait in Flexiform 8

Trait for submit buttons in form enhancers.

Hierarchy

4 files declare their use of SubmitButtonFormEnhancerTrait
SubmitButtonAjax.php in src/Plugin/FormEnhancer/SubmitButtonAjax.php
SubmitButtonLabel.php in src/Plugin/FormEnhancer/SubmitButtonLabel.php
SubmitButtonRedirect.php in src/Plugin/FormEnhancer/SubmitButtonRedirect.php
SubmitButtonRules.php in contrib/rules/src/Plugin/FormEnhancer/SubmitButtonRules.php

File

src/FormEnhancer/SubmitButtonFormEnhancerTrait.php, line 10

Namespace

Drupal\flexiform\FormEnhancer
View source
trait SubmitButtonFormEnhancerTrait {

  /**
   * Form display.
   *
   * @var \Drupal\flexiform\FlexiformEntityFormDisplayInterface
   */
  protected $formDisplay;

  /**
   * Locate any submit buttons in the form.
   *
   * @return array
   *   The buttons in the form.
   */
  protected function locateSubmitButtons() {
    $form_info = $this->formDisplay
      ->getFormInformation();
    return $this
      ->locateSubmitButtonsR($form_info['form']);
  }

  /**
   * Locate the submit buttons recursively.
   */
  private function locateSubmitButtonsR($elements, $depth = 0) {
    $buttons = [];
    foreach (Element::children($elements) as $key) {
      if ($depth == 0 && $this->formDisplay
        ->getComponent($key)) {
        continue;
      }
      if (isset($elements[$key]['#type']) && $elements[$key]['#type'] == 'submit') {
        $buttons[implode('][', $elements[$key]['#array_parents'])] = $elements[$key]['#value'];
      }
      $buttons += $this
        ->locateSubmitButtonsR($elements[$key], $depth + 1);
    }
    return $buttons;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SubmitButtonFormEnhancerTrait::$formDisplay protected property Form display.
SubmitButtonFormEnhancerTrait::locateSubmitButtons protected function Locate any submit buttons in the form.
SubmitButtonFormEnhancerTrait::locateSubmitButtonsR private function Locate the submit buttons recursively.