/** * {@inheritdoc} */ public function checkoutSettingsForm(array $form, FormStateInterface $form_state, JobInterface $job) { if ($translators = tmgmt_local_assignees($job->getSourceLangcode(), array($job->getTargetLangcode()))) { $form['translator'] = array('#title' => t('Assign job to'), '#type' => 'select', '#options' => array('' => t('- Select user -')) + $translators, '#default_value' => $job->getSetting('translator')); } else { $form['message'] = array('#markup' => t('There are no users available to assign.')); } $form['job_comment'] = array('#type' => 'textarea', '#title' => t('Comment for the translation'), '#description' => t('You can provide a comment so that the assigned user will better understand your requirements.'), '#default_value' => $job->getSetting('job_comment')); return $form; }
/** * {@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; }
public function testAbilitiesAPI() { $this->addLanguage('fr'); $this->addLanguage('ru'); $this->addLanguage('it'); $all_assignees = array(); $assignee1 = $this->drupalCreateUser($this->localTranslatorPermissions); $all_assignees[$assignee1->id()] = $assignee1->getUsername(); $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); $all_assignees[$assignee2->id()] = $assignee2->getUsername(); $this->drupalLogin($assignee2); $edit = array('tmgmt_translation_skills[0][language_from]' => 'en', 'tmgmt_translation_skills[0][language_to]' => 'ru'); $this->drupalPostForm('user/' . $assignee2->id() . '/edit', $edit, t('Save')); $edit = array('tmgmt_translation_skills[1][language_from]' => 'en', 'tmgmt_translation_skills[1][language_to]' => 'fr'); $this->drupalPostForm('user/' . $assignee2->id() . '/edit', $edit, t('Save')); $edit = array('tmgmt_translation_skills[2][language_from]' => 'fr', 'tmgmt_translation_skills[2][language_to]' => 'it'); $this->drupalPostForm('user/' . $assignee2->id() . '/edit', $edit, t('Save')); $assignee3 = $this->drupalCreateUser($this->localTranslatorPermissions); $all_assignees[$assignee3->id()] = $assignee3->getUsername(); $this->drupalLogin($assignee3); $edit = array('tmgmt_translation_skills[0][language_from]' => 'fr', 'tmgmt_translation_skills[0][language_to]' => 'ru'); $this->drupalPostForm('user/' . $assignee3->id() . '/edit', $edit, t('Save')); $edit = array('tmgmt_translation_skills[1][language_from]' => 'it', 'tmgmt_translation_skills[1][language_to]' => 'en'); $this->drupalPostForm('user/' . $assignee3->id() . '/edit', $edit, t('Save')); // Test target languages. $target_languages = tmgmt_local_supported_target_languages('fr'); $this->assertTrue(isset($target_languages['it'])); $this->assertTrue(isset($target_languages['ru'])); $target_languages = tmgmt_local_supported_target_languages('en'); $this->assertTrue(isset($target_languages['fr'])); $this->assertTrue(isset($target_languages['ru'])); // Test language pairs. $this->assertEqual(tmgmt_local_supported_language_pairs(), array('en__de' => array('source_language' => 'en', 'target_language' => 'de'), 'en__ru' => array('source_language' => 'en', 'target_language' => 'ru'), 'en__fr' => array('source_language' => 'en', 'target_language' => 'fr'), 'fr__it' => array('source_language' => 'fr', 'target_language' => 'it'), 'fr__ru' => array('source_language' => 'fr', 'target_language' => 'ru'), 'it__en' => array('source_language' => 'it', 'target_language' => 'en'))); $this->assertEqual(tmgmt_local_supported_language_pairs('fr', array($assignee2->id())), array('fr__it' => array('source_language' => 'fr', 'target_language' => 'it'))); // Test if we got all translators. $assignees = tmgmt_local_assignees(); foreach ($all_assignees as $uid => $name) { if (!isset($assignees[$uid])) { $this->fail('Expected translator not present'); } if (!in_array($name, $all_assignees)) { $this->fail('Expected translator name not present'); } } // Only translator2 has such abilities. $assignees = tmgmt_local_assignees('en', array('ru', 'fr')); $this->assertTrue(isset($assignees[$assignee2->id()])); }