class ExportConfirmForm in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Form/ExportConfirmForm.php \Drupal\content_synchronizer\Form\ExportConfirmForm
- 3.x src/Form/ExportConfirmForm.php \Drupal\content_synchronizer\Form\ExportConfirmForm
Class ExportConfirmForm.
@package Drupal\content_synchronizer\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\content_synchronizer\Form\ExportConfirmForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of ExportConfirmForm
1 file declares its use of ExportConfirmForm
- ExportAction.php in src/
Plugin/ Action/ ExportAction.php
1 string reference to 'ExportConfirmForm'
File
- src/
Form/ ExportConfirmForm.php, line 22
Namespace
Drupal\content_synchronizer\FormView source
class ExportConfirmForm extends ConfirmFormBase {
const FORM_ID = 'content_synchronizer.export_confirm';
const ARCHIVE_PARAMS = 'archive';
/**
* The array of nodes to delete.
*
* @var string[][]
*/
protected $nodeInfo = [];
/**
* The tempstore factory.
*
* @var \Drupal\user\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* The node storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $manager;
/**
* The export manager.
*
* @var \Drupal\content_synchronizer\Service\ExportManager
*/
protected $exportManager;
/**
* Constructs a DeleteMultiple form object.
*
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $manager
* The entity manager.
*/
public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityManagerInterface $manager) {
$this->tempStoreFactory = $temp_store_factory;
$this->storage = $manager
->getStorage('node');
$this->exportManager = \Drupal::service(ExportManager::SERVICE_NAME);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('user.private_tempstore'), $container
->get('entity.manager'));
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
$this
->t('Export entity');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this
->t('Export');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('system.admin_content');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return static::FORM_ID;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['content_synchronizer'] = [
'#type' => 'fieldset',
'#title' => t('Export'),
];
$form['content_synchronizer']['quick_export'] = [
'#type' => 'submit',
'#value' => t('Export entity'),
'#description' => t('Download the entity .zip file with dependencies'),
'#button_type' => 'primary',
'#submit' => [
[
$this,
'onQuickExport',
],
],
];
$exportsListOptions = $this->exportManager
->getExportsListOptions();
if (!empty($exportsListOptions)) {
$form['content_synchronizer']['exports_list'] = [
'#type' => 'checkboxes',
'#title' => t('Or add the entity to an existing export'),
'#options' => $exportsListOptions,
];
$form['content_synchronizer']['add_to_export'] = [
'#type' => 'submit',
'#value' => t('Add to the choosen export'),
'#submit' => [
[
$this,
'onAddToExport',
],
],
];
}
return $form;
}
/**
* Action on quick export submit action.
*
* @param array $form
* The form build array.
* @param \Drupal\Core\Form\FormStateInterface $formState
* The form state.
*/
public function onQuickExport(array &$form, FormStateInterface $formState) {
$entities = $this
->getEntities();
$writer = new ExportEntityWriter();
$writer
->initFromId(time());
$batchExportProcessor = new BatchExportProcessor($writer);
$batchExportProcessor
->exportEntities($entities, [
$this,
'onBatchEnd',
]);
}
/**
* On batch end redirect to the form url.
*
* @param string $archiveUri
* THe archive to download.
*/
public function onBatchEnd($archiveUri) {
$redirectUrl = $this
->getTmpStoredData('url');
\Drupal::service(ArchiveDownloader::SERVICE_NAME)
->redirectWithArchivePath($redirectUrl, $archiveUri);
}
/**
* Add entity to an existing entity export.
*
* @param array $form
* The form build array.
* @param \Drupal\Core\Form\FormStateInterface $formState
* The form state.
*/
public function onAddToExport(array &$form, FormStateInterface $formState) {
$exportsList = ExportEntity::loadMultiple($formState
->getValue('exports_list'));
foreach ($this
->getEntities() as $entity) {
/** @var \Drupal\content_synchronizer\Entity\ExportEntity $export */
foreach ($exportsList as $export) {
$export
->addEntity($entity);
}
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
}
/**
* Return the list of entities to export.
*
* @return array|\Drupal\Core\Entity\EntityInterface[]
* The entities.
*/
protected function getEntities() {
$entities = [];
foreach ($this
->getTmpStoredData('entities') as $entityTypeId => $entitiesIds) {
$entities += \Drupal::entityTypeManager()
->getStorage($entityTypeId)
->loadMultiple($entitiesIds);
}
return $entities;
}
/**
* Return the stored element by key.
*
* @param string $key
* The key.
*
* @return mixed
* The value.
*/
protected function getTmpStoredData($key) {
return $this->tempStoreFactory
->get(static::FORM_ID)
->get(\Drupal::currentUser()
->id())[$key];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
1 |
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
11 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
ExportConfirmForm:: |
protected | property | The export manager. | |
ExportConfirmForm:: |
protected | property | The node storage. | |
ExportConfirmForm:: |
protected | property | The array of nodes to delete. | |
ExportConfirmForm:: |
protected | property | The tempstore factory. | |
ExportConfirmForm:: |
constant | |||
ExportConfirmForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
ExportConfirmForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ExportConfirmForm:: |
constant | |||
ExportConfirmForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
ExportConfirmForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
ExportConfirmForm:: |
protected | function | Return the list of entities to export. | |
ExportConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ExportConfirmForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
ExportConfirmForm:: |
protected | function | Return the stored element by key. | |
ExportConfirmForm:: |
public | function | Add entity to an existing entity export. | |
ExportConfirmForm:: |
public | function | On batch end redirect to the form url. | |
ExportConfirmForm:: |
public | function | Action on quick export submit action. | |
ExportConfirmForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ExportConfirmForm:: |
public | function | Constructs a DeleteMultiple form object. | |
FormBase:: |
protected | property | The config factory. | 1 |
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. | 1 |
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. Overrides UrlGeneratorTrait:: |
|
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:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
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. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
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. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |