You are here

public function ConfirmDeleteForm::submitForm in Hashtags 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 FormInterface::submitForm

File

src/Form/ConfirmDeleteForm.php, line 80

Class

ConfirmDeleteForm

Namespace

Drupal\hashtags\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $hashtags_field_name = \Drupal::config('hashtags.settings')
    ->get('hashtags_taxonomy_terms_field_name');
  $hashtags_field = FieldConfig::loadByName($this->entity_type, $this->bundle, $hashtags_field_name);
  if (!empty($hashtags_field)) {
    $hashtags_field
      ->delete();
    \Drupal::messenger()
      ->addMessage('Hashtags field has been removed.');
    $activated_text_fields = _hashtags_get_activated_text_fields($this->entity_type, $this->bundle);
    foreach ($activated_text_fields as $field_name) {
      $text_field = \Drupal::entityTypeManager()
        ->getStorage('field_config')
        ->load("{$this->entity_type}.{$this->bundle}.{$field_name}");
      if (!empty($text_field)) {
        $text_field
          ->unsetThirdPartySetting('hashtags', 'hashtags_activate');
        $text_field
          ->save();
        \Drupal::messenger()
          ->addMessage("Hashtags has been diactivated for {$field_name} field.");
      }
    }
  }
  $form_state
    ->setRedirectUrl(new Url('hashtags.manager_form'));
}