Loading translators/tmgmt_local/src/Entity/ListBuilder/LocalTaskItemListBuilder.php +1 −1 Changes for translators/tmgmt_local/src/Entity/ListBuilder/LocalTaskItemListBuilder.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ class LocalTaskItemListBuilder extends EntityListBuilder { protected function getDefaultOperations(EntityInterface $entity) { /** @var \Drupal\tmgmt_local\Entity\LocalTaskItem $entity */ $operations = parent::getDefaultOperations($entity); if ($entity->access('view', \Drupal::currentUser()) && $entity->getTask()->getAssignee()->id() == \Drupal::currentUser()->id()) { if ($entity->access('view', \Drupal::currentUser()) && $entity->getTask()->getAssignee() && $entity->getTask()->getAssignee()->id() == \Drupal::currentUser()->id()) { if ($entity->isPending()) { $operations['translate'] = [ 'url' => $entity->urlInfo(), Loading translators/tmgmt_local/src/Form/LocalTaskForm.php +1 −1 Changes for translators/tmgmt_local/src/Form/LocalTaskForm.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class LocalTaskForm extends ContentEntityForm { '#type' => 'select', '#options' => $assignees, '#empty_option' => t('- Unassigned -'), '#default_value' => $local_task->getAssignee()->id(), '#default_value' => $local_task->getAssignee() ? $local_task->getAssignee()->id() : NULL, '#access' => \Drupal::currentUser()->hasPermission('administer tmgmt') || \Drupal::currentUser()->hasPermission('administer translation tasks'), ); Loading translators/tmgmt_local/src/LocalTaskInterface.php +2 −2 Changes for translators/tmgmt_local/src/LocalTaskInterface.php: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -48,8 +48,8 @@ interface LocalTaskInterface extends ContentEntityInterface, EntityChangedInterf /** * Return the user assigned to this task. * * @return \Drupal\Core\Session\AccountInterface * The user assigned to this task. * @return \Drupal\Core\Session\AccountInterface|null * The user assigned to this task or NULL if there is no user assigned. */ public function getAssignee(); Loading translators/tmgmt_local/src/Plugin/tmgmt/Translator/LocalTranslator.php +18 −5 Changes for translators/tmgmt_local/src/Plugin/tmgmt/Translator/LocalTranslator.php: 18 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ namespace Drupal\tmgmt_local\Plugin\tmgmt\Translator; use Drupal\tmgmt\ContinuousTranslatorInterface; use Drupal\tmgmt\JobInterface; use Drupal\tmgmt\TranslatorInterface; use Drupal\tmgmt\TranslatorPluginBase; Loading @@ -24,7 +25,7 @@ use Drupal\tmgmt_local\LocalTaskInterface; * map_remote_languages = FALSE * ) */ class LocalTranslator extends TranslatorPluginBase { class LocalTranslator extends TranslatorPluginBase implements ContinuousTranslatorInterface { protected $language_pairs = array(); Loading @@ -32,9 +33,23 @@ class LocalTranslator extends TranslatorPluginBase { * {@inheritdoc} */ public function requestTranslation(JobInterface $job) { $items = $job->getItems(); $this->requestJobItemsTranslation($items); // The translation job has been successfully submitted. $job->submitted(); } /** * {@inheritdoc} */ public function requestJobItemsTranslation(array $job_items) { /** @var \Drupal\tmgmt\Entity\Job $job */ $job = reset($job_items)->getJob(); $tuid = $job->getSetting('translator'); // Create local task for this job. /** @var \Drupal\tmgmt_local\LocalTaskInterface $local_task */ $local_task = tmgmt_local_task_create(array( 'uid' => $job->getOwnerId(), 'tuid' => $tuid, Loading @@ -48,12 +63,10 @@ class LocalTranslator extends TranslatorPluginBase { $local_task->save(); // Create task items. foreach ($job->getItems() as $item) { foreach ($job_items as $item) { $local_task->addTaskItem($item); $item->active(); } // The translation job has been successfully submitted. $job->submitted(); } /** Loading translators/tmgmt_local/src/Tests/LocalTranslatorContinuousTest.php 0 → 100755 +114 −0 Changes for translators/tmgmt_local/src/Tests/LocalTranslatorContinuousTest.php: 114 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\tmgmt_local\Tests; use Drupal\tmgmt\Entity\Job; use Drupal\tmgmt\JobItemInterface; use Drupal\node\Entity\Node; /** * Test Continuous jobs support in the local translator. * * @group tmgmt */ class LocalTranslatorContinuousTest extends LocalTranslatorTestBase { /** * Modules to enable. * * @var array */ public static $modules = array('tmgmt_content'); /** * Test continuous Jobs in TMGMT local. */ public function testContinuousJobs() { $type = $this->drupalCreateContentType(); // Enable entity translations for nodes. $content_translation_manager = \Drupal::service('content_translation.manager'); $content_translation_manager->setEnabled('node', $type->label(), TRUE); $this->assignee = $this->drupalCreateUser($this->localTranslatorPermissions); $this->drupalLogin($this->assignee); $edit = array( 'tmgmt_translation_skills[0][language_from]' => 'en', 'tmgmt_translation_skills[0][language_to]' => 'de', ); $this->drupalPostForm('user/' . $this->assignee->id() . '/edit', $edit, t('Save')); $this->loginAsAdmin($this->localManagerPermissions); // Test continuous integration. $this->config('tmgmt.settings') ->set('submit_job_item_on_cron', TRUE) ->save(); // Continuous settings configuration. $continuous_settings = [ 'content' => [ 'node' => [ 'enabled' => 1, 'bundles' => [ $type->id() => 1, ], ], ], ]; $translator = $this->createTranslator(['plugin' => 'local']); $continuous_job = $this->createJob('en', 'de', 0, [ 'label' => 'Continuous job', 'job_type' => Job::TYPE_CONTINUOUS, 'translator' => $translator, 'continuous_settings' => $continuous_settings, ]); $continuous_job->save(); // Create an english node. $node = Node::create([ 'title' => $this->randomMachineName(), 'uid' => 0, 'type' => $type->id(), 'langcode' => 'en', ]); $node->save(); $continuous_job_items = $continuous_job->getItems(); $this->assertEqual(count($continuous_job_items), 1); $continuous_job_item = reset($continuous_job_items); $this->assertTrue($continuous_job_item->getState() == JobItemInterface::STATE_INACTIVE); tmgmt_cron(); $this->drupalGet('translate'); $this->clickLink('View'); // Assign to user. $edit = array( 'tuid' => $this->assignee->id(), ); $this->drupalPostForm(NULL, $edit, t('Save task')); $this->drupalLogin($this->assignee); $this->drupalGet('translate'); $this->clickLink('View'); $this->clickLink('Translate'); $edit = array( 'title|0|value[translation]' => 'Text für Job Element mit Typ-Knoten und ID 1.', ); $this->drupalPostForm(NULL, $edit, t('Save as completed')); $items = $continuous_job->getItems(); $item = reset($items); // Check is set to need review. $data = $item->getData(); $this->assertEqual($data['title']['0']['value']['#translation']['#text'], 'Text für Job Element mit Typ-Knoten und ID 1.'); $this->assertTrue($continuous_job->getState() == Job::STATE_CONTINUOUS); $this->assertTrue($item->getState() == JobItemInterface::STATE_REVIEW); } } Loading
translators/tmgmt_local/src/Entity/ListBuilder/LocalTaskItemListBuilder.php +1 −1 Changes for translators/tmgmt_local/src/Entity/ListBuilder/LocalTaskItemListBuilder.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ class LocalTaskItemListBuilder extends EntityListBuilder { protected function getDefaultOperations(EntityInterface $entity) { /** @var \Drupal\tmgmt_local\Entity\LocalTaskItem $entity */ $operations = parent::getDefaultOperations($entity); if ($entity->access('view', \Drupal::currentUser()) && $entity->getTask()->getAssignee()->id() == \Drupal::currentUser()->id()) { if ($entity->access('view', \Drupal::currentUser()) && $entity->getTask()->getAssignee() && $entity->getTask()->getAssignee()->id() == \Drupal::currentUser()->id()) { if ($entity->isPending()) { $operations['translate'] = [ 'url' => $entity->urlInfo(), Loading
translators/tmgmt_local/src/Form/LocalTaskForm.php +1 −1 Changes for translators/tmgmt_local/src/Form/LocalTaskForm.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class LocalTaskForm extends ContentEntityForm { '#type' => 'select', '#options' => $assignees, '#empty_option' => t('- Unassigned -'), '#default_value' => $local_task->getAssignee()->id(), '#default_value' => $local_task->getAssignee() ? $local_task->getAssignee()->id() : NULL, '#access' => \Drupal::currentUser()->hasPermission('administer tmgmt') || \Drupal::currentUser()->hasPermission('administer translation tasks'), ); Loading
translators/tmgmt_local/src/LocalTaskInterface.php +2 −2 Changes for translators/tmgmt_local/src/LocalTaskInterface.php: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -48,8 +48,8 @@ interface LocalTaskInterface extends ContentEntityInterface, EntityChangedInterf /** * Return the user assigned to this task. * * @return \Drupal\Core\Session\AccountInterface * The user assigned to this task. * @return \Drupal\Core\Session\AccountInterface|null * The user assigned to this task or NULL if there is no user assigned. */ public function getAssignee(); Loading
translators/tmgmt_local/src/Plugin/tmgmt/Translator/LocalTranslator.php +18 −5 Changes for translators/tmgmt_local/src/Plugin/tmgmt/Translator/LocalTranslator.php: 18 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ namespace Drupal\tmgmt_local\Plugin\tmgmt\Translator; use Drupal\tmgmt\ContinuousTranslatorInterface; use Drupal\tmgmt\JobInterface; use Drupal\tmgmt\TranslatorInterface; use Drupal\tmgmt\TranslatorPluginBase; Loading @@ -24,7 +25,7 @@ use Drupal\tmgmt_local\LocalTaskInterface; * map_remote_languages = FALSE * ) */ class LocalTranslator extends TranslatorPluginBase { class LocalTranslator extends TranslatorPluginBase implements ContinuousTranslatorInterface { protected $language_pairs = array(); Loading @@ -32,9 +33,23 @@ class LocalTranslator extends TranslatorPluginBase { * {@inheritdoc} */ public function requestTranslation(JobInterface $job) { $items = $job->getItems(); $this->requestJobItemsTranslation($items); // The translation job has been successfully submitted. $job->submitted(); } /** * {@inheritdoc} */ public function requestJobItemsTranslation(array $job_items) { /** @var \Drupal\tmgmt\Entity\Job $job */ $job = reset($job_items)->getJob(); $tuid = $job->getSetting('translator'); // Create local task for this job. /** @var \Drupal\tmgmt_local\LocalTaskInterface $local_task */ $local_task = tmgmt_local_task_create(array( 'uid' => $job->getOwnerId(), 'tuid' => $tuid, Loading @@ -48,12 +63,10 @@ class LocalTranslator extends TranslatorPluginBase { $local_task->save(); // Create task items. foreach ($job->getItems() as $item) { foreach ($job_items as $item) { $local_task->addTaskItem($item); $item->active(); } // The translation job has been successfully submitted. $job->submitted(); } /** Loading
translators/tmgmt_local/src/Tests/LocalTranslatorContinuousTest.php 0 → 100755 +114 −0 Changes for translators/tmgmt_local/src/Tests/LocalTranslatorContinuousTest.php: 114 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\tmgmt_local\Tests; use Drupal\tmgmt\Entity\Job; use Drupal\tmgmt\JobItemInterface; use Drupal\node\Entity\Node; /** * Test Continuous jobs support in the local translator. * * @group tmgmt */ class LocalTranslatorContinuousTest extends LocalTranslatorTestBase { /** * Modules to enable. * * @var array */ public static $modules = array('tmgmt_content'); /** * Test continuous Jobs in TMGMT local. */ public function testContinuousJobs() { $type = $this->drupalCreateContentType(); // Enable entity translations for nodes. $content_translation_manager = \Drupal::service('content_translation.manager'); $content_translation_manager->setEnabled('node', $type->label(), TRUE); $this->assignee = $this->drupalCreateUser($this->localTranslatorPermissions); $this->drupalLogin($this->assignee); $edit = array( 'tmgmt_translation_skills[0][language_from]' => 'en', 'tmgmt_translation_skills[0][language_to]' => 'de', ); $this->drupalPostForm('user/' . $this->assignee->id() . '/edit', $edit, t('Save')); $this->loginAsAdmin($this->localManagerPermissions); // Test continuous integration. $this->config('tmgmt.settings') ->set('submit_job_item_on_cron', TRUE) ->save(); // Continuous settings configuration. $continuous_settings = [ 'content' => [ 'node' => [ 'enabled' => 1, 'bundles' => [ $type->id() => 1, ], ], ], ]; $translator = $this->createTranslator(['plugin' => 'local']); $continuous_job = $this->createJob('en', 'de', 0, [ 'label' => 'Continuous job', 'job_type' => Job::TYPE_CONTINUOUS, 'translator' => $translator, 'continuous_settings' => $continuous_settings, ]); $continuous_job->save(); // Create an english node. $node = Node::create([ 'title' => $this->randomMachineName(), 'uid' => 0, 'type' => $type->id(), 'langcode' => 'en', ]); $node->save(); $continuous_job_items = $continuous_job->getItems(); $this->assertEqual(count($continuous_job_items), 1); $continuous_job_item = reset($continuous_job_items); $this->assertTrue($continuous_job_item->getState() == JobItemInterface::STATE_INACTIVE); tmgmt_cron(); $this->drupalGet('translate'); $this->clickLink('View'); // Assign to user. $edit = array( 'tuid' => $this->assignee->id(), ); $this->drupalPostForm(NULL, $edit, t('Save task')); $this->drupalLogin($this->assignee); $this->drupalGet('translate'); $this->clickLink('View'); $this->clickLink('Translate'); $edit = array( 'title|0|value[translation]' => 'Text für Job Element mit Typ-Knoten und ID 1.', ); $this->drupalPostForm(NULL, $edit, t('Save as completed')); $items = $continuous_job->getItems(); $item = reset($items); // Check is set to need review. $data = $item->getData(); $this->assertEqual($data['title']['0']['value']['#translation']['#text'], 'Text für Job Element mit Typ-Knoten und ID 1.'); $this->assertTrue($continuous_job->getState() == Job::STATE_CONTINUOUS); $this->assertTrue($item->getState() == JobItemInterface::STATE_REVIEW); } }