cloud-8.x-2.0-beta1/src/Form/CloudServerTemplateDeleteMultipleForm.php
src/Form/CloudServerTemplateDeleteMultipleForm.php
<?php
namespace Drupal\cloud\Form;
use Drupal\cloud\Entity\CloudServerTemplate;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
/**
* Provides support for bulk deletion of cloud server templates.
*/
class CloudServerTemplateDeleteMultipleForm extends CloudServerTemplateProcessMultipleForm {
/**
* Constructs a new CloudProcessMultiple object.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud service provider plugin manager (CloudConfigPluginManager).
*/
public function __construct(AccountInterface $current_user,
EntityTypeManagerInterface $entity_type_manager,
PrivateTempStoreFactory $temp_store_factory,
MessengerInterface $messenger,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
parent::__construct(
$current_user,
$entity_type_manager,
$temp_store_factory,
$messenger,
$cloud_config_plugin_manager
);
// Set the temp_store_factory.
$this->tempStore = $temp_store_factory->get('entity_delete_multiple_confirm');
}
/**
* Process entity.
*
* @param \Drupal\cloud\Entity\CloudServerTemplate $entity
* An entity object.
*/
protected function processEntity(CloudServerTemplate $entity) {
$entity->delete();
}
/**
* Process an entity and related AWS resource.
*
* @param \Drupal\cloud\Entity\CloudServerTemplate $entity
* An entity object.
*
* @return bool
* Succeeded or failed.
*/
protected function process(CloudServerTemplate $entity) {
$message = $this->t('The @type "@label" has been processed.', [
'@type' => $entity->getEntityType()->getLabel(),
'@label' => $entity->label(),
]);
$this->processEntity($entity);
$this->messenger->addMessage($message);
return TRUE;
}
}
