diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c14689f
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,40 @@
+language: php
+
+sudo: false
+
+php:
+- 7.4
+
+before_install:
+- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
+
+install:
+- composer global require drush/drush:8.x-dev drupal/coder mglaman/drupal-check friendsoftwig/twigcs
+- export PATH="$HOME/.config/composer/vendor/bin:$PATH"
+- phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer
+- phpenv rehash
+- nvm install 12.13.0
+- nvm use 12
+- npm install --global yarn
+- cd ../ && composer create-project drupal-composer/drupal-project:8.x-dev drupal --no-interaction
+- cd drupal
+- DRUPAL_ROOT=$(pwd)/web
+- export REPOSITORIES='"repositories":\ \['
+- export REPOSITORIES_REPLACE='"repositories":\[\{"type":"path","url":"..\/os2forms_forloeb","options":\{"symlink":false\}\},'
+- export REQUIRE='"require":\ {'
+- export REQUIRE_REPLACE='"require":{"os2forms\/os2forms_forloeb":"\*",'
+- sed -i "s/$REPOSITORIES/$REPOSITORIES_REPLACE/g" composer.json
+- sed -i "s/$REQUIRE/$REQUIRE_REPLACE/g" composer.json
+- composer update os2forms/os2forms_forloeb
+- PROJECT_PATH=$DRUPAL_ROOT/modules/contrib/os2forms_forloeb
+- cd $DRUPAL_ROOT/core
+- yarn install
+- npm install --global eslint-config-drupal-bundle stylelint
+
+script:
+- phpcs --standard=Drupal --ignore=*.md $PROJECT_PATH
+- twigcs $PROJECT_PATH
+- cd $DRUPAL_ROOT/core
+- eslint $DRUPAL_ROOT/modules/contrib/os2forms_forloeb
+- stylelint --aei $DRUPAL_ROOT/modules/contrib/os2forms_forloeb/**/*.css
+- drupal-check $DRUPAL_ROOT/modules/contrib/os2forms_forloeb
diff --git a/composer.json b/composer.json
index 5b58f1d..347629f 100644
--- a/composer.json
+++ b/composer.json
@@ -52,7 +52,7 @@
"drupal/webform_scheduled_tasks": "^2.0",
"drupal/webform_views": "5.0.0-alpha7",
"drupal/workflow_participants": "^2.4",
- "vlucas/phpdotenv": "^2.4",
+ "vlucas/phpdotenv": "^4.0",
"webmozart/path-util": "2.3.0",
"zaporylie/composer-drupal-optimizations": "1.2.0"
},
diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module
index 274893c..9cf05ed 100644
--- a/os2forms_forloeb.module
+++ b/os2forms_forloeb.module
@@ -94,7 +94,7 @@ function os2forms_forloeb_workflow_maestro_reassign_form_submit(&$form, &$form_s
MaestroEngine::setProcessVariable("assigned_to", $reviewer_username, $processID);
//Provide some feedback
- drupal_set_message("Content Reassigned");
+ \Drupal::messenger()->addStatus("Content Reassigned");
}
diff --git a/src/Plugin/EngineTasks/MaestroSelectContentTask.php b/src/Plugin/EngineTasks/MaestroSelectContentTask.php
index 6d9030b..74b597e 100644
--- a/src/Plugin/EngineTasks/MaestroSelectContentTask.php
+++ b/src/Plugin/EngineTasks/MaestroSelectContentTask.php
@@ -2,6 +2,7 @@
namespace Drupal\os2forms_forloeb\Plugin\EngineTasks;
+use Drupal\node\Entity\Node;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Plugin\PluginBase;
@@ -11,15 +12,16 @@
use Drupal\maestro\Engine\MaestroEngine;
use Drupal\Core\Routing\TrustedRedirectResponse;
-
/**
* Maestro Select a Content Item.
*
* The plugin annotations below should include:
- * id: The task type ID for this task. For Maestro tasks, this is Maestro[TaskType].
+ * id: The task type ID for this task.
+ * For Maestro tasks, this is Maestro[TaskType].
* So for example, the start task shipped by Maestro is MaestroStart.
* The Maestro End task has an id of MaestroEnd
- * Those task IDs are what's used in the engine when a task is injected into the queue
+ * Those task IDs are what's used in the engine when
+ * a task is injected into the queue.
*
* @Plugin(
* id = "MaestroSelectContent",
@@ -28,382 +30,385 @@
*/
class MaestroSelectContentTask extends PluginBase implements MaestroEngineTaskInterface {
- use MaestroTaskTrait;
+ use MaestroTaskTrait;
- function __construct($configuration = NULL) {
- if(is_array($configuration)) {
- $this->processID = $configuration[0];
- $this->queueID = $configuration[1];
- }
+ /**
+ * {@inheritDoc}
+ */
+ public function __construct($configuration = NULL) {
+ if (is_array($configuration)) {
+ $this->processID = $configuration[0];
+ $this->queueID = $configuration[1];
}
-
- /**
- * {@inheritDoc}
- */
- public function isInteractive() {
- return TRUE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function isInteractive() {
+ return TRUE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function shortDescription() {
+ return t('Create or Select a Content Item');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function description() {
+ return $this->t('Create or Select a Content Item');
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see \Drupal\Component\Plugin\PluginBase::getPluginId()
+ */
+ public function getPluginId() {
+ return 'MaestroSelectContent';
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getTaskColours() {
+ return '#e2743c';
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getTaskEditForm(array $task, $templateMachineName) {
+ $form = [
+ '#markup' => t('Select a Content Item.'),
+ ];
+
+ $content_type_options = [
+ 'all' => t('All Content Types'),
+ ];
+ $content_types_objs = $types = \Drupal::entityTypeManager()
+ ->getStorage('node_type')
+ ->loadMultiple();
+ foreach ($content_types_objs as $content_type_machine_name => $content_type) {
+ $content_type_options[$content_type_machine_name] = $content_type_machine_name;
}
- /**
- * {@inheritDoc}
- */
- public function shortDescription() {
- return t('Create or Select a Content Item');
+ $form['content_type'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Select the Content Type'),
+ '#description' => $this->t('Limit the content that can be selected to this content type.'),
+ '#required' => TRUE,
+ '#options' => $content_type_options,
+ ];
+ if (isset($task['data']['content_type'])) {
+ $form['content_type']['#default_value'] = $task['data']['content_type'];
}
- /**
- * {@inheritDoc}
- */
- public function description() {
- return $this->t('Create or Select a Content Item');
+ $form['unique_id'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Give this piece of content a unique identifier'),
+ '#description' => $this->t('This identifier is stored along with its ID to allow you to recall it when filled in.'),
+ '#default_value' => isset($task['data']['unique_id']) ? $task['data']['unique_id'] : '',
+ '#required' => TRUE,
+ ];
+
+ $form['redirect_to'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Return Path'),
+ '#description' => $this->t('You can specify where your return path should go upon task completion.'),
+ '#default_value' => isset($task['data']['redirect_to']) ? $task['data']['redirect_to'] : '/taskconsole',
+ '#required' => TRUE,
+ ];
+
+ $form['modal'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Task presentation'),
+ '#description' => $this->t('Should this task be shown as a modal or full screen task.'),
+ '#default_value' => isset($task['data']['modal']) ? $task['data']['modal'] : 'notmodal',
+ '#options' => [
+ 'modal' => $this->t('Modal'),
+ 'notmodal' => $this->t('Full Page'),
+ ],
+ '#required' => TRUE,
+ ];
+ return $form;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function validateTaskEditForm(array &$form, FormStateInterface $form_state) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function prepareTaskForSave(array &$form, FormStateInterface $form_state, array &$task) {
+
+ $task['data']['modal'] = $form_state->getValue('modal');
+ $redirect = $form_state->getValue('redirect_to');
+ if (isset($redirect)) {
+ $task['data']['redirect_to'] = $redirect;
}
-
- /**
- *
- * {@inheritDoc}
- * @see \Drupal\Component\Plugin\PluginBase::getPluginId()
- */
- public function getPluginId() {
- return 'MaestroSelectContent';
+ else {
+ $task['data']['redirect_to'] = '';
}
- /**
- * {@inheritDoc}
- */
- public function getTaskColours() {
- return '#e2743c';
+ $content_type = $form_state->getValue('content_type');
+ if (isset($content_type)) {
+ $task['data']['content_type'] = $content_type;
}
-
-
-
- /**
- * {@inheritDoc}
- */
- public function getTaskEditForm(array $task, $templateMachineName) {
- $form = array(
- '#markup' => t('Select a Content Item.'),
- );
-
- $content_type_options = array(
- 'all' => t('All Content Types'),
- );
- $content_types_objs = $types = \Drupal::entityTypeManager()
- ->getStorage('node_type')
- ->loadMultiple();
- foreach($content_types_objs as $content_type_machine_name => $content_type) {
- $content_type_options[$content_type_machine_name] = $content_type_machine_name;
- }
-
- $form['content_type'] = array(
- '#type' => 'select',
- '#title' => $this->t('Select the Content Type'),
- '#description' => $this->t('Limit the content that can be selected to this content type.'),
- '#required' => TRUE,
- '#options' => $content_type_options,
- );
- if(isset($task['data']['content_type'])) {
- $form['content_type']['#default_value'] = $task['data']['content_type'];
- }
-
- $form['unique_id'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Give this piece of content a unique identifier'),
- '#description' => $this->t('This identifier is stored along with its ID to allow you to recall it when filled in.'),
- '#default_value' => isset($task['data']['unique_id']) ? $task['data']['unique_id'] : '',
- '#required' => TRUE,
- ];
-
- $form['redirect_to'] = array(
- '#type' => 'textfield',
- '#title' => $this->t('Return Path'),
- '#description' => $this->t('You can specify where your return path should go upon task completion.'),
- '#default_value' => isset($task['data']['redirect_to']) ? $task['data']['redirect_to'] : '/taskconsole',
- '#required' => TRUE,
- );
-
- $form['modal'] = array(
- '#type' => 'select',
- '#title' => $this->t('Task presentation'),
- '#description' => $this->t('Should this task be shown as a modal or full screen task.'),
- '#default_value' => isset($task['data']['modal']) ? $task['data']['modal'] : 'notmodal',
- '#options' => array(
- 'modal' => $this->t('Modal'),
- 'notmodal' => $this->t('Full Page'),
- ),
- '#required' => TRUE,
- );
- return $form;
+ else {
+ $task['data']['content_type'] = '';
}
+ $task['data']['unique_id'] = $form_state->getValue('unique_id');
+
+ }
+
+ /**
+ * Part of the ExecutableInterface.
+ *
+ * Execution of the interactive task does nothing except for
+ * setting the run_once flag.
+ */
+ public function execute() {
+ // Need to set the run_once flag here
+ // as interactive tasks are executed
+ // and completed by the user using the Maestro API.
+ $queueRecord = \Drupal::entityTypeManager()->getStorage('maestro_queue')->load($this->queueID);
+ $queueRecord->set('run_once', 1);
+ $queueRecord->save();
+
+ return TRUE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) {
+ $form['forloebsside'] = [
+ '#id' => 'forloebsside',
+ '#type' => 'radios',
+ '#options' => [
+ 0 => t('Choose an Existing Forløbsside'),
+ 1 => t('Create a New Forløbsside'),
+ ],
+ '#default_value' => 0,
+ '#title' => t('Create or Select a Forløbsside'),
+ '#required' => TRUE,
+ ];
+
+ // Query for all Forløbssider.
+ $forloebssider = [];
+ $nids = \Drupal::entityQuery('node')
+ ->condition('type', 'forloebsside')
+ ->execute();
+ $forloebsside_nodes = Node::loadMultiple($nids);
+ foreach ($forloebsside_nodes as $nid => $forloebsside_node) {
+ $forloebssider[$nid] = $forloebsside_node->getTitle();
+ }
- /**
- * {@inheritDoc}
- */
- public function validateTaskEditForm(array &$form, FormStateInterface $form_state) {
-
+ $form['existing_forloebsside'] = [
+ '#id' => 'existing_forloebsside',
+ '#type' => 'select',
+ '#options' => $forloebssider,
+ '#title' => t('Choose an Existing Forløbsside'),
+ '#validated' => TRUE,
+ '#prefix' => '
',
+ '#suffix' => '
',
+ '#states' => [
+ 'invisible' => [
+ ':input[name="new_forloebsside"]' => ['value' => 1],
+ ],
+ 'required' => [
+ ':input[name="new_forloebsside"]' => ['value' => 0],
+ ],
+ ],
+ ];
+
+ $form['queueID'] = [
+ '#type' => 'hidden',
+ '#title' => 'the queue ID in the event we need it in later processing',
+ '#default_value' => $this->queueID,
+ '#description' => ('queueID'),
+ ];
+
+ // Add all of the entity form's fields into a fieldset
+ // create a fieldset to hold all the entity form fields.
+ // @todo Rather than simply hiding the entity_form it should be loaded and
+ // unloaded via JS. Currently required fields in the entity form, can cause
+ // this form to not validate, even when the new entity option is not
+ // selected and the entity_form is hidden.
+ $form['entity_form'] = [
+ '#type' => 'fieldset',
+ '#title' => 'Create a Forløbsside',
+ '#states' => [
+ 'invisible' => [
+ ':input[name="new_forloebsside"]' => ['value' => 0],
+ ],
+ 'required' => [
+ ':input[name="new_forloebsside"]' => ['value' => 1],
+ ],
+ ],
+ ];
+
+ // Create a form_state for this step.
+ $form_state = new FormState();
+
+ // Specify a #parents key on our form definition
+ // because that is something the widgets themselves expect.
+ $form['#parents'] = [];
+
+ // Load an entity and store on the form state.
+ $new_forloebsside = \Drupal::entityTypeManager()->getStorage('node')->create([
+ 'type' => 'forloebsside',
+ ]);
+ $form_state->set('entity', $new_forloebsside);
+
+ // Load the form display.
+ $forloebsside_form_display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load('node.forloebsside.default');
+ $form_state->set('form_display', $forloebsside_form_display);
+ // Loop over the form display and add fields to the maestro form.
+ foreach ($forloebsside_form_display->getComponents() as $name => $component) {
+ // Load the component's configured widget.
+ $widget = $forloebsside_form_display->getRenderer($name);
+ $items = $new_forloebsside->get($name);
+ $form['entity_form'][$name] = $widget->form($items, $form, $form_state);
+ $form['entity_form'][$name]['#weight'] = $component['weight'];
+ // Make the title field required.
+ if ($name == "title") {
+ $form['entity_form'][$name]['#required'] = FALSE;
+ $form['entity_form'][$name]['widget']['#required'] = FALSE;
+ $form['entity_form'][$name]['widget'][0]['#required'] = FALSE;
+ $form['entity_form'][$name]['widget'][0]['value']['#required'] = FALSE;
+ $form['entity_form'][$name]['#states'] = [
+ 'required' => [
+ ':input[name="new_lineup"]' => ['value' => 1],
+ ],
+ ];
+ }
}
- /**
- * {@inheritDoc}
- */
- public function prepareTaskForSave(array &$form, FormStateInterface $form_state, array &$task) {
-
- $task['data']['modal'] = $form_state->getValue('modal');
- $redirect = $form_state->getValue('redirect_to');
- if(isset($redirect)) {
- $task['data']['redirect_to'] = $redirect;
- }
- else {
- $task['data']['redirect_to'] = '';
- }
-
- $content_type = $form_state->getValue('content_type');
- if(isset($content_type)) {
- $task['data']['content_type'] = $content_type;
- }
- else {
- $task['data']['content_type'] = '';
- }
-
- $task['data']['unique_id'] = $form_state->getValue('unique_id');
+ $form['actions']['submit'] = [
+ '#type' => 'submit',
+ '#value' => $this->t('Go'),
+ '#weight' => 1000,
+ ];
- }
+ // If this is a modal task, we use the ajax completion routines
+ // and tell the buttons to use our built in completeForm modal closer.
+ if ($modal == 'modal') {
+ $form['actions']['submit']['#ajax'] = [
+ 'callback' => [$parent, 'completeForm'],
+ 'wrapper' => '',
+ ];
- /*
- * Part of the ExecutableInterface
- * Execution of the interactive task does nothing except for setting the run_once flag
- * {@inheritdoc}
- */
- public function execute() {
- //need to set the run_once flag here
- //as interactive tasks are executed and completed by the user using the Maestro API
- $queueRecord = \Drupal::entityTypeManager()->getStorage('maestro_queue')->load($this->queueID);
- $queueRecord->set('run_once', 1);
- $queueRecord->save();
-
- return TRUE;
}
-
- /**
- * {@inheritDoc}
- */
- public function getExecutableForm($modal, MaestroExecuteInteractive $parent) {
- $form['forloebsside'] = array(
- '#id' => 'forloebsside',
- '#type' => 'radios',
- '#options' => array (
- 0 => t('Choose an Existing Forløbsside'),
- 1 => t('Create a New Forløbsside'),
- ),
- '#default_value' => 0,
- '#title' => t('Create or Select a Forløbsside'),
- '#required' => true,
- );
-
- //query for all Forløbssider.
- $forloebssider = array();
- $nids = \Drupal::entityQuery('node')
- ->condition('type','forloebsside')
- ->execute();
- $forloebsside_nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
- foreach($forloebsside_nodes as $nid => $forloebsside_node) {
- $forloebssider[$nid] = $forloebsside_node->getTitle();
- }
-
- $form['existing_forloebsside'] = array(
- '#id' => 'existing_forloebsside',
- '#type' => 'select',
- '#options' => $forloebssider,
- '#title' => t('Choose an Existing Forløbsside'),
- '#validated' => TRUE,
- '#prefix' => '',
- '#suffix' => '
',
- '#states' => array(
- 'invisible' => array(
- ':input[name="new_forloebsside"]' => array('value' => 1),
- ),
- 'required' => array(
- ':input[name="new_forloebsside"]' => array('value' => 0),
- ),
- ),
- );
-
- $form['queueID'] = array(
- '#type' => 'hidden',
- '#title' => 'the queue ID in the event we need it in later processing',
- '#default_value' => $this->queueID,
- '#description' => ('queueID'),
- );
-
- //add all of the entity form's fields into a fieldset
- //create a fieldset to hold all the entity form fields
- #ToDo Rather than simply hiding the entity_form it should be loaded and
- # unloaded via JS. Currently required fields in the entity form, can cause
- # this form to not validate, even when the new entity option is not selected
- # and the entity_form is hidden.
- $form['entity_form'] = array(
- '#type'=>'fieldset',
- '#title'=>'Create a Forløbsside',
- '#states' => array(
- 'invisible' => array(
- ':input[name="new_forloebsside"]' => array('value' => 0),
- ),
- 'required' => array(
- ':input[name="new_forloebsside"]' => array('value' => 1),
- ),
- ),
- );
-
- //create a form_state for this step.
- $form_state = new FormState();
-
- //specify a #parents key on our form definition because that is something the widgets themselves expect.
- $form['#parents'] = [];
-
- //load an entity and store on the form state.
+ return $form;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function handleExecuteSubmit(array &$form, FormStateInterface $form_state) {
+
+ $queueID = intval($form_state->getValue('maestro_queue_id'));
+ $triggeringElement = $form_state->getTriggeringElement();
+ $processID = MaestroEngine::getProcessIdFromQueueId($queueID);
+
+ if (strstr($triggeringElement['#id'], 'edit-submit') !== FALSE && $queueID > 0) {
+ // If existing forløbsside is chosen simply assign it to this process
+ // If a new artivle is chosen create that forløbsside
+ // and assign it to this process.
+ if ($form_state->getValue('new_forloebsside')) {
+ // Create the new forloebsside entity.
$new_forloebsside = \Drupal::entityTypeManager()->getStorage('node')->create([
- 'type' => 'forloebsside'
+ 'type' => 'forloebsside',
]);
- $form_state->set('entity', $new_forloebsside);
-
- //Load the form display
+ // Load te form display.
$forloebsside_form_display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load('node.forloebsside.default');
- $form_state->set('form_display', $forloebsside_form_display);
- //Loop over the form display and add fields to the maestro form
- foreach ($forloebsside_form_display->getComponents() as $name => $component) {
- //Load the component's configured widget
- $widget = $forloebsside_form_display->getRenderer($name);
- $items = $new_forloebsside->get($name);
- $form['entity_form'][$name] = $widget->form($items, $form, $form_state);
- $form['entity_form'][$name]['#weight'] = $component['weight'];
- //make the title field required.
- if($name == "title"){
- $form['entity_form'][$name]['#required'] = false;
- $form['entity_form'][$name]['widget']['#required'] = false;
- $form['entity_form'][$name]['widget'][0]['#required'] = false;
- $form['entity_form'][$name]['widget'][0]['value']['#required'] = false;
- $form['entity_form'][$name]['#states'] = array(
- 'required' => array(
- ':input[name="new_lineup"]' => array('value' => 1),
- ),
- );
- }
- }
-
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => $this->t('Go'),
- '#weight' => 1000
- );
-
- if($modal == 'modal') { //if this is a modal task, we use the ajax completion routines and tell the buttons to use our built in completeForm modal closer
- $form['actions']['submit']['#ajax'] = array(
- 'callback' => [$parent, 'completeForm'],
- 'wrapper' => '',
- );
-
- }
- return $form;
+ // Extract all of the form display's fields that are in the form_state
+ // value and assign to the new forloebsside.
+ $forloebsside_form_display->extractFormValues($new_forloebsside, $form, $form_state);
+ // Save the forloebsside.
+ $new_forloebsside->save();
+ // Assign this forloebsside to the maestro variable.
+ MaestroEngine::setProcessVariable("new_forloebsside", $new_forloebsside->id(), $processID);
+ // Bound this entity to this maestro process.
+ $templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
+ MaestroEngine::createEntityIdentifier($processID, 'node', 'forloebsside', $templateTask['data']['unique_id'], $new_forloebsside->id());
+ // Complete this task.
+ MaestroEngine::completeTask($queueID, \Drupal::currentUser()->id());
+ }
+ else {
+ $forloebsside_nid = $form_state->getValue('existing_forloebsside');
+ MaestroEngine::setProcessVariable("new_forloebsside", $forloebsside_nid, $processID);
+ // Bound this entity to this maestro process.
+ $templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
+ MaestroEngine::createEntityIdentifier($processID, 'node', 'forloebsside', $templateTask['data']['unique_id'], $forloebsside_nid);
+
+ // Complete this task.
+ MaestroEngine::completeTask($queueID, \Drupal::currentUser()->id());
+ }
+ }
+ else {
+ // we'll complete the task, but we'll also flag it as TASK_STATUS_CANCEL.
+ MaestroEngine::completeTask($queueID, \Drupal::currentUser()->id());
+ MaestroEngine::setTaskStatus($queueID, TASK_STATUS_CANCEL);
}
- /**
- * {@inheritDoc}
- */
- public function handleExecuteSubmit(array &$form, FormStateInterface $form_state) {
-
-
- $queueID = intval($form_state->getValue('maestro_queue_id'));
- $triggeringElement = $form_state->getTriggeringElement();
- $processID = MaestroEngine::getProcessIdFromQueueId($queueID);
-
- if(strstr($triggeringElement['#id'], 'edit-submit') !== FALSE && $queueID > 0) {
- /**
- * If existing forløbsside is chosen simply assign it to this process
- *
- * If a new artivle is chosen create that forløbsside and assign it to this process.
- */
- if($form_state->getValue('new_forloebsside')) {
- //Create the new forloebsside entity.
- $new_forloebsside = \Drupal::entityTypeManager()->getStorage('node')->create([
- 'type' => 'forloebsside'
- ]);
- //Load te form display
- $forloebsside_form_display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load('node.forloebsside.default');
- //extract all of the form display's fields that are in the form_state values and assign to the new forloebsside.
- $forloebsside_form_display->extractFormValues($new_forloebsside, $form, $form_state);
- //Save the forloebsside
- $new_forloebsside->save();
- //Assign this forloebsside to the maestro variable.
- MaestroEngine::setProcessVariable("new_forloebsside", $new_forloebsside->id(), $processID);
- //Bound this entity to this maestro process
- $templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
- MaestroEngine::createEntityIdentifier($processID, 'node', 'forloebsside', $templateTask['data']['unique_id'], $new_forloebsside->id());
- //Complete this task.
- MaestroEngine::completeTask($queueID, \Drupal::currentUser()->id());
- }
- else {
- $forloebsside_nid = $form_state->getValue('existing_forloebsside');
- MaestroEngine::setProcessVariable("new_forloebsside", $forloebsside_nid, $processID);
- //Bound this entity to this maestro process
- $templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
- MaestroEngine::createEntityIdentifier($processID, 'node', 'forloebsside', $templateTask['data']['unique_id'], $forloebsside_nid);
-
- //Complete this task.
- MaestroEngine::completeTask($queueID, \Drupal::currentUser()->id());
- }
- }
- else {
- //we'll complete the task, but we'll also flag it as TASK_STATUS_CANCEL
- MaestroEngine::completeTask($queueID, \Drupal::currentUser()->id());
- MaestroEngine::setTaskStatus($queueID, TASK_STATUS_CANCEL);
- }
-
- $task = MaestroEngine::getTemplateTaskByQueueID($queueID);
- if(isset($task['data']['redirect_to'])) {
- $response = new TrustedRedirectResponse($task['data']['redirect_to']);
- $form_state->setResponse($response);
- }
+ $task = MaestroEngine::getTemplateTaskByQueueID($queueID);
+ if (isset($task['data']['redirect_to'])) {
+ $response = new TrustedRedirectResponse($task['data']['redirect_to']);
+ $form_state->setResponse($response);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function performValidityCheck(array &$validation_failure_tasks, array &$validation_information_tasks, array $task) {
+ if ((array_key_exists('modal', $task['data']) && $task['data']['modal'] == '') || !array_key_exists('modal', $task['data'])) {
+ $validation_failure_tasks[] = [
+ 'taskID' => $task['id'],
+ 'taskLabel' => $task['label'],
+ 'reason' => t('The Interactive Task has not been set up properly. The "Task Presentation" option is missing and thus the engine will be unable to execute this task.'),
+ ];
+ }
+ // This task should have assigned users
+ // $task['assigned'] should have data.
+ if ((array_key_exists('assigned', $task) && $task['assigned'] == '') || !array_key_exists('assigned', $task)) {
+ $validation_failure_tasks[] = [
+ 'taskID' => $task['id'],
+ 'taskLabel' => $task['label'],
+ 'reason' => t('The Interactive Task has not been set up properly. The Interactive Task requires assignments to actors, roles or other assignment options.'),
+ ];
}
- /**
- * {@inheritDoc}
- */
- public function performValidityCheck(array &$validation_failure_tasks, array &$validation_information_tasks, array $task) {
- if( (array_key_exists('modal', $task['data']) && $task['data']['modal'] == '') || !array_key_exists('modal', $task['data'])) {
- $validation_failure_tasks[] = array(
- 'taskID' => $task['id'],
- 'taskLabel' => $task['label'],
- 'reason' => t('The Interactive Task has not been set up properly. The "Task Presentation" option is missing and thus the engine will be unable to execute this task.'),
- );
- }
-
- //This task should have assigned users
- //$task['assigned'] should have data
- if( (array_key_exists('assigned', $task) && $task['assigned'] == '') || !array_key_exists('assigned', $task)) {
- $validation_failure_tasks[] = array(
- 'taskID' => $task['id'],
- 'taskLabel' => $task['label'],
- 'reason' => t('The Interactive Task has not been set up properly. The Interactive Task requires assignments to actors, roles or other assignment options.'),
- );
- }
-
- if ((array_key_exists('unique_id', $task['data']) && $task['data']['unique_id'] == '') || !array_key_exists('unique_id', $task['data'])) {
- $validation_failure_tasks[] = [
- 'taskID' => $task['id'],
- 'taskLabel' => $task['label'],
- 'reason' => t('The Content Type Task has not been set up properly. The "unique identifier" option is missing and thus the engine will be unable to execute this task.'),
- ];
- }
+ if ((array_key_exists('unique_id', $task['data']) && $task['data']['unique_id'] == '') || !array_key_exists('unique_id', $task['data'])) {
+ $validation_failure_tasks[] = [
+ 'taskID' => $task['id'],
+ 'taskLabel' => $task['label'],
+ 'reason' => t('The Content Type Task has not been set up properly. The "unique identifier" option is missing and thus the engine will be unable to execute this task.'),
+ ];
}
+ }
- /**
- * {@inheritDoc}
- */
- public function getTemplateBuilderCapabilities() {
+ /**
+ * {@inheritDoc}
+ */
+ public function getTemplateBuilderCapabilities() {
- return array('edit', 'drawlineto', 'removelines', 'remove');
+ return ['edit', 'drawlineto', 'removelines', 'remove'];
- }
+ }
}