diff --git a/src/Entity/JobItem.php b/src/Entity/JobItem.php index d7e099d..4317d4a 100644 --- a/src/Entity/JobItem.php +++ b/src/Entity/JobItem.php @@ -827,10 +827,7 @@ class JobItem extends ContentEntityBase implements JobItemInterface { if (!$this->isActive() || !$this->getTranslatorPlugin()) { throw new TMGMTException('Cannot abort job item.'); } - else { - $this->setState(JobItemInterface::STATE_ABORTED); - return TRUE; - } + return $this->setState(JobItemInterface::STATE_ABORTED); } /** diff --git a/src/Entity/ListBuilder/JobItemListBuilder.php b/src/Entity/ListBuilder/JobItemListBuilder.php index ebeb081..ddbf3b3 100644 --- a/src/Entity/ListBuilder/JobItemListBuilder.php +++ b/src/Entity/ListBuilder/JobItemListBuilder.php @@ -33,8 +33,8 @@ class JobItemListBuilder extends EntityListBuilder { 'title' => t('View'), ); } - // Do not display delete on active jobs, display abort. - if ($entity->getJob()->isActive() && $entity->isActive() && !$entity->isAborted()) { + // Do not display delete on active job items, display abort. + if ($entity->getJob()->isActive() && $entity->isActive()) { unset($operations['delete']); $operations['abort'] = array( 'url' => $entity->urlInfo('abort-form')->setOption('query', array('destination' => Url::fromRoute('')->getInternalPath())), @@ -42,6 +42,10 @@ class JobItemListBuilder extends EntityListBuilder { 'weight' => 10, ); } + // Do not display delete on aborted job items also. + if ($entity->isAborted()) { + unset($operations['delete']); + } return $operations; } diff --git a/src/Form/JobAbortForm.php b/src/Form/JobAbortForm.php index 892cc0a..07e6f98 100644 --- a/src/Form/JobAbortForm.php +++ b/src/Form/JobAbortForm.php @@ -48,7 +48,17 @@ class JobAbortForm extends ContentEntityConfirmFormBase { // It would make more sense to not display the button for the action, // however we do not know if the translator is able to abort a job until // we trigger the action. - tmgmt_write_request_messages($entity); + foreach ($entity->getMessagesSince() as $message) { + /** @var \Drupal\tmgmt\MessageInterface $message */ + if ($message->getType() == 'debug') { + continue; + } + if ($text = $message->getMessage()) { + // We want to persist also the type therefore we will set the + // messages directly and not return them. + drupal_set_message($text, $message->getType()); + } + } } else { $entity->addMessage('The user ordered aborting the Job through the UI.'); diff --git a/src/Form/JobItemAbortForm.php b/src/Form/JobItemAbortForm.php index 290bca3..6217389 100644 --- a/src/Form/JobItemAbortForm.php +++ b/src/Form/JobItemAbortForm.php @@ -22,15 +22,18 @@ class JobItemAbortForm extends ContentEntityConfirmFormBase { return $this->t('Abort this job item?', array('%title' => $this->entity->label())); } + /** + * {@inheritdoc} + */ public function getDescription() { - return $this->t('This is only an internal decision and the translator does not know about it. After the action the job item will be aborted and the only remaining action will be deleting it.'); + return $this->t('This is only an internal decision and the translator does not know about it. After the action the job item will be aborted.'); } /** * {@inheritdoc} */ public function getCancelUrl() { - return $this->entity->urlInfo(); + return $this->entity->toUrl(); } /** @@ -40,10 +43,19 @@ class JobItemAbortForm extends ContentEntityConfirmFormBase { /** @var \Drupal\tmgmt\Entity\JobItem $entity */ $entity = $this->entity; if (!$entity->abortTranslation()) { - // This is the case when a translator does not support the abort operation. - tmgmt_write_request_messages($entity); + foreach ($entity->getMessagesSince() as $message) { + /** @var \Drupal\tmgmt\MessageInterface $message */ + if ($message->getType() == 'debug') { + continue; + } + if ($text = $message->getMessage()) { + // We want to persist also the type therefore we will set the + // messages directly and not return them. + drupal_set_message($text, $message->getType()); + } + } } - $form_state->setRedirectUrl($this->entity->urlInfo()); + $form_state->setRedirectUrl($this->entity->toUrl()); } } diff --git a/src/Form/JobItemForm.php b/src/Form/JobItemForm.php index de7b463..fa83f94 100644 --- a/src/Form/JobItemForm.php +++ b/src/Form/JobItemForm.php @@ -8,6 +8,7 @@ namespace Drupal\tmgmt\Form; use Drupal\Component\Utility\NestedArray; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Xss; use Drupal\tmgmt\Entity\JobItem; use Drupal\tmgmt\JobItemInterface; @@ -164,7 +165,7 @@ class JobItemForm extends TmgmtFormBase { '#type' => 'submit', '#button_type' => 'primary', '#value' => t('Save as completed'), - '#access' => $item->isNeedsReview() && !$item->isAborted(), + '#access' => $item->isNeedsReview(), '#validate' => array('::validateForm', '::validateJobItem'), '#submit' => array('::submitForm', '::save'), ); @@ -201,15 +202,6 @@ class JobItemForm extends TmgmtFormBase { ], ]; } - $actions['delete'] = array( - '#type' => 'submit', - '#value' => t('Delete'), - '#access' => $item->isAborted(), - '#submit' => array('tmgmt_submit_redirect'), - '#redirect' => 'admin/tmgmt/items/' . $item->id() . '/delete', - // Don't run validations, so the user can always delete the job item. - '#limit_validation_errors' => array(), - ); return $actions; } @@ -342,7 +334,15 @@ class JobItemForm extends TmgmtFormBase { $item->acceptTranslation(); // Print all messages that have been saved while accepting the reviewed // translation. - tmgmt_write_request_messages($item); + foreach ($item->getMessagesSince() as $message) { + // Ignore debug messages. + if ($message->getType() == 'debug') { + continue; + } + if ($text = $message->getMessage()) { + drupal_set_message(SafeMarkup::format($text, []), $message->getType()); + } + } } if ($form_state->getTriggeringElement()['#value'] == $form['actions']['save']['#value'] && isset($data)) { drupal_set_message(t('The translation for @job_title has been saved successfully.', [ diff --git a/src/JobItemInterface.php b/src/JobItemInterface.php index f469f74..4cf380e 100644 --- a/src/JobItemInterface.php +++ b/src/JobItemInterface.php @@ -163,12 +163,14 @@ interface JobItemInterface extends ContentEntityInterface { /** * Attempts to abort the translation job item. * - * Already accepted job items can not be aborted, submitted job items only if - * supported by the translator plugin. Always use this method if you want to - * abort a translation job item. + * Already accepted job items can not be aborted. Always use this method if + * you want to abort a translation job item. * - * @return bool - * TRUE if the translation job item was aborted, FALSE otherwise. + * @return int + * The updated state of the job item if it could be set. + * + * @throws \Drupal\tmgmt\TMGMTException + * If fails to abort the job item. */ public function abortTranslation(); diff --git a/src/Tests/TMGMTUiTest.php b/src/Tests/TMGMTUiTest.php index 5a797a3..01aff91 100644 --- a/src/Tests/TMGMTUiTest.php +++ b/src/Tests/TMGMTUiTest.php @@ -803,27 +803,17 @@ class TMGMTUiTest extends EntityTestBase { $item = reset($items); $this->assertTrue($item->isAborted()); - // Check for delete button on item review form. + // Check that there is no delete button on item review form. $this->drupalGet('admin/tmgmt/items/' . $item->id()); - $this->assertFieldById('edit-delete', NULL, 'There is delete button.'); + $this->assertNoFieldById('edit-delete', NULL, 'There is delete button.'); // Check that there is no accept button on item review form. $this->assertNoFieldById('edit-accept', NULL, 'There is no accept button.'); $this->drupalGet('admin/tmgmt/jobs/' . $job->id()); - // Check for delete link. - $this->assertLink('Delete'); - - $this->clickLink('Delete'); - $this->assertText(t('Are you sure you want to delete the translation job item @label?', ['@label' => $item->getSourceLabel()])); - - // Check if cancel button is present or not. - $this->assertLink('Cancel'); - - // Delete the job item. - $this->drupalPostForm(NULL, [], t('Delete')); - $this->assertText(t('The translation job item @label has been deleted', ['@label' => $item->getSourceLabel()])); + // Check that there is no delete link on job overview. + $this->assertNoLink('Delete'); } /** diff --git a/tmgmt.module b/tmgmt.module index 0413bc5..ab93921 100644 --- a/tmgmt.module +++ b/tmgmt.module @@ -16,7 +16,6 @@ use Drupal\tmgmt\Entity\JobItem; use Drupal\tmgmt\JobInterface; use Drupal\tmgmt\JobItemInterface; use Drupal\tmgmt\TranslatorRejectDataInterface; -use Drupal\Component\Render\FormattableMarkup; /** * @addtogroup tmgmt_job @@ -687,13 +686,13 @@ function tmgmt_job_request_translation(JobInterface $job) { /** * Print all messages that occurred since our request to the screen. * - * @param \Drupal\tmgmt\JobInterface|\Drupal\tmgmt\JobItemInterface $job - * The translation job or job item for which the message should be written. + * @param \Drupal\tmgmt\JobInterface $job + * The translation job for which the message should be written. * * @return bool * FALSE if there are message with severity error, TRUE otherwise. */ -function tmgmt_write_request_messages($job) { +function tmgmt_write_request_messages(JobInterface $job) { $errors = FALSE; foreach ($job->getMessagesSince() as $message) { // Ignore debug messages. @@ -704,7 +703,7 @@ function tmgmt_write_request_messages($job) { $errors = TRUE; } if ($text = $message->getMessage()) { - drupal_set_message(new FormattableMarkup($text, []), $message->getType()); + drupal_set_message($text, $message->getType()); } } return !$errors;