You are here

public function ContentLockSettingsForm::submitForm in Content locking (anti-concurrent editing) 8

Same name and namespace in other branches
  1. 8.2 src/Form/ContentLockSettingsForm.php \Drupal\content_lock\Form\ContentLockSettingsForm::submitForm()

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/ContentLockSettingsForm.php, line 231

Class

ContentLockSettingsForm
Class ContentLockSettingsForm.

Namespace

Drupal\content_lock\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $content_lock = $this
    ->config('content_lock.settings');
  $definitions = $this->entityTypeManager
    ->getDefinitions();
  foreach ($definitions as $definition) {
    if ($definition instanceof ContentEntityTypeInterface) {
      if ($form_state
        ->getValue($definition
        ->id())) {
        $content_lock
          ->set('types.' . $definition
          ->id(), $this
          ->removeEmptyValue($form_state
          ->getValue([
          $definition
            ->id(),
          'bundles',
        ])));
        $translation_lock = (bool) $form_state
          ->getValue([
          $definition
            ->id(),
          'settings',
          'translation_lock',
        ]);
        $types_translation_lock = $content_lock
          ->get('types_translation_lock') ?: [];
        if ($translation_lock && !in_array($definition
          ->id(), $types_translation_lock)) {
          $types_translation_lock[] = $definition
            ->id();
        }
        elseif (!$translation_lock && in_array($definition
          ->id(), $types_translation_lock)) {
          $types_translation_lock = array_diff($types_translation_lock, [
            $definition
              ->id(),
          ]);
        }
        $content_lock
          ->set('types_translation_lock', $types_translation_lock);
        $js_lock = (bool) $form_state
          ->getValue([
          $definition
            ->id(),
          'settings',
          'js_lock',
        ]);
        $types_js_lock = $content_lock
          ->get('types_js_lock') ?: [];
        if ($js_lock && !in_array($definition
          ->id(), $types_js_lock)) {
          $types_js_lock[] = $definition
            ->id();
        }
        elseif (!$js_lock && in_array($definition
          ->id(), $types_js_lock)) {
          $types_js_lock = array_diff($types_js_lock, [
            $definition
              ->id(),
          ]);
        }
        $content_lock
          ->set('types_js_lock', $types_js_lock);
        $content_lock
          ->set('form_op_lock.' . $definition
          ->id() . '.mode', $form_state
          ->getValue([
          $definition
            ->id(),
          'settings',
          'form_op_lock',
          'mode',
        ]));
        $content_lock
          ->set('form_op_lock.' . $definition
          ->id() . '.values', $this
          ->removeEmptyValue((array) $form_state
          ->getValue([
          $definition
            ->id(),
          'settings',
          'form_op_lock',
          'values',
        ])));
      }
    }
  }
  $content_lock
    ->set('verbose', $form_state
    ->getValue('verbose'))
    ->save();
}