You are here

protected function TawkToExtraSettingsForm::submitVisibility in Tawk.to - Live chat application (Drupal 8) 8

Same name and namespace in other branches
  1. 8.2 src/Form/TawkToExtraSettingsForm.php \Drupal\tawk_to\Form\TawkToExtraSettingsForm::submitVisibility()

Helper function to independently submit the visibility UI.

Parameters

array $form: A nested array form elements comprising the form.

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

1 call to TawkToExtraSettingsForm::submitVisibility()
TawkToExtraSettingsForm::submitForm in src/Form/TawkToExtraSettingsForm.php
Form submission handler.

File

src/Form/TawkToExtraSettingsForm.php, line 247

Class

TawkToExtraSettingsForm
Provides form for block instance forms.

Namespace

Drupal\tawk_to\Form

Code

protected function submitVisibility(array $form, FormStateInterface $form_state) {
  $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
      ->submitConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form, $form_state));
    if ($condition instanceof ContextAwarePluginInterface) {
      $contextMapping = isset($values['context_mapping']) ? $values['context_mapping'] : [];
      $condition
        ->setContextMapping($contextMapping);
    }
    $conditionConfiguration = $condition
      ->getConfiguration();

    // Save the visibility conditions to config.
    $visibility[$condition_id] = $conditionConfiguration;
  }
  $this
    ->config('tawk_to.settings')
    ->set('visibility', $visibility)
    ->save();
}