You are here

public function AutoEntityLabelForm::submitForm in Automatic Entity Label 8.3

Same name and namespace in other branches
  1. 8 src/Form/AutoEntityLabelForm.php \Drupal\auto_entitylabel\Form\AutoEntityLabelForm::submitForm()
  2. 8.2 src/Form/AutoEntityLabelForm.php \Drupal\auto_entitylabel\Form\AutoEntityLabelForm::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/AutoEntityLabelForm.php, line 284

Class

AutoEntityLabelForm
Class AutoEntityLabelForm.

Namespace

Drupal\auto_entitylabel\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this->configFactory
    ->getEditable($this
    ->getConfigName());
  $form_state
    ->cleanValues();
  foreach ([
    'status',
    'pattern',
    'escape',
    'preserve_titles',
    'save',
    'chunk',
  ] as $key) {
    $config
      ->set($key, $form_state
      ->getValue($key));
  }

  /** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */
  $storage = $this->entityTypeManager
    ->getStorage($this->entityType);

  /** @var \Drupal\Core\Config\Entity\ConfigEntityType $entity_type */
  $entity_type = $storage
    ->getEntityType();
  $prefix = $entity_type
    ->getConfigPrefix();
  $bundle = $entity_type
    ->getBundleOf();
  $config
    ->set('dependencies', [
    'config' => [
      $prefix . '.' . $this->entityBundle,
    ],
  ]);
  $config
    ->save();

  // If user checked the re-save option, set batch for re-saving labels.
  if ($config
    ->get('save')) {
    $this
      ->setBatch($this->entityBundle, $bundle, $config
      ->get('chunk'));
  }
  parent::submitForm($form, $form_state);
}