SubmitButtonFormEnhancerTrait.php in Flexiform 8
File
src/FormEnhancer/SubmitButtonFormEnhancerTrait.php
View source
<?php
namespace Drupal\flexiform\FormEnhancer;
use Drupal\Core\Render\Element;
trait SubmitButtonFormEnhancerTrait {
protected $formDisplay;
protected function locateSubmitButtons() {
$form_info = $this->formDisplay
->getFormInformation();
return $this
->locateSubmitButtonsR($form_info['form']);
}
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;
}
}