function maestro_content_type_task_submit in Maestro 3.x
Same name and namespace in other branches
- 8.2 maestro.module \maestro_content_type_task_submit()
Handling the submission from a content type task. This will offload the saving from the content type task plugin.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The formstate information from the form.
1 string reference to 'maestro_content_type_task_submit'
- maestro_form_alter in ./
maestro.module - Implements hook_form_alter().
File
- ./
maestro.module, line 313 - Provides glue logic, hook implementation and core set process variable functions.
Code
function maestro_content_type_task_submit(array &$form, FormStateInterface $form_state) {
global $base_url;
$trigger = $form_state
->getTriggeringElement();
$maestroElements = $form_state
->getValue('maestro');
$queueID = $maestroElements['queue_id'];
$processID = $maestroElements['process_id'];
$contentType = $maestroElements['type'];
$storage = $form_state
->getStorage();
// We have a node ID.
if (intval($storage['nid']) > 0) {
$task = MaestroEngine::getTemplateTaskByQueueID($queueID);
$uniqueIdentifier = $task['data']['unique_id'];
$entityIdentifier = MaestroEngine::getEntityIdentiferByUniqueID($processID, $uniqueIdentifier);
// doesn't exist in our entity identifiers entity.
if (!$entityIdentifier) {
MaestroEngine::createEntityIdentifier($processID, 'node', $contentType, $uniqueIdentifier, $storage['nid']);
// Since we don't have this combo set in our entity identifiers, we then need to set the handler too to point to the content.
$queueRecord = \Drupal::entityTypeManager()
->getStorage('maestro_queue')
->load($queueID);
$queueRecord
->set('handler', $base_url . '/node/' . $storage['nid'] . '/edit?maestro=1');
$queueRecord
->save();
}
if ($trigger['#id'] != 'edit-save-edit-later') {
// We want to complete the task here and redirect to the redirection location specified.
\Drupal::messenger()
->addMessage(t('Content added and your task has been completed!'));
MaestroEngine::completeTask($queueID, \Drupal::currentUser()
->id());
if (isset($task['data']['redirect_to'])) {
$response = new RedirectResponse('/' . ltrim($task['data']['redirect_to'], '/'));
$response
->send();
}
}
else {
if (isset($task['data']['redirect_to']) && $task['data']['redirect_to'] != '') {
// We need to change the handler for this task to go to the content edit page.
\Drupal::messenger()
->addMessage(t('Content added and your task is still open for completion!'));
$response = new RedirectResponse('/' . ltrim($task['data']['redirect_to'], '/') . '/' . $queueID);
$response
->send();
}
}
}
}