You are here

public function SubmitButtonRules::processForm in Flexiform 8

Process Form Enhancer.

File

contrib/rules/src/Plugin/FormEnhancer/SubmitButtonRules.php, line 294

Class

SubmitButtonRules
A flexiform enhancer to trigger rules on submission.

Namespace

Drupal\flexiform_rules\Plugin\FormEnhancer

Code

public function processForm($element, FormStateInterface $form_state, $form) {
  foreach (array_filter($this->configuration) as $key => $redirect) {
    $array_parents = explode('::', $key);
    $button = NestedArray::getValue($element, $array_parents, $exists);
    if ($exists) {
      if (empty($button['#submit'])) {
        $button['#submit'] = !empty($form['#submit']) ? $form['#submit'] : [];
      }
      $button['#submit'][] = [
        $this,
        'formSubmitRules',
      ];
      $button['#submit_rules'] = $this->configuration[$key]['rules'];
      NestedArray::setValue($element, $array_parents, $button);
    }
  }
  return $element;
}