function tmgmt_translation_review_form_update_state in Translation Management Tool 8
Callback for the action at the job item review form.
2 string references to 'tmgmt_translation_review_form_update_state'
- JobItemForm::buildActions in src/
Form/ JobItemForm.php - Builds the actions for a data item.
- tmgmt_translation_review_form_reject_confirm in ./
tmgmt.module - Form callback for the reject confirm form.
File
- ./
tmgmt.module, line 773 - Main module file for the Translation Management module.
Code
function tmgmt_translation_review_form_update_state(array $form, FormStateInterface $form_state) {
$matches = array();
// We should have an #name element
// and the name should beginn with approve-
// and the $matches should now contain an element with name key.
preg_match("/^(?P<action>[^-]+)-(?P<key>.+)/i", $form_state
->getTriggeringElement()['#name'], $matches);
$values = $form_state
->getValues();
$data = array();
$job_item = $form_state
->getFormObject()
->getEntity();
/** @var \Drupal\tmgmt\JobItemInterface $job_item */
$plugin = $job_item
->getTranslatorPlugin();
$success = TRUE;
switch ($matches['action']) {
case 'reviewed':
$form_state
->setRebuild();
$data['#status'] = TMGMT_DATA_ITEM_STATE_REVIEWED;
break;
case 'unreviewed':
$form_state
->setRebuild();
$data['#status'] = TMGMT_DATA_ITEM_STATE_TRANSLATED;
break;
case 'reject':
if (empty($values['confirm'])) {
if (isset($_GET['destination'])) {
$destination = $_GET['destination'];
unset($_GET['destination']);
}
else {
$destination = '';
}
tmgmt_redirect_queue_set(array(
Url::fromRoute('<current>')
->getInternalPath(),
), $destination);
$form_state
->setRedirectUrl(Url::fromUri('base:' . Url::fromRoute('<current>')
->getInternalPath() . '/reject/' . $matches['key']));
$success = FALSE;
}
else {
$form_state
->setRedirectUrl(Url::fromUri('base:' . tmgmt_redirect_queue_dequeue(), array(
'query' => array(
'destination' => tmgmt_redirect_queue_destination(),
),
)));
if ($plugin instanceof TranslatorRejectDataInterface) {
$success = $job_item
->getTranslatorController()
->rejectDataItem($job_item, \Drupal::service('tmgmt.data')
->ensureArrayKey($matches['key']), $values);
}
}
default:
$data['#status'] = TMGMT_DATA_ITEM_STATE_PENDING;
break;
}
if ($success) {
$job_item
->updateData($matches['key'], $data);
// If a data item has been rejected and the job is in needs review state,
// set back to active.
if ($matches['action'] == 'reject' && $job_item
->isNeedsReview()) {
$job_item
->active(FALSE);
}
}
$job_item
->save();
tmgmt_write_request_messages($job_item);
}