Commit 92d8df02 authored by miroslav-lee's avatar miroslav-lee Committed by miroslav-lee

Add GUI for the Export command

parent e9a72b2f
...@@ -243,12 +243,6 @@ will be reverted to the state defined in a content directory. ...@@ -243,12 +243,6 @@ will be reverted to the state defined in a content directory.
drush dcdi --force-override drush dcdi --force-override
drush dcdi --force-override --folder='../content' drush dcdi --force-override --folder='../content'
### Run import process form UI
If you can not use Drush, go to page `/admin/config/development/dcd/import`.
Check "Import content" permission.
## drush default-content-deploy:uuid-info, drush dcd-uuid-info ## drush default-content-deploy:uuid-info, drush dcd-uuid-info
Display UUID value of Entity. Display UUID value of Entity.
...@@ -266,6 +260,16 @@ Displays all current content entity types. ...@@ -266,6 +260,16 @@ Displays all current content entity types.
drush dcd-entity-list drush dcd-entity-list
# GUI
## Settings
Go to the `/admin/config/development/dcd` page.
## Export
Go to the `/admin/config/development/dcd/export` page.
## Import
Go to the `/admin/config/development/dcd/import` page.
# Team workflow - how to synchronize configuration and content between sites # Team workflow - how to synchronize configuration and content between sites
......
...@@ -9,3 +9,9 @@ default_content_deploy.import: ...@@ -9,3 +9,9 @@ default_content_deploy.import:
description: 'Perform content import (drush dcdi) via UI.' description: 'Perform content import (drush dcdi) via UI.'
parent: default_content_deploy.settings parent: default_content_deploy.settings
route_name: default_content_deploy.import route_name: default_content_deploy.import
default_content_deploy.export:
title: 'Export'
description: 'Perform content export (drush dcde,dcder,dcdes) via UI.'
parent: default_content_deploy.settings
route_name: default_content_deploy.export
...@@ -7,3 +7,8 @@ default_content_deploy.import: ...@@ -7,3 +7,8 @@ default_content_deploy.import:
base_route: default_content_deploy.settings base_route: default_content_deploy.settings
route_name: default_content_deploy.import route_name: default_content_deploy.import
title: 'Import' title: 'Import'
default_content_deploy.export:
base_route: default_content_deploy.settings
route_name: default_content_deploy.export
title: 'Export'
...@@ -17,3 +17,13 @@ default_content_deploy.import: ...@@ -17,3 +17,13 @@ default_content_deploy.import:
_permission: 'default content deploy import' _permission: 'default content deploy import'
options: options:
_admin_route: TRUE _admin_route: TRUE
default_content_deploy.export:
path: '/admin/config/development/dcd/export'
defaults:
_form: 'Drupal\default_content_deploy\Form\ExportForm'
_title: 'Default Content Deploy - Export'
requirements:
_permission: 'default content deploy export'
options:
_admin_route: TRUE
<?php
namespace Drupal\default_content_deploy\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\default_content_deploy\DeployManager;
use Drupal\default_content_deploy\Exporter;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Config Form for run DCD deploy in Admin UI.
*/
class ExportForm extends FormBase {
/**
* Default Content Deploy Export object.
*
* @var \Drupal\default_content_deploy\Exporter
*/
private $exporter;
/**
* Deploy manager.
*
* @var \Drupal\default_content_deploy\DeployManager
*/
protected $deployManager;
/**
* ExportForm constructor.
*
* @param \Drupal\default_content_deploy\Exporter $exporter
* @param \Drupal\Core\Messenger\Messenger $messenger
* @param \Drupal\default_content_deploy\DeployManager $deploy_manager
*/
public function __construct(Exporter $exporter, Messenger $messenger, DeployManager $deploy_manager) {
$this->exporter = $exporter;
$this->messenger = $messenger;
$this->deployManager = $deploy_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('default_content_deploy.exporter'),
$container->get('messenger'),
$container->get('default_content_deploy.manager')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dcd_export_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['mode'] = [
'#type' => 'select',
'#title' => $this->t('Mode'),
'#description' => $this->t('Mode of the export (export all content, with reference etc). Read more in the documentation.'),
'#required' => TRUE,
'#options' => [
'all' => $this->t('All content'),
],
'#default_value' => 'all',
];
$form['folder'] = [
'#type' => 'textfield',
'#title' => $this->t('Folder'),
'#description' => $this->t('All existing content will be exported form this folder.'),
'#default_value' => $this->deployManager->getContentFolder(),
];
$form['force_update'] = [
'#type' => 'checkbox',
'#title' => $this->t('Force update'),
'#description' => $this->t('All existing content will be overridden (locally updated default content will be reverted to the state defined on the site).'),
'#default_value' => FALSE,
];
$form['export'] = [
'#type' => 'submit',
'#value' => $this->t('Export content'),
];
return $form;
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @throws \Exception
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$mode = $form_state->getValue('mode');
$folder = $form_state->getValue('folder');
$force_update = $form_state->getValue('force_update');
$this->exporter->setFolder($folder);
$this->exporter->setMode($mode);
$this->exporter->setForceUpdate($force_update);
$this->exporter->export();
$this->addResultMessage();
}
/**
* Add a message with exporting results.
*/
private function addResultMessage() {
$result = $this->exporter->getResult();
foreach ($result as $entity_type => $value) {
$this->messenger->addMessage($this->t('Exported @count entities of the "@entity_type" entity type.', [
'@count' => count($value),
'@entity_type' => $entity_type, MB_CASE_TITLE,
]));
}
return $this;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment