You are here

public function NodeTitleValidationAdminForm::submitForm in Node Title Validation 1.0.x

Same name and namespace in other branches
  1. 8 src/Form/NodeTitleValidationAdminForm.php \Drupal\node_title_validation\Form\NodeTitleValidationAdminForm::submitForm()
  2. 2.0.x src/Form/NodeTitleValidationAdminForm.php \Drupal\node_title_validation\Form\NodeTitleValidationAdminForm::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 FormInterface::submitForm

File

src/Form/NodeTitleValidationAdminForm.php, line 207

Class

NodeTitleValidationAdminForm
Class NodeTitleValidationAdminForm.

Namespace

Drupal\node_title_validation\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = [];

  // Get available content types.
  $node_types = $this->entityTypeManager
    ->getStorage('node_type')
    ->loadMultiple();

  // Store Form values in node_title_validation_config variable.
  foreach ($node_types as $type) {
    $values['comma-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'comma-' . $type
        ->get('type'),
    ]);
    $values['exclude-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'exclude-' . $type
        ->get('type'),
    ]);
    $values['min-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'min-' . $type
        ->get('type'),
    ]);
    $values['max-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'max-' . $type
        ->get('type'),
    ]);
    $values['min-wc-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'min-wc-' . $type
        ->get('type'),
    ]);
    $values['max-wc-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'max-wc-' . $type
        ->get('type'),
    ]);
    $values['unique-' . $type
      ->get('type')] = $form_state
      ->getValue([
      'unique-' . $type
        ->get('type'),
    ]);
  }
  $values['unique'] = $form_state
    ->getValue([
    'unique',
  ]);

  // Set node_title_validation_config variable.
  $this->configFactory
    ->getEditable('node_title_validation.node_title_validation_settings')
    ->set('node_title_validation_config', $values)
    ->save();
  $this->messenger
    ->addMessage($this
    ->t('Node Title Validation Configurations saved successfully!'));
}