You are here

public static function FlexiformEntityFormDisplay::addSaveFormEntitiesSubmit in Flexiform 8

Look through the form to find submit buttons.

If they have the save submit method then add our saveEntities submit callback.

@todo: Move onto the multiple_entities enhancer plugin.

Parameters

array $element: The element to add the submit callback to. If this is not a submit element then continue to search the children.

\Drupal\flexiform\FlexiformEntityFormDisplayInterface $form_display: The flexiform entity form display.

1 call to FlexiformEntityFormDisplay::addSaveFormEntitiesSubmit()
FlexiformEntityFormDisplay::processForm in src/FlexiformEntityFormDisplay.php
Process callback: assigns weights and hides extra fields.

File

src/FlexiformEntityFormDisplay.php, line 402

Class

FlexiformEntityFormDisplay
Defines a class to extend EntityFormDisplays.

Namespace

Drupal\flexiform

Code

public static function addSaveFormEntitiesSubmit(array &$element, FlexiformEntityFormDisplayInterface $form_display) {
  if (isset($element['#type']) && $element['#type'] == 'submit') {
    if (!empty($element['#submit']) && in_array('::save', $element['#submit'])) {
      $new_submit = [];

      // Add extra submit handlers to all buttons on the form.
      // This includes adding a formSubmitComponents callback to allow
      // components to have their own submission logic. This applies
      // BEFORE the entities are saved.
      // Also add the 'saveFormEntities' callback immediatly after the
      // standard '::save'.
      foreach ($element['#submit'] as $callback) {
        if ($callback == '::save') {
          $new_submit[] = [
            $form_display,
            'formSubmitComponents',
          ];
        }
        $new_submit[] = $callback;
        if ($callback == '::save') {
          $new_submit[] = [
            $form_display,
            'saveFormEntities',
          ];
        }
      }
      $element['#submit'] = $new_submit;
    }
    if (!empty($element['#validate'])) {

      // Add extra validate handler to all buttons on the form.
      // This allows form components to have their own validation logic.
      $element['#validate'][] = [
        $form_display,
        'formValidateComponents',
      ];
    }
  }
  else {
    foreach (Element::children($element) as $key) {
      FlexiformEntityFormDisplay::addSaveFormEntitiesSubmit($element[$key], $form_display);
    }
  }
}