You are here

public function ParserConfigurationForm::validateSubform in Markdown 8.2

Subform validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Form/ParserConfigurationForm.php, line 775

Class

ParserConfigurationForm
Form for modifying parser configuration.

Namespace

Drupal\markdown\Form

Code

public function validateSubform(array &$form, FormStateInterface $form_state) {

  // Immediately return if no subform parents or form hasn't submitted.
  if (!($arrayParents = $form_state
    ->get('markdownSubformArrayParents')) || !$form_state
    ->isSubmitted()) {
    return;
  }

  // Submit handlers aren't necessarily known until a user has started the.
  // process of submitting the form. The triggering element might have
  // specific submit handlers that needs to be intercepted and the only place
  // that this can be done is during the validation phase.
  if ($submitHandlers = $form_state
    ->getSubmitHandlers()) {
    if (!in_array([
      $this,
      'submitSubform',
    ], $submitHandlers)) {
      array_unshift($submitHandlers, [
        $this,
        'submitSubform',
      ]);
      $form_state
        ->setSubmitHandlers($submitHandlers);
    }
  }
  else {
    $complete_form =& $form_state
      ->getCompleteForm();
    $complete_form['#submit'][] = [
      $this,
      'submitSubform',
    ];
  }
  $subform =& NestedArray::getValue($form, $arrayParents);
  $subformState = SubformState::createForSubform($subform, $form, $form_state);
  $parserId = $subformState
    ->getValue('id');
  if ($parserId && $this->parserManager
    ->hasDefinition($parserId)) {
    $parser = $this->parserManager
      ->createInstance($parserId, $subformState
      ->getValues());
    if ($parser instanceof SettingsInterface && $parser instanceof PluginFormInterface && !empty($subform['parser']['settings'])) {
      $parser
        ->validateConfigurationForm($subform['parser']['settings'], SubformState::createForSubform($subform['parser']['settings'], $subform, $subformState));
    }
    if ($parser instanceof ExtensibleParserInterface && !empty($subform['parser']['extensions'])) {
      foreach ($parser
        ->extensions() as $extensionId => $extension) {
        if ($extension instanceof SettingsInterface && $extension instanceof PluginFormInterface && isset($subform['parser']['extensions'][$extensionId]['settings'])) {
          $extension
            ->validateConfigurationForm($subform['parser']['extensions'][$extensionId]['settings'], SubformState::createForSubform($subform['parser']['extensions'][$extensionId]['settings'], $subform, $subformState));
        }
      }
    }
  }
}