diff --git a/src/Entity/JobItem.php b/src/Entity/JobItem.php index cc7a780..904b387 100644 --- a/src/Entity/JobItem.php +++ b/src/Entity/JobItem.php @@ -32,8 +32,7 @@ use Drupal\Core\Render\Element; * "form" = { * "edit" = "Drupal\tmgmt\Form\JobItemForm", * "abort" = "Drupal\tmgmt\Form\JobItemAbortForm", - * "delete" = "Drupal\tmgmt\Form\JobItemDeleteForm", - * "resubmit" = "Drupal\tmgmt\Form\JobItemResubmitForm", + * "delete" = "Drupal\tmgmt\Form\JobItemDeleteForm" * }, * "list_builder" = "Drupal\tmgmt\Entity\ListBuilder\JobItemListBuilder", * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", @@ -48,7 +47,6 @@ use Drupal\Core\Render\Element; * "canonical" = "/admin/tmgmt/items/{tmgmt_job_item}", * "abort-form" = "/admin/tmgmt/items/{tmgmt_job_item}/abort", * "delete-form" = "/admin/tmgmt/items/{tmgmt_job_item}/delete", - * "resubmit-form" = "/admin/tmgmt/items/{tmgmt_job_item}/resubmit", * } * ) * diff --git a/src/Entity/ListBuilder/JobItemListBuilder.php b/src/Entity/ListBuilder/JobItemListBuilder.php index f7f5143..1503ca9 100644 --- a/src/Entity/ListBuilder/JobItemListBuilder.php +++ b/src/Entity/ListBuilder/JobItemListBuilder.php @@ -34,7 +34,7 @@ class JobItemListBuilder extends EntityListBuilder { ); } // Do not display delete on active jobs, display abort. - if ($entity->getJob()->isActive() && !$entity->isAborted()) { + if ($entity->getJob()->isActive() && $entity->isActive() && !$entity->isAborted()) { unset($operations['delete']); $operations['cancel'] = array( 'url' => $entity->urlInfo('abort-form')->setOption('query', array('destination' => Url::fromRoute('')->getInternalPath())), diff --git a/src/Form/JobItemForm.php b/src/Form/JobItemForm.php index f366fb6..2c7ff7e 100644 --- a/src/Form/JobItemForm.php +++ b/src/Form/JobItemForm.php @@ -153,14 +153,6 @@ class JobItemForm extends TmgmtFormBase { '#validate' => array('::validateForm', '::validateJobItem'), '#submit' => array('::submitForm', '::save'), ); - $actions['resubmit'] = array( - '#type' => 'submit', - '#button_type' => 'primary', - '#value' => t('Resubmit'), - '#access' => $item->isAborted(), - '#redirect' => 'admin/tmgmt/items/' . $item->id() . '/resubmit', - '#submit' => array('tmgmt_submit_redirect'), - ); $actions['save'] = array( '#type' => 'submit', '#value' => t('Save'), @@ -194,6 +186,15 @@ 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; } diff --git a/src/Form/JobItemResubmitForm.php b/src/Form/JobItemResubmitForm.php deleted file mode 100644 index 7d41545..0000000 --- a/src/Form/JobItemResubmitForm.php +++ /dev/null @@ -1,49 +0,0 @@ -t('Resubmit job item?', array('%title' => $this->entity->label())); - } - - public function getDescription() { - return $this->t('This resubmits job item. In case the sources meanwhile changed, the job item will reflect the update.'); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo(); - - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $item = $this->entity; - $item->resetData(); - $item->setState(JobItemInterface::STATE_ACTIVE); - drupal_set_message(t('The aborted job item has been resubmitted.')); - $form_state->setRedirectUrl($item->urlInfo()); - } - -} diff --git a/src/Tests/TMGMTUiTest.php b/src/Tests/TMGMTUiTest.php index 588e440..e28b758 100644 --- a/src/Tests/TMGMTUiTest.php +++ b/src/Tests/TMGMTUiTest.php @@ -1190,7 +1190,7 @@ class TMGMTUiTest extends EntityTestBase { } /** - * Test the deletion of job item. + * Test the deletion and abortion of job item. * * @todo This will in future check that delete is not allowed. * @todo There will be some overlap with Aborting items & testAbortJob. @@ -1209,6 +1209,32 @@ class TMGMTUiTest extends EntityTestBase { // Add item to the job. $item = $job->addItem('test_source', 'test', 1); + $item->setState(JobItem::STATE_ACTIVE); + + $this->drupalGet('admin/tmgmt/jobs/' . $job->id()); + + // Check that there is no delete link. + $this->assertNoLink('Delete'); + + // Check for abort link. + $this->assertLink('Abort'); + + $this->clickLink('Abort'); + $this->assertText(t('Abort this job item?')); + + // Check if cancel button is present or not. + $this->assertLink('Cancel'); + + // Abort the job item. + $this->drupalPostForm(NULL, [], t('Confirm')); + + // Reload job and check its state and state of its item. + \Drupal::entityManager()->getStorage('tmgmt_job')->resetCache(); + $job = Job::load($job->id()); + $this->assertTrue($job->isActive()); + $items = $job->getItems(); + $item = reset($items); + $this->assertTrue($item->isAborted()); $this->drupalGet('admin/tmgmt/jobs/' . $job->id()); diff --git a/tmgmt.routing.yml b/tmgmt.routing.yml index 3cc4b33..545f937 100644 --- a/tmgmt.routing.yml +++ b/tmgmt.routing.yml @@ -96,13 +96,6 @@ entity.tmgmt_job_item.delete_form: requirements: _entity_access: tmgmt_job_item.delete -entity.tmgmt_job_item.resubmit_form: - path: '/admin/tmgmt/items/{tmgmt_job_item}/resubmit' - defaults: - _entity_form: tmgmt_job_item.resubmit - requirements: - _entity_access: tmgmt_job_item.update - entity.tmgmt_job_item.abort_form: path: '/admin/tmgmt/items/{tmgmt_job_item}/abort' defaults: