trait SubmitButtonFormEnhancerTrait in Flexiform 8
Trait for submit buttons in form enhancers.
Hierarchy
- trait \Drupal\flexiform\FormEnhancer\SubmitButtonFormEnhancerTrait
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\FormEnhancerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SubmitButtonFormEnhancerTrait:: |
protected | property | Form display. | |
SubmitButtonFormEnhancerTrait:: |
protected | function | Locate any submit buttons in the form. | |
SubmitButtonFormEnhancerTrait:: |
private | function | Locate the submit buttons recursively. |