You are here

class ContentExportMultiple in Content Synchronization 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/ContentExportMultiple.php \Drupal\content_sync\Form\ContentExportMultiple

Class ContentExportMultiple

@package Drupal\content_sync_ui\Form

Hierarchy

Expanded class hierarchy of ContentExportMultiple

1 string reference to 'ContentExportMultiple'
content_sync.routing.yml in ./content_sync.routing.yml
content_sync.routing.yml

File

src/Form/ContentExportMultiple.php, line 20

Namespace

Drupal\content_sync\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::getCancelText public function Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface::getCancelText 2
ConfirmFormBase::getDescription public function Returns additional text to display as a description. Overrides ConfirmFormInterface::getDescription 14
ConfirmFormBase::getFormName public function Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface::getFormName
ContentExportMultiple::$contentSyncManager protected property
ContentExportMultiple::$contentSyncUIToolbox protected property
ContentExportMultiple::$entityList protected property
ContentExportMultiple::$entityTypeManager protected property Entity type manager service.
ContentExportMultiple::$formats protected property
ContentExportMultiple::$tempStoreFactory protected property Private Temp Store Factory service.
ContentExportMultiple::buildForm public function Form constructor. Overrides ConfirmFormBase::buildForm
ContentExportMultiple::create public static function Instantiates a new instance of this class. Overrides FormBase::create
ContentExportMultiple::getCancelUrl public function Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface::getCancelUrl
ContentExportMultiple::getConfirmText public function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
ContentExportMultiple::getContentExporter protected function Overrides ContentExportTrait::getContentExporter
ContentExportMultiple::getEntityTypeManager protected function Overrides ContentExportTrait::getEntityTypeManager
ContentExportMultiple::getExportLogger protected function Overrides ContentExportTrait::getExportLogger
ContentExportMultiple::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ContentExportMultiple::getQuestion public function Returns the question to ask the user. Overrides ConfirmFormInterface::getQuestion
ContentExportMultiple::submitForm public function Form submission handler. Overrides FormInterface::submitForm
ContentExportMultiple::__construct public function Constructs a ContentSyncMultiple form object.
ContentExportTrait::$archiver protected property
ContentExportTrait::finishContentExportBatch public function Finish batch.
ContentExportTrait::generateExportBatch public function
ContentExportTrait::generateSiteUUIDFile public function Generate UUID YAML file To use for site UUID validation.
ContentExportTrait::getArchiver protected function
ContentExportTrait::getTempFile protected function
ContentExportTrait::processContentExportFiles public function Processes the content archive export batch
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.