You are here

public function SmartDateOverrideDeleteForm::submitForm in Smart Date 3.4.x

Same name and namespace in other branches
  1. 8.2 modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideDeleteForm::submitForm()
  2. 3.x modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideDeleteForm::submitForm()
  3. 3.0.x modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideDeleteForm::submitForm()
  4. 3.1.x modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideDeleteForm::submitForm()
  5. 3.2.x modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideDeleteForm::submitForm()
  6. 3.3.x modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideDeleteForm::submitForm()

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

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 ContentEntityForm::submitForm

File

modules/smart_date_recur/src/Form/SmartDateOverrideDeleteForm.php, line 42

Class

SmartDateOverrideDeleteForm
Provides a deletion confirmation form for Smart Date Overrides.

Namespace

Drupal\smart_date_recur\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // TODO: Delete override entity, if it exists.
  $this->entity
    ->delete();

  /* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */
  $entityTypeManager = \Drupal::service('entity_type.manager');
  $rrid = $this->entity->rrule
    ->getString();

  /* @var \Drupal\smart_date_recur\Entity\SmartDateRule $rrule */
  $rrule = $entityTypeManager
    ->getStorage('smart_date_rule')
    ->load($rrid);
  $instanceController = new Instances();

  // Force refresh of parent entity.
  $instanceController
    ->applyChanges($rrule);

  // Output message about operation performed.
  $this
    ->messenger()
    ->addMessage($this
    ->t('The instance has been reverted to default.'));
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
}