setRedirectUrl example

/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entity->delete();

    $this->messenger()->addStatus($this->t(
      'Workflow %label deleted.',
      ['%label' => $this->entity->label()]
    ));

    $form_state->setRedirectUrl($this->getCancelUrl());
  }

}
/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Cancel account immediately, if the current user has administrative     // privileges, no confirmation mail shall be sent, and the user does not     // attempt to cancel the own account.     if (!$form_state->isValueEmpty('access') && $form_state->isValueEmpty('user_cancel_confirm') && $this->entity->id() != $this->currentUser()->id()) {
      user_cancel($form_state->getValues()$this->entity->id()$form_state->getValue('user_cancel_method'));

      $form_state->setRedirectUrl($this->entity->toUrl('collection'));
    }
    else {
      // Store cancelling method and whether to notify the user in       // $this->entity for       // \Drupal\user\Controller\UserController::confirmCancel().       $this->entity->user_cancel_method = $form_state->getValue('user_cancel_method');
      $this->entity->user_cancel_notify = $form_state->getValue('user_cancel_notify');
      $this->entity->save();
      _user_mail_notify('cancel_confirm', $this->entity);
      $this->messenger()->addStatus($this->t('A confirmation request to cancel your account has been sent to your email address.'));
      $this->logger('user')->info('Sent account cancellation request to %name %email.', ['%name' => $this->entity->label(), '%email' => '<' . $this->entity->getEmail() . '>']);

      
public function submitForm(array &$form, FormStateInterface $form_state) {
    try {
      $this->workspaceManager->setActiveWorkspace($this->entity);
      $this->messenger->addMessage($this->t('%workspace_label is now the active workspace.', ['%workspace_label' => $this->entity->label()]));
    }
    catch (WorkspaceAccessException $e) {
      $this->messenger->addError($this->t('You do not have access to activate the %workspace_label workspace.', ['%workspace_label' => $this->entity->label()]));
    }

    // Redirect to the workspace manage page by default.     if (!$this->getRequest()->query->has('destination')) {
      $form_state->setRedirectUrl($this->entity->toUrl());
    }
  }

  /** * Checks access for the workspace activate form. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * * @return \Drupal\Core\Access\AccessResult * The access result. */
return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if (!$form_state->isValueEmpty('redirection')) {
      if (!$form_state->isValueEmpty('destination')) {
        // The destination is a random URL, so we can't use routed URLs.         // @todo Revisit this in https://www.drupal.org/node/2418219.         $form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination')));
      }
    }
    else {
      $form_state->disableRedirect();
    }
  }

}
return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->taxonomyTerm->delete();
    $this->messenger()->addStatus($this->t('The forum %label and all sub-forums have been deleted.', ['%label' => $this->taxonomyTerm->label()]));
    $this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', ['%label' => $this->taxonomyTerm->label()]);
    $form_state->setRedirectUrl($this->getCancelUrl());
  }

}

  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $return = parent::save($form$form_state);

    $this->layoutTempstoreRepository->delete($this->sectionStorage);
    $this->messenger()->addStatus($this->t('The layout override has been saved.'));
    $form_state->setRedirectUrl($this->sectionStorage->getRedirectUrl());
    return $return;
  }

  /** * {@inheritdoc} */
  protected function actions(array $form, FormStateInterface $form_state) {
    $actions = parent::actions($form$form_state);
    $actions['#attributes']['role'] = 'region';
    $actions['#attributes']['aria-label'] = $this->t('Layout Builder tools');
    $actions['submit']['#value'] = $this->t('Save layout');
    


    // Override the "status" base field default value, for this media type.     $fields = $this->entityFieldManager->getFieldDefinitions('media', $media_type->id());
    /** @var \Drupal\media\MediaInterface $media */
    $media = $this->entityTypeManager->getStorage('media')->create(['bundle' => $media_type->id()]);
    $value = (bool) $form_state->getValue(['options', 'status']);
    if ($media->status->value != $value) {
      $fields['status']->getConfig($media_type->id())->setDefaultValue($value)->save();
    }

    $form_state->setRedirectUrl($media_type->toUrl('collection'));
  }

}
$this->messenger()->addStatus($this->t('@type %label has been created.', $t_args));
    }
    else {
      $logger->info('@type: updated %label.', $context);
      $this->messenger()->addStatus($this->t('@type %label has been updated.', $t_args));
    }

    // Redirect the user to the media overview if the user has the 'access media     // overview' permission. If not, redirect to the canonical URL of the media     // item.     if ($this->currentUser()->hasPermission('access media overview')) {
      $form_state->setRedirectUrl($this->entity->toUrl('collection'));
    }
    else {
      $form_state->setRedirectUrl($this->entity->toUrl());
    }

    return $saved;
  }

}

  public function entityFormSave(array $form, FormStateInterface $form_state) {
    if ($this->getSourceLangcode($form_state)) {
      $entity = $form_state->getFormObject()->getEntity();
      // We need a redirect here, otherwise we would get an access denied page       // since the current URL would be preserved and we would try to add a       // translation for a language that already has a translation.       $form_state->setRedirectUrl($entity->toUrl());
    }
  }

}
$wizard = $form_state->get('wizard_instance');
      $this->entity = $wizard->createView($form$form_state);
    }
    // @todo Figure out whether it really makes sense to throw and catch exceptions on the wizard.     catch (WizardException $e) {
      $this->messenger()->addError($e->getMessage());
      $form_state->setRedirect('entity.view.collection');
      return;
    }
    $this->entity->save();
    $this->messenger()->addStatus($this->t('The view %name has been saved.', ['%name' => $form_state->getValue('label')]));
    $form_state->setRedirectUrl($this->entity->toUrl('edit-form'));
  }

  /** * Form submission handler for the 'cancel' action. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */
  public function cancel(array $form, FormStateInterface $form_state) {
    

    $entity->save();

    $this->messenger()->addStatus($this->t('The moderation state has been updated.'));

    $new_state = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($new_state);
    // The page we're on likely won't be visible if we just set the entity to     // the default state, as we hide that latest-revision tab if there is no     // pending revision. Redirect to the canonical URL instead, since that will     // still exist.     if ($new_state->isDefaultRevisionState()) {
      $form_state->setRedirectUrl($entity->toUrl('canonical'));
    }
  }

}
/** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $return = $workflow->save();
    if (empty($workflow->getTypePlugin()->getStates())) {
      $this->messenger()->addStatus($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
        '%label' => $workflow->label(),
      ]));
      $form_state->setRedirectUrl($workflow->toUrl('add-state-form'));
    }
    else {
      $this->messenger()->addStatus($this->t('Created the %label Workflow.', [
        '%label' => $workflow->label(),
      ]));
      $form_state->setRedirectUrl($workflow->toUrl('edit-form'));
    }
    return $return;
  }

  /** * {@inheritdoc} */
    // @todo Make it possible to get default values without an entity.     // https://www.drupal.org/node/2318187     $node = $this->entityTypeManager->getStorage('node')->create(['type' => $type->id()]);
    foreach (['status', 'promote', 'sticky'] as $field_name) {
      $value = (bool) $form_state->getValue(['options', $field_name]);
      if ($node->$field_name->value != $value) {
        $fields[$field_name]->getConfig($type->id())->setDefaultValue($value)->save();
      }
    }

    $this->entityFieldManager->clearCachedFieldDefinitions();
    $form_state->setRedirectUrl($type->toUrl('collection'));
  }

}
'#required' => TRUE,
    ];

    return parent::form($form$form_state);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    parent::save($form$form_state);
    $form_state->setRedirectUrl($this->entity->toUrl('edit-form'));
  }

}
$this->messenger()->addStatus($this->t('Responsive image style %label saved.', ['%label' => $responsive_image_style->label()]));

    // Redirect to edit form after creating a new responsive image style or     // after selecting another breakpoint group.     if (!$responsive_image_style->hasImageStyleMappings()) {
      $form_state->setRedirect(
        'entity.responsive_image_style.edit_form',
        ['responsive_image_style' => $responsive_image_style->id()]
      );
    }
    else {
      $form_state->setRedirectUrl($this->entity->toUrl('collection'));
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.