class LogCloneActionForm in Log entity 2.x
Provides a log clone confirmation form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\log\Form\LogActionFormBase
- class \Drupal\log\Form\LogCloneActionForm
- class \Drupal\log\Form\LogActionFormBase
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of LogCloneActionForm
1 string reference to 'LogCloneActionForm'
File
- src/
Form/ LogCloneActionForm.php, line 10
Namespace
Drupal\log\FormView source
class LogCloneActionForm extends LogActionFormBase {
/**
* The action id.
*
* @var string
*/
protected $actionId = 'log_clone_action';
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'log_clone_action_form';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->formatPlural(count($this->logs), 'Are you sure you want to clone this log?', 'Are you sure you want to clone these logs?');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this
->t('Clone');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Filter out logs the user doesn't have access to.
$inaccessible_logs = [];
$accessible_logs = [];
$current_user = $this
->currentUser();
foreach ($this->logs as $log) {
if (!$log
->access('view', $current_user) || !$log
->access('create', $current_user)) {
$inaccessible_logs[] = $log;
continue;
}
$accessible_logs[] = $log;
}
/** @var \Drupal\Core\Datetime\DrupalDateTime $new_date */
if ($form_state
->getValue('confirm') && !empty($accessible_logs)) {
$new_date = $form_state
->getValue('date');
$count = count($this->logs);
foreach ($accessible_logs as $log) {
$cloned_log = $log
->createDuplicate();
$cloned_log
->set('timestamp', $new_date
->getTimestamp());
$cloned_log
->save();
}
$this
->messenger()
->addMessage($this
->formatPlural($count, 'Cloned 1 log.', 'Cloned @count logs.'));
}
// Add warning message if there were inaccessible logs.
if (!empty($inaccessible_logs)) {
$inaccessible_count = count($inaccessible_logs);
$this
->messenger()
->addWarning($this
->formatPlural($inaccessible_count, 'Could not clone @count log because you do not have the necessary permissions.', 'Could not clone @count logs because you do not have the necessary permissions.'));
}
parent::submitForm($form, $form_state);
}
}
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:: |
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 |
LogActionFormBase:: |
protected | property | The entity type manager. | |
LogActionFormBase:: |
protected | property | The logs to clone. | |
LogActionFormBase:: |
protected | property | The tempstore factory. | |
LogActionFormBase:: |
protected | property | The current user. | |
LogActionFormBase:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
1 |
LogActionFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
LogActionFormBase:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
LogActionFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
LogActionFormBase:: |
public | function | Constructs a LogCloneActionForm form object. | |
LogCloneActionForm:: |
protected | property | The action id. | |
LogCloneActionForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides LogActionFormBase:: |
|
LogCloneActionForm:: |
public | function |
Returns a unique string identifying the form. Overrides LogActionFormBase:: |
|
LogCloneActionForm:: |
public | function |
Returns the question to ask the user. Overrides LogActionFormBase:: |
|
LogCloneActionForm:: |
public | function |
Form submission handler. Overrides LogActionFormBase:: |
|
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. | |
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. |