You are here

public function AdminExclude::submitForm in Image Lazyloader 8

Form submission 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.

Overrides ConfigFormBase::submitForm

File

src/Form/AdminExclude.php, line 66

Class

AdminExclude
Class AdminExclude.

Namespace

Drupal\lazyloader\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $this
    ->config('lazyloader.exclude')
    ->set('filenames', $form_state
    ->get('filenames'));

  // Submit visibility condition settings.
  $visibility = $this
    ->config('lazyloader.exclude')
    ->get('visibility') ?: [];
  foreach ($form_state
    ->getValue('visibility') as $condition_id => $values) {

    // Allow the condition to submit the form.
    $condition = $form_state
      ->get([
      'conditions',
      $condition_id,
    ]);
    $condition_values = (new FormState())
      ->setValues($values);
    $condition
      ->submitConfigurationForm($form, $condition_values);
    if ($condition instanceof ContextAwarePluginInterface) {
      $context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : [];
      $condition
        ->setContextMapping($context_mapping);
    }

    // Update the original form values.
    $condition_configuration = $condition
      ->getConfiguration();
    $form_state
      ->setValue([
      'visibility',
      $condition_id,
    ], $condition_configuration);

    // Update the visibility conditions on the block.
    $visibility[$condition_id] = $condition_configuration;
  }
  $this
    ->config('lazyloader.exclude')
    ->set('visibility', $visibility)
    ->save();
}