Commit e4e36b4f authored by Loparev's avatar Loparev
Browse files

Added "Download by job items" initial action

parent d286a599
langcode: en
status: true
dependencies:
module:
- tmgmt
id: tmgmt_smartling_download_by_job_items_job_action
label: 'Download Translation by TMGMT Job Items'
type: tmgmt_job
plugin: tmgmt_smartling_download_by_job_items_job_action
configuration: { }
......@@ -78,3 +78,7 @@ tmgmt.translator.settings.smartling:
action.configuration.tmgmt_smartling_send_context_action:
type: action_configuration_default
label: 'Send context action'
action.configuration.tmgmt_smartling_download_by_job_items_job_action:
type: action_configuration_default
label: 'Download Translation by TMGMT Job Items'
<?php
namespace Drupal\tmgmt_smartling\Form;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\tmgmt_extension_suit\ExtendedTranslatorPluginInterface;
use Drupal\tmgmt_extension_suit\Form\BaseTmgmtActionApproveForm;
/**
* Provides a confirmation form for sending multiple content entities.
*/
class DownloadByJobItemsTmgmtActionApproveForm extends BaseTmgmtActionApproveForm {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'tmgmt_smartling_download_by_job_items_form_confirm';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Download Translation by TMGMT Job Items');
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to download translations for these jobs?');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Downloading can take some time, do not close the browser');
}
/**
* {@inheritdoc}
*/
public static function processBatch(array $data, array &$context) {
$job = parent::processBatch($data, $context);
if (!empty($job) && $translator = $job->getTranslator()) {
$plugin = $translator->getPlugin();
if ($plugin instanceof ExtendedTranslatorPluginInterface &&
$plugin->downloadTranslation($job)) {
$context['results']['count']++;
}
else {
$context['results']['errors'][] = new FormattableMarkup('Error downloading %name', [
'%name' => $job->label(),
]);
return;
}
$context['message'] = new FormattableMarkup('Processed %name.', [
'%name' => $job->label(),
]);
}
else {
$context['message'] = new FormattableMarkup('Skipped %name.', [
'%name' => $data['entity_type'],
]);
}
}
}
<?php
namespace Drupal\tmgmt_smartling\Plugin\Action;
use Drupal\tmgmt_extension_suit\Plugin\Action\BaseJobAction;
/**
* Translate entity.
*
* @Action(
* id = "tmgmt_smartling_download_by_job_items_job_action",
* label = @Translation("Download Translation by TMGMT Job Items"),
* type = "tmgmt_job",
* confirm_form_route_name = "tmgmt_smartling.download_by_job_items_approve_action"
* )
*/
class DowloadByJobItemsJobAction extends BaseJobAction {
/**
* Returns temp storage name.
*
* @inheritdoc
*/
protected function getTempStoreName($entity_type = '') {
return 'tmgmt_smartling_' . $entity_type . '_operations_download_by_job_items';
}
}
......@@ -4,6 +4,8 @@
* @file
* Update function for the tmgmt_smartling module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Utility\UpdateException;
......@@ -188,3 +190,35 @@ function tmgmt_smartling_update_8403() {
}
}
}
/**
* Create download by job items action plugin./
*/
function tmgmt_smartling_update_8804() {
try {
$plugin_id = 'tmgmt_smartling_download_by_job_items_job_action';
$plugin_name = 'system.action.tmgmt_smartling_download_by_job_items_job_action';
$entity_type_manager = \Drupal::entityTypeManager();
$module_handler = \Drupal::moduleHandler();
$config_install_path = $module_handler->getModule('tmgmt_smartling')
->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
$action_storage = $entity_type_manager->getStorage('action');
$action = $action_storage->load($plugin_id);
// Create action if it doesn't exist.
if (!$action) {
$storage = new FileStorage($config_install_path);
$read_file = $storage->read($plugin_name);
if ($read_file) {
$entity_type_manager
->getStorage('action')
->create($read_file)
->save();
}
}
}
catch (Exception $e) {
throw new UpdateException('Unable to create "tmgmt_smartling_download_by_job_items_job_action" action.');
}
}
......@@ -20,3 +20,11 @@ tmgmt_smartling.send_context_action:
_form: 'Drupal\tmgmt_smartling\Form\SendContextActionApproveForm'
requirements:
_permission: 'send context smartling'
tmgmt_smartling.download_by_job_items_approve_action:
path: '/admin/tmgmt/approve-action-download-by-job-items'
defaults:
_title: 'TMGMT Smartling approve download by job items action'
_form: '\Drupal\tmgmt_smartling\Form\DownloadByJobItemsTmgmtActionApproveForm'
requirements:
_permission: 'administer tmgmt'
Supports Markdown
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