class SmartDateRemoveInstanceForm in Smart Date 3.x
Same name and namespace in other branches
- 8.2 modules/smart_date_recur/src/Form/SmartDateRemoveInstanceForm.php \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
- 3.0.x modules/smart_date_recur/src/Form/SmartDateRemoveInstanceForm.php \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
- 3.1.x modules/smart_date_recur/src/Form/SmartDateRemoveInstanceForm.php \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
- 3.2.x modules/smart_date_recur/src/Form/SmartDateRemoveInstanceForm.php \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
- 3.3.x modules/smart_date_recur/src/Form/SmartDateRemoveInstanceForm.php \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
- 3.4.x modules/smart_date_recur/src/Form/SmartDateRemoveInstanceForm.php \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
Provides an instance cancellation confirmation form for Smart Date.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\smart_date_recur\Form\SmartDateRemoveInstanceForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of SmartDateRemoveInstanceForm
1 file declares its use of SmartDateRemoveInstanceForm
- Instances.php in modules/
smart_date_recur/ src/ Controller/ Instances.php
1 string reference to 'SmartDateRemoveInstanceForm'
- smart_date_recur.routing.yml in modules/
smart_date_recur/ smart_date_recur.routing.yml - modules/smart_date_recur/smart_date_recur.routing.yml
File
- modules/
smart_date_recur/ src/ Form/ SmartDateRemoveInstanceForm.php, line 17
Namespace
Drupal\smart_date_recur\FormView source
class SmartDateRemoveInstanceForm extends ConfirmFormBase {
/**
* ID of the rrule being used.
*
* @var \Drupal\smart_date_recur\Entity\SmartDateRule
*/
protected $rrule;
/**
* Index of the instance to delete.
*
* @var int
*/
protected $index;
/**
* ID of an existing override.
*
* @var int
*/
protected $oid;
/**
* {@inheritdoc}
*/
public function getFormId() {
return "smart_date_recur_remove_form";
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, SmartDateRule $rrule = NULL, string $index = NULL, $ajax = FALSE) {
$this->rrule = $rrule;
$this->index = $index;
$result = \Drupal::entityQuery('smart_date_override')
->condition('rrule', $rrule
->id())
->condition('rrule_index', $index)
->execute();
if ($result && ($override = SmartDateOverride::load(array_pop($result)))) {
$this->oid = $override
->id();
}
$form = parent::buildForm($form, $form_state);
if ($ajax) {
$this
->addAjaxWrapper($form);
$form['actions']['cancel']['#attributes']['class'][] = 'use-ajax';
$form['actions']['cancel']['#url']
->setRouteParameter('modal', TRUE);
$form['actions']['submit']['#ajax'] = [
'callback' => '::ajaxSubmit',
];
}
return $form;
}
/**
* Ajax submit function.
*
* @param array $form
* The form values being submitted.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state being submitted.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* The response from the AJAX form submit.
*/
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
$form_state
->disableRedirect();
$instanceController = new Instances();
$instanceController
->setSmartDateRule($this->rrule);
$instanceController
->setUseAjax(TRUE);
$instanceController
->setUpdateButton(FALSE);
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('#manage-instances', $instanceController
->listInstancesOutput()));
return $response;
}
/**
* Adding a wrapper to the form, for ajax targeting.
*
* @param array $form
* The form array to be enclosed.
*/
protected function addAjaxWrapper(array &$form) {
$form['#prefix'] = '<div id="manage-instances">';
$form['#suffix'] = '</div>';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
$question = $this
->t('Are you sure you want to remove this instance?');
if ($this->oid) {
$question .= ' ' . $this
->t('Your existing overridden data will be deleted.');
}
return $question;
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
$rrule = $this->rrule
->id();
return new Url('smart_date_recur.instances', [
'rrule' => $rrule,
]);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this
->t('Remove Instance');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this
->t('You will be able to restore the instance if necessary.');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$instanceController = new Instances();
$instanceController
->setSmartDateRule($this->rrule);
$instanceController
->removeInstance($this->index, $this->oid);
// TODO: Update parent entity field value.
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
2 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
105 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SmartDateRemoveInstanceForm:: |
protected | property | Index of the instance to delete. | |
SmartDateRemoveInstanceForm:: |
protected | property | ID of an existing override. | |
SmartDateRemoveInstanceForm:: |
protected | property | ID of the rrule being used. | |
SmartDateRemoveInstanceForm:: |
protected | function | Adding a wrapper to the form, for ajax targeting. | |
SmartDateRemoveInstanceForm:: |
public | function | Ajax submit function. | |
SmartDateRemoveInstanceForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
SmartDateRemoveInstanceForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
SmartDateRemoveInstanceForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
SmartDateRemoveInstanceForm:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
SmartDateRemoveInstanceForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SmartDateRemoveInstanceForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
SmartDateRemoveInstanceForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |