Provides a node deletion confirmation form.
Expanded class hierarchy of DeleteMultiple
class DeleteMultiple extends ConfirmFormBase implements ControllerInterface {
/**
* The array of nodes to delete.
*
* @var array
*/
protected $nodes = array();
/**
* The tempstore factory.
*
* @var \Drupal\user\TempStoreFactory
*/
protected $tempStoreFactory;
/**
* The node storage controller.
*
* @var \Drupal\Core\Entity\EntityStorageControllerInterface
*/
protected $manager;
/**
* Constructs a DeleteMultiple form object.
*
* @param \Drupal\user\TempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Entity\EntityManager $manager
* The entity manager.
*/
public function __construct(TempStoreFactory $temp_store_factory, EntityManager $manager) {
$this->tempStoreFactory = $temp_store_factory;
$this->storageController = $manager
->getStorageController('node');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('user.tempstore'), $container
->get('plugin.manager.entity'));
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'node_multiple_delete_confirm';
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return format_plural(count($this->nodes), 'Are you sure you want to delete this item?', 'Are you sure you want to delete these items?');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/content';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$this->nodes = $this->tempStoreFactory
->get('node_multiple_delete_confirm')
->get($GLOBALS['user']->uid);
if (empty($this->nodes)) {
drupal_goto($this
->getCancelPath());
}
$form['nodes'] = array(
'#theme' => 'item_list',
'#items' => array_map(function ($node) {
return String::checkPlain($node
->label());
}, $this->nodes),
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
if ($form_state['values']['confirm'] && !empty($this->nodes)) {
$this->storageController
->delete($this->nodes);
$this->tempStoreFactory
->get('node_multiple_delete_confirm')
->delete($GLOBALS['user']->uid);
$count = count($this->nodes);
watchdog('content', 'Deleted @count posts.', array(
'@count' => $count,
));
drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
}
$form_state['redirect'] = 'admin/content';
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
protected | function | Returns a caption for the link which cancels the action. | 2 |
ConfirmFormBase:: |
protected | function | Returns additional text to display as a description. | 10 |
ConfirmFormBase:: |
protected | function | Returns the internal name used to refer to the confirmation item. | |
ConfirmFormBase:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface:: |
1 |
DeleteMultiple:: |
protected | property | The node storage controller. | |
DeleteMultiple:: |
protected | property | The array of nodes to delete. | |
DeleteMultiple:: |
protected | property | The tempstore factory. | |
DeleteMultiple:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConfirmFormBase:: |
|
DeleteMultiple:: |
public static | function |
Instantiates a new instance of this controller. Overrides ControllerInterface:: |
|
DeleteMultiple:: |
protected | function |
Returns the page to go to if the user cancels the action. Overrides ConfirmFormBase:: |
|
DeleteMultiple:: |
protected | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
DeleteMultiple:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
DeleteMultiple:: |
protected | function |
Returns the question to ask the user. Overrides ConfirmFormBase:: |
|
DeleteMultiple:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
DeleteMultiple:: |
public | function | Constructs a DeleteMultiple form object. |