class LaunchExportForm in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Form/LaunchExportForm.php \Drupal\content_synchronizer\Form\LaunchExportForm
- 3.x src/Form/LaunchExportForm.php \Drupal\content_synchronizer\Form\LaunchExportForm
Launch Export Form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\content_synchronizer\Form\LaunchExportForm
Expanded class hierarchy of LaunchExportForm
File
- src/
Form/ LaunchExportForm.php, line 19
Namespace
Drupal\content_synchronizer\FormView source
class LaunchExportForm extends FormBase {
/**
* The export entity.
*
* @var \Drupal\content_synchronizer\Entity\ExportEntity
*/
protected $export;
protected $currentUrl;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'content_synchronizer.export.launch';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\content_synchronizer\Entity\ImportEntity $import */
$this->export = $form_state
->getBuildInfo()['export'];
// Entity list :
$this
->initRootEntitiesList($form);
if (array_key_exists('entities_list', $form)) {
$form['launch'] = [
'#type' => 'submit',
'#value' => t('Launch export'),
'#button_type' => 'primary',
];
$form['deleteEntities'] = [
'#type' => 'submit',
'#value' => t('Remove selected entities from export list'),
'#submit' => [
'::removeSelectedEntities',
],
];
}
return $form;
}
/**
* Remove selected entities of the import.
*/
public function removeSelectedEntities(array &$form, FormStateInterface $form_state) {
$entitiesToRemove = $form_state
->getUserInput()['entities_to_export'];
$entitiesToRemove = array_intersect_key($this->export
->getEntitiesList(), array_flip($entitiesToRemove));
foreach ($entitiesToRemove as $entity) {
$this->export
->removeEntity($entity);
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$entitiesToExport = $form_state
->getUserInput()['entities_to_export'];
$entitiesToExport = array_intersect_key($this->export
->getEntitiesList(), array_flip($entitiesToExport));
if (!empty($entitiesToExport)) {
$this->currentUrl = \Drupal::request()
->getRequestUri();
$writer = new ExportEntityWriter();
$writer
->initFromId($this->export
->label());
$batchExportProcessor = new BatchExportProcessor($writer);
$batchExportProcessor
->exportEntities($entitiesToExport, [
$this,
'onBatchEnd',
]);
}
}
/**
* Callback after batch.
*/
public function onBatchEnd($archiveUri) {
$redirectUrl = $this->currentUrl;
\Drupal::service(ArchiveDownloader::SERVICE_NAME)
->redirectWithArchivePath($redirectUrl, $archiveUri);
}
/**
* Init Root entities lists for display.
*/
protected function initRootEntitiesList(array &$form) {
$rootEntities = $this
->getRootsEntities();
if (!empty($rootEntities)) {
$build = [
'#theme' => 'entities_list_table',
'#entities' => $rootEntities,
'#status_or_bundle' => 'bundle',
'#checkbox_name' => 'entities_to_export[]',
'#title' => t('Entities to export'),
'#attached' => [
'library' => [
'content_synchronizer/list',
],
],
];
$form['entities_list'] = $build;
}
}
/**
* Return the roots entities.
*/
public function getRootsEntities() {
$data = [];
/** @var \Drupal\Core\Entity\Entity $entity */
foreach ($this->export
->getEntitiesList() as $key => $entity) {
$data[$key] = [
"entity_type_id" => $entity
->getEntityTypeId(),
"entity_id" => $entity
->id(),
"status" => $entity
->bundle(),
"label" => ExportEntityWriter::getEntityLabel($entity),
'edit_url' => Url::fromRoute('entity.' . $entity
->getEntityTypeId() . '.edit_form', [
$entity
->getEntityTypeId() => $entity
->id(),
]),
'view_url' => $entity
->toUrl(),
];
}
return $data;
}
/**
* Add a donwload hidden iframe.
*
* @param array $form
* The build form array.
*/
protected function addDownloadIframe(array &$form) {
if ($archiveUri = \Drupal::request()
->get(EntityExportFormBuilder::ARCHIVE_PARAMS)) {
if (file_exists($archiveUri)) {
$form['archive'] = [
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'style' => [
'display:none',
],
'src' => file_create_url($archiveUri),
],
];
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
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:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
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 |
LaunchExportForm:: |
protected | property | ||
LaunchExportForm:: |
protected | property | The export entity. | |
LaunchExportForm:: |
protected | function | Add a donwload hidden iframe. | |
LaunchExportForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LaunchExportForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LaunchExportForm:: |
public | function | Return the roots entities. | |
LaunchExportForm:: |
protected | function | Init Root entities lists for display. | |
LaunchExportForm:: |
public | function | Callback after batch. | |
LaunchExportForm:: |
public | function | Remove selected entities of the import. | |
LaunchExportForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
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. |