class ContentExportMultiple in Content Synchronization 3.0.x
Same name and namespace in other branches
- 8.2 src/Form/ContentExportMultiple.php \Drupal\content_sync\Form\ContentExportMultiple
Class ContentExportMultiple
@package Drupal\content_sync_ui\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\content_sync\Form\ContentExportMultiple uses ContentExportTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of ContentExportMultiple
1 string reference to 'ContentExportMultiple'
File
- src/
Form/ ContentExportMultiple.php, line 20
Namespace
Drupal\content_sync\FormView source
class ContentExportMultiple extends ConfirmFormBase {
use ContentExportTrait;
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Private Temp Store Factory service.
*
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* @var \Drupal\content_sync\ContentSyncManagerInterface
*/
protected $contentSyncManager;
/**
* @var \Drupal\content_sync_ui\Toolbox\ContentSyncUIToolboxInterface
*/
protected $contentSyncUIToolbox;
/**
* @var array
*/
protected $entityList = [];
protected $formats;
/**
* Constructs a ContentSyncMultiple form object.
*
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $manager
* The entity type manager.
*/
public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $manager, ContentSyncManagerInterface $content_sync_manager, array $formats, FileSystemInterface $file_system) {
$this->tempStoreFactory = $temp_store_factory;
$this->entityTypeManager = $manager;
$this->contentSyncManager = $content_sync_manager;
$this->formats = $formats;
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('tempstore.private'), $container
->get('entity_type.manager'), $container
->get('content_sync.manager'), $container
->getParameter('serializer.formats'), $container
->get('file_system'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'content_sync_export_multiple_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->formatPlural(count($this->entityList), 'Are you sure you want to export this item?', 'Are you sure you want to export these items?');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('system.admin_content');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Export');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$this->entityList = $this->tempStoreFactory
->get('content_sync_ui_multiple_confirm')
->get($this
->currentUser()
->id());
if (empty($this->entityList)) {
return new RedirectResponse($this
->getCancelUrl()
->setAbsolute()
->toString());
}
// List of items to export.
$items = [];
foreach ($this->entityList as $uuid => $entity_info) {
$storage = $this->entityTypeManager
->getStorage($entity_info['entity_type']);
$entity = $storage
->load($entity_info['entity_id']);
if (!empty($entity)) {
$items[$uuid] = $entity
->label();
}
}
$form['content_list'] = [
'#theme' => 'item_list',
'#title' => 'Content List.',
'#items' => $items,
];
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('confirm') && !empty($this->entityList)) {
// Delete the content tar file in case an older version exist.
$this->fileSystem
->delete($this
->getTempFile());
$entities_list = [];
foreach ($this->entityList as $entity_info) {
$entities_list[] = [
'entity_type' => $entity_info['entity_type'],
'entity_id' => $entity_info['entity_id'],
];
}
if (!empty($entities_list)) {
$serializer_context['export_type'] = 'tar';
$serializer_context['include_files'] = 'folder';
$batch = $this
->generateExportBatch($entities_list, $serializer_context);
batch_set($batch);
}
}
else {
$form_state
->setRedirect('system.admin_content');
}
}
/**
* {@inheritdoc}
*/
protected function getEntityTypeManager() {
return $this->entityTypeManager;
}
/**
* {@inheritdoc}
*/
protected function getContentExporter() {
return $this->contentSyncManager
->getContentExporter();
}
/**
* {@inheritdoc}
*/
protected function getExportLogger() {
return $this
->logger('content_sync');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
2 |
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
14 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
ContentExportMultiple:: |
protected | property | ||
ContentExportMultiple:: |
protected | property | ||
ContentExportMultiple:: |
protected | property | ||
ContentExportMultiple:: |
protected | property | Entity type manager service. | |
ContentExportMultiple:: |
protected | property | ||
ContentExportMultiple:: |
protected | property | Private Temp Store Factory service. | |
ContentExportMultiple:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
ContentExportMultiple:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ContentExportMultiple:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
ContentExportMultiple:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
ContentExportMultiple:: |
protected | function |
Overrides ContentExportTrait:: |
|
ContentExportMultiple:: |
protected | function |
Overrides ContentExportTrait:: |
|
ContentExportMultiple:: |
protected | function |
Overrides ContentExportTrait:: |
|
ContentExportMultiple:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ContentExportMultiple:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
ContentExportMultiple:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ContentExportMultiple:: |
public | function | Constructs a ContentSyncMultiple form object. | |
ContentExportTrait:: |
protected | property | ||
ContentExportTrait:: |
public | function | Finish batch. | |
ContentExportTrait:: |
public | function | ||
ContentExportTrait:: |
public | function | Generate UUID YAML file To use for site UUID validation. | |
ContentExportTrait:: |
protected | function | ||
ContentExportTrait:: |
protected | function | ||
ContentExportTrait:: |
public | function | Processes the content archive export batch | |
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 |
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. |