Esempio n. 1
0
 /**
  * Test assignee skills.
  */
 public function testAssigneeSkillsForTasks()
 {
     $this->addLanguage('fr');
     $assignee1 = $this->drupalCreateUser($this->localTranslatorPermissions);
     $this->drupalLogin($assignee1);
     $edit = array('tmgmt_translation_skills[0][language_from]' => 'en', 'tmgmt_translation_skills[0][language_to]' => 'de');
     $this->drupalPostForm('user/' . $assignee1->id() . '/edit', $edit, t('Save'));
     $assignee2 = $this->drupalCreateUser($this->localTranslatorPermissions);
     $this->drupalLogin($assignee2);
     $edit = array('tmgmt_translation_skills[0][language_from]' => 'en', 'tmgmt_translation_skills[0][language_to]' => 'de');
     $this->drupalPostForm('user/' . $assignee2->id() . '/edit', $edit, t('Save'));
     $edit = array('tmgmt_translation_skills[1][language_from]' => 'de', 'tmgmt_translation_skills[1][language_to]' => 'en');
     $this->drupalPostForm('user/' . $assignee2->id() . '/edit', $edit, t('Save'));
     $assignee3 = $this->drupalCreateUser($this->localTranslatorPermissions);
     $this->drupalLogin($assignee3);
     $edit = array('tmgmt_translation_skills[0][language_from]' => 'en', 'tmgmt_translation_skills[0][language_to]' => 'de');
     $this->drupalPostForm('user/' . $assignee3->id() . '/edit', $edit, t('Save'));
     $edit = array('tmgmt_translation_skills[1][language_from]' => 'de', 'tmgmt_translation_skills[1][language_to]' => 'en');
     $this->drupalPostForm('user/' . $assignee3->id() . '/edit', $edit, t('Save'));
     $edit = array('tmgmt_translation_skills[2][language_from]' => 'en', 'tmgmt_translation_skills[2][language_to]' => 'fr');
     $this->drupalPostForm('user/' . $assignee3->id() . '/edit', $edit, t('Save'));
     $job1 = $this->createJob('en', 'de');
     $job2 = $this->createJob('de', 'en');
     $job3 = $this->createJob('en', 'fr');
     $local_task1 = LocalTask::create(array('uid' => $job1->getOwnerId(), 'tjid' => $job1->id(), 'title' => 'Task 1'));
     $local_task1->save();
     $local_task2 = LocalTask::create(array('uid' => $job2->getOwnerId(), 'tjid' => $job2->id(), 'title' => 'Task 2'));
     $local_task2->save();
     $local_task3 = LocalTask::create(array('uid' => $job3->getOwnerId(), 'tjid' => $job3->id(), 'title' => 'Task 3'));
     $local_task3->save();
     // Test languages involved in tasks.
     $this->assertEqual(tmgmt_local_tasks_languages(array($local_task1->id(), $local_task2->id(), $local_task3->id())), array('en' => array('de', 'fr'), 'de' => array('en')));
     // Test available translators for task en - de.
     $this->assertEqual(tmgmt_local_get_assignees_for_tasks(array($local_task1->id())), array($assignee1->id() => $assignee1->getUsername(), $assignee2->id() => $assignee2->getUsername(), $assignee3->id() => $assignee3->getUsername()));
     // Test available translators for tasks en - de, de - en.
     $this->assertEqual(tmgmt_local_get_assignees_for_tasks(array($local_task1->id(), $local_task2->id())), array($assignee2->id() => $assignee2->getUsername(), $assignee3->id() => $assignee3->getUsername()));
     // Test available translators for tasks en - de, de - en, en - fr.
     $this->assertEqual(tmgmt_local_get_assignees_for_tasks(array($local_task1->id(), $local_task2->id(), $local_task3->id())), array($assignee3->id() => $assignee3->getUsername()));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var LocalTask $local_task */
     $local_task = $this->entity;
     $states = LocalTask::getStatuses();
     // Set the title of the page to the label and the current state of the
     // localTask.
     $form['#title'] = t('@title (@source to @target, @state)', array('@title' => $local_task->label(), '@source' => $local_task->getJob()->getSourceLanguage()->getName(), '@target' => $local_task->getJob()->getTargetLanguage()->getName(), '@state' => $states[$local_task->getStatus()]));
     $assignees = tmgmt_local_assignees($local_task->getJob()->getSourceLangcode(), array($local_task->getJob()->getTargetLangcode()));
     $form['tuid'] = array('#title' => t('Assigned'), '#type' => 'select', '#options' => $assignees, '#empty_option' => t('- Unassigned -'), '#default_value' => $local_task->getAssignee()->id(), '#access' => \Drupal::currentUser()->hasPermission('administer tmgmt') || \Drupal::currentUser()->hasPermission('administer translation tasks'));
     $form['info'] = array('#type' => 'container', '#attributes' => array('class' => array('tmgmt-local-task-info', 'clearfix')), '#weight' => 0, '#tree' => TRUE);
     // Check for label value and set for dynamically change.
     if ($form_state->getValue('label') && $form_state->getValue('label') == $local_task->label()) {
         $form_state->setValue('label', $local_task->label());
     }
     $form['title']['widget'][0]['value']['#description'] = t('You can provide a label for this localTask in order to identify it easily later on. Or leave it empty to use the default one.');
     $form['title']['#group'] = 'info';
     $form['title']['#prefix'] = '<div id="tmgmt-ui-label">';
     $form['title']['#suffix'] = '</div>';
     $form['info']['source_language'] = array('#title' => t('Source language'), '#type' => 'item', '#markup' => $local_task->getJob()->getSourceLanguage()->getName(), '#prefix' => '<div id="tmgmt-ui-source-language" class="tmgmt-ui-source-language tmgmt-ui-info-item">', '#suffix' => '</div>', '#value' => $local_task->getJob()->getSourceLangcode());
     $form['info']['target_language'] = array('#title' => t('Target language'), '#type' => 'item', '#markup' => $local_task->getJob()->getTargetLanguage()->getName(), '#prefix' => '<div id="tmgmt-ui-target-language" class="tmgmt-ui-target-language tmgmt-ui-info-item">', '#suffix' => '</div>', '#value' => $local_task->getJob()->getTargetLangcode());
     $form['info']['word_count'] = array('#type' => 'item', '#title' => t('Total word count'), '#markup' => number_format($local_task->getWordCount()), '#prefix' => '<div class="tmgmt-ui-word-count tmgmt-ui-info-item">', '#suffix' => '</div>');
     // Display created time only for localTasks that are not new anymore.
     if (!$local_task->getJob()->isUnprocessed()) {
         $form['info']['created'] = array('#type' => 'item', '#title' => t('Created'), '#markup' => \Drupal::service('date.formatter')->format($local_task->getJob()->getCreatedTime()), '#prefix' => '<div class="tmgmt-ui-created tmgmt-ui-info-item">', '#suffix' => '</div>', '#value' => $local_task->getJob()->getCreatedTime());
     }
     $form['info']['status'] = array('#type' => 'item', '#title' => t('Status'), '#markup' => $states[$local_task->getStatus()], '#prefix' => '<div class="tmgmt-local-ui-status tmgmt-ui-info-item">', '#suffix' => '</div>');
     if ($view = Views::getView('tmgmt_local_task_items')) {
         $block = $view->preview('block_1', [$local_task->id()]);
         $form['items'] = array('#type' => 'item', '#title' => $view->getTitle(), '#prefix' => '<div class="tmgmt-local-task-items">', '#markup' => \Drupal::service('renderer')->render($block), '#attributes' => array('class' => array('tmgmt-local-task-items')), '#suffix' => '</div>', '#weight' => 10);
     }
     $form['footer'] = tmgmt_color_legend_local_task_item();
     $form['footer']['#weight'] = 100;
     $form['#attached']['library'][] = 'tmgmt/admin';
     return $form;
 }