class LaunchExportForm in Content Synchronizer 3.x
Same name and namespace in other branches
- 8.2 src/Form/LaunchExportForm.php \Drupal\content_synchronizer\Form\LaunchExportForm
- 8 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, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\content_synchronizer\Form\LaunchExportForm
Expanded class hierarchy of LaunchExportForm
1 file declares its use of LaunchExportForm
- ExportEntityViewBuilder.php in src/
Entity/ ExportEntityViewBuilder.php
File
- src/
Form/ LaunchExportForm.php, line 18
Namespace
Drupal\content_synchronizer\FormView source
class LaunchExportForm extends FormBase {
/**
* The export entity.
*
* @var \Drupal\content_synchronizer\Entity\ExportEntity
*/
protected $export;
/**
* Current url.
*
* @var string
*/
protected $currentUrl;
/**
* LaunchExportForm constructor.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*/
public function __construct(Request $request) {
$this->currentUrl = $request
->getRequestUri();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('request_stack')
->getCurrentRequest());
}
/**
* {@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' => $this
->t('Launch export'),
'#button_type' => 'primary',
];
$form['deleteEntities'] = [
'#type' => 'submit',
'#value' => $this
->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)) {
$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;
ArchiveDownloader::me()
->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' => $this
->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 = static::getRequestParam()) {
if (file_exists($archiveUri)) {
$form['archive'] = [
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'style' => [
'display:none',
],
'src' => file_create_url($archiveUri),
],
];
}
}
}
/**
* Return request.
*
* @return mixed|\Symfony\Component\HttpFoundation\Request
* The value of the param.
*/
public static function getRequestParam() {
return \Drupal::request()
->get(EntityExportFormBuilder::ARCHIVE_PARAMS);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 |
LaunchExportForm:: |
protected | property | Current url. | |
LaunchExportForm:: |
protected | property | The export entity. | |
LaunchExportForm:: |
protected | function | Add a donwload hidden iframe. | |
LaunchExportForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LaunchExportForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
LaunchExportForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LaunchExportForm:: |
public static | function | Return request. | |
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:: |
|
LaunchExportForm:: |
public | function | LaunchExportForm constructor. | |
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. |