Commit ce03fb3b authored by Loparev's avatar Loparev Committed by Loparev

Issue #2921534 by Loparev: Provide possibillity to alter filename

parent 5aed0e9f
......@@ -331,7 +331,12 @@ class SmartlingTranslator extends TranslatorPluginBase implements ExtendedTransl
if (empty($filename)) {
$extension = $job->getSetting('export_format');
$filename = "JobID" . $job->id() . '_' . $job->getSourceLangcode() . '_' . $job->getTargetLangcode() . '.' . $extension;
$name = "JobID" . $job->id() . '_' . $job->getSourceLangcode() . '_' . $job->getTargetLangcode();
// Alter name before saving it into database.
\Drupal::moduleHandler()->alter('tmgmt_smartling_filename', $name, clone $job);
$filename = $name . '.' . $extension;
}
return $filename;
......
......@@ -5,6 +5,7 @@
* Hooks provided by the TMGMT Smartling module.
*/
use Drupal\tmgmt\JobInterface;
use Drupal\tmgmt\JobItemInterface;
/**
......@@ -17,3 +18,18 @@ function hook_tmgmt_smartling_context_url_alter(&$url, JobItemInterface $job_ite
// Set NULL to avoid creating context for a content from $job_item.
$url = NULL;
}
/**
* Alter translation file name.
*
* @param string $name
* @param JobInterface $job
*/
function hook_tmgmt_smartling_filename_alter(&$name, JobInterface $job) {
// Example: filename = job's label. If you have only one job item in a job
// then file name will look like "[node_title]_job_id_[id]". If there are more
// than 1 job item inside a job then filename will look like
// "[node_title]_and_[n]_more_job_id_[id]". If you enter your own job label
// then filename will look like "[your_own_label]_job_id_[id]"
$name = preg_replace('/[^a-zA-Z0-9_\-\:]/i', '_', $job->label()) . '_job_id_' . $job->id();
}
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