/** * Builds the actions for a data item. * * @param array $data_item * The data item. * @param string $key * The data item key for the given structure. * @param string $field_name * The name of the form element. * @param string $ajax_id * The ID used for ajax replacements. * * @return array * A list of action form elements. */ 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', '#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', '#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', '#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', '#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; }