You are here

class TMGMTJobUIController in Translation Management Tool 7

Entity UI controller for the Job Entity.

Hierarchy

Expanded class hierarchy of TMGMTJobUIController

1 string reference to 'TMGMTJobUIController'
tmgmt_ui_entity_info in ui/tmgmt_ui.module
Implements hook_entity_info().

File

ui/includes/tmgmt_ui.controller.job.inc, line 11
Contains the job UI controller.

View source
class TMGMTJobUIController extends EntityDefaultUIController {

  /**
   * Translation job that is a duplicate of an aborted job.
   *
   * @var TMGMTJob
   */
  private $jobToResubmit = NULL;

  /**
   * {@inheritdoc}
   */
  public function hook_menu() {
    $id_count = count(explode('/', $this->path));
    $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
    $items[$this->path . '/' . $wildcard] = array(
      'title callback' => 'entity_label',
      'title arguments' => array(
        $this->entityType,
        $id_count,
      ),
      'page callback' => 'tmgmt_ui_job_view',
      'page arguments' => array(
        $id_count,
      ),
      'load arguments' => array(
        $this->entityType,
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'view',
        $this->entityType,
        $id_count,
      ),
      'file' => $this->entityInfo['admin ui']['file'],
      'file path' => $this->entityInfo['admin ui']['file path'],
    );
    $items[$this->path . '/' . $wildcard . '/delete'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        $this->entityType . '_operation_form',
        $this->entityType,
        $id_count,
        $id_count + 1,
      ),
      'load arguments' => array(
        $this->entityType,
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'delete',
        $this->entityType,
        $id_count,
      ),
      'type' => MENU_CALLBACK,
    );
    $items[$this->path . '/' . $wildcard . '/abort'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        $this->entityType . '_operation_form',
        $this->entityType,
        $id_count,
        $id_count + 1,
      ),
      'load arguments' => array(
        $this->entityType,
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'abort',
        $this->entityType,
        $id_count,
      ),
      'type' => MENU_CALLBACK,
    );
    $items[$this->path . '/' . $wildcard . '/resubmit'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        $this->entityType . '_operation_form',
        $this->entityType,
        $id_count,
        $id_count + 1,
      ),
      'load arguments' => array(
        $this->entityType,
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'resubmit',
        $this->entityType,
        $id_count,
      ),
      'type' => MENU_CALLBACK,
    );
    return $items;
  }

  /**
   * {@inheritdoc}
   */
  public function operationForm($form, &$form_state, $entity, $op) {
    switch ($op) {
      case 'delete':
        $confirm_question = t('Are you sure you want to delete the translation job %label?', array(
          '%label' => $entity
            ->label(),
        ));
        return confirm_form($form, $confirm_question, $this->path);
      case 'abort':
        return confirm_form($form, t('Abort this job?'), 'admin/tmgmt/jobs/' . $entity->tjid, t('This will send a request to the translator to abort the job. After the action the job translation process will be aborted and only remaining action will be resubmitting it.'));
      case 'resubmit':
        return confirm_form($form, t('Resubmit as a new job?'), 'admin/tmgmt/jobs/' . $entity->tjid, t('This creates a new job with the same items which can then be submitted again. In case the sources meanwhile changed, the new job will reflect the update.'));
    }
    drupal_not_found();
    exit;
  }

  /**
   * {@inheritdoc}
   */
  public function applyOperation($op, $entity) {
    switch ($op) {
      case 'delete':
        $entity
          ->delete();
        return t('Deleted the translation job %label.', array(
          '%label' => $entity
            ->label(),
        ));
      case 'abort':
        if (!$entity
          ->abortTranslation()) {

          // This is the case when a translator does not support the abort operation.
          // 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.
          foreach ($entity
            ->getMessagesSince() as $message) {
            if ($message->type == '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(filter_xss($text), $message->type);
            }
          }
        }
        break;
      case 'resubmit':
        $this->jobToResubmit = $entity
          ->cloneAsUnprocessed();
        $this->jobToResubmit->uid = $GLOBALS['user']->uid;
        $this->jobToResubmit
          ->save();

        /** @var TMGMTJobItem $item */
        foreach ($entity
          ->getItems() as $item) {
          $item_to_resubmit = $item
            ->cloneAsActive();
          $this->jobToResubmit
            ->addExistingItem($item_to_resubmit);
        }
        $entity
          ->addMessage('Job has been duplicated as a new job <a href="@url">#@id</a>.', array(
          '@url' => url('admin/tmgmt/jobs/' . $this->jobToResubmit->tjid),
          '@id' => $this->jobToResubmit->tjid,
        ));
        $this->jobToResubmit
          ->addMessage('This job is a duplicate of the previously aborted job <a href="@url">#@id</a>', array(
          '@url' => url('admin/tmgmt/jobs/' . $entity->tjid),
          '@id' => $entity->tjid,
        ));
        return t('The aborted job has been duplicated. You can resubmit it now.');
    }
    return FALSE;
  }

  /**
   * Operation form submit callback.
   */
  public function operationFormSubmit($form, &$form_state) {
    parent::operationFormSubmit($form, $form_state);
    if ($form_state['op'] == 'resubmit') {
      $form_state['redirect'] = $this->path . '/' . $this->jobToResubmit->tjid;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityDefaultUIController::$entityInfo protected property
EntityDefaultUIController::$entityType protected property
EntityDefaultUIController::$id_count protected property
EntityDefaultUIController::$overviewPagerLimit public property Defines the number of entries to show per page in overview table.
EntityDefaultUIController::entityFormSubmitBuildEntity public function Entity submit builder invoked via entity_ui_form_submit_build_entity().
EntityDefaultUIController::hook_forms public function Provides definitions for implementing hook_forms().
EntityDefaultUIController::operationCount protected function Returns the operation count for calculating colspans.
EntityDefaultUIController::operationFormValidate public function Operation form validation callback.
EntityDefaultUIController::overviewForm public function Builds the entity overview form.
EntityDefaultUIController::overviewFormSubmit public function Overview form submit callback.
EntityDefaultUIController::overviewFormValidate public function Overview form validation callback.
EntityDefaultUIController::overviewTable public function Generates the render array for a overview table for arbitrary entities matching the given conditions.
EntityDefaultUIController::overviewTableHeaders protected function Generates the table headers for the overview table.
EntityDefaultUIController::overviewTableRow protected function Generates the row for the passed entity and may be overridden in order to customize the rows.
EntityDefaultUIController::__construct public function
TMGMTJobUIController::$jobToResubmit private property Translation job that is a duplicate of an aborted job.
TMGMTJobUIController::applyOperation public function Applies an operation to the given entity. Overrides EntityDefaultUIController::applyOperation
TMGMTJobUIController::hook_menu public function Provides definitions for implementing hook_menu(). Overrides EntityDefaultUIController::hook_menu
TMGMTJobUIController::operationForm public function Builds the operation form. Overrides EntityDefaultUIController::operationForm
TMGMTJobUIController::operationFormSubmit public function Operation form submit callback. Overrides EntityDefaultUIController::operationFormSubmit