You are here

protected function JobItemForm::buildActions in Translation Management Tool 8

Builds the actions for a data item.

Parameters

array $data_item: The data item.

string $key: The data item key for the given structure.

string $field_name: The name of the form element.

string $ajax_id: The ID used for ajax replacements.

Return value

array A list of action form elements.

1 call to JobItemForm::buildActions()
JobItemForm::reviewFormElement in src/Form/JobItemForm.php
Build form elements for the review form using flattened data items.

File

src/Form/JobItemForm.php, line 763

Class

JobItemForm
Form controller for the job item edit forms.

Namespace

Drupal\tmgmt\Form

Code

protected function buildActions($data_item, $key, $field_name, $ajax_id) {
  $actions = [];
  if (!$this->entity
    ->isAccepted()) {
    if ($data_item['#status'] != TMGMT_DATA_ITEM_STATE_REVIEWED) {
      $actions['reviewed'] = array(
        '#type' => 'submit',
        // Unicode character &#x2713 CHECK MARK
        '#value' => '✓',
        '#attributes' => array(
          'title' => t('Reviewed'),
        ),
        '#name' => 'reviewed-' . $field_name,
        '#submit' => [
          '::save',
          'tmgmt_translation_review_form_update_state',
        ],
        '#limit_validation_errors' => array(
          array(
            $ajax_id,
          ),
          array(
            $field_name,
          ),
        ),
        '#ajax' => array(
          'callback' => array(
            $this,
            'ajaxReviewForm',
          ),
          'wrapper' => $ajax_id,
        ),
      );
    }
    else {
      $actions['unreviewed'] = array(
        '#type' => 'submit',
        // Unicode character &#x2713 CHECK MARK
        '#value' => '✓',
        '#attributes' => array(
          'title' => t('Not reviewed'),
          'class' => array(
            'unreviewed',
          ),
        ),
        '#name' => 'unreviewed-' . $field_name,
        '#submit' => [
          '::save',
          'tmgmt_translation_review_form_update_state',
        ],
        '#limit_validation_errors' => array(
          array(
            $ajax_id,
          ),
          array(
            $field_name,
          ),
        ),
        '#ajax' => array(
          'callback' => array(
            $this,
            'ajaxReviewForm',
          ),
          'wrapper' => $ajax_id,
        ),
      );
    }
    if ($this->entity
      ->hasTranslator() && $this->entity
      ->getTranslatorPlugin() instanceof TranslatorRejectDataInterface && $data_item['#status'] != TMGMT_DATA_ITEM_STATE_PENDING) {
      $actions['reject'] = array(
        '#type' => 'submit',
        // Unicode character &#x2717 BALLOT X
        '#value' => '✗',
        '#attributes' => array(
          'title' => t('Reject'),
        ),
        '#name' => 'reject-' . $field_name,
        '#submit' => [
          '::save',
          'tmgmt_translation_review_form_update_state',
        ],
      );
    }
    if (!empty($data_item['#translation']['#text_revisions'])) {
      $actions['revert'] = array(
        '#type' => 'submit',
        // Unicode character U+21B6 ANTICLOCKWISE TOP SEMICIRCLE ARROW
        '#value' => '↶',
        '#attributes' => array(
          'title' => t('Revert to previous revision'),
          'class' => array(
            'reset-above',
          ),
        ),
        '#name' => 'revert-' . $field_name,
        '#data_item_key' => $key,
        '#submit' => array(
          'tmgmt_translation_review_form_revert',
        ),
        '#ajax' => array(
          'callback' => array(
            $this,
            'ajaxReviewForm',
          ),
          'wrapper' => $ajax_id,
        ),
      );
      $actions['reviewed']['#attributes'] = array(
        'class' => array(
          'reviewed-below',
        ),
      );
    }
  }
  return $actions;
}