View source
<?php
namespace Drupal\maestro\Plugin\EngineTasks;
use Drupal\Core\Plugin\PluginBase;
use Drupal\maestro\MaestroEngineTaskInterface;
use Drupal\maestro\MaestroTaskTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\maestro\Form\MaestroExecuteInteractive;
class MaestroManualWebTask extends PluginBase implements MaestroEngineTaskInterface {
use MaestroTaskTrait;
public function __construct($configuration = NULL) {
if (is_array($configuration)) {
$this->processID = $configuration[0];
$this->queueID = $configuration[1];
}
}
public function isInteractive() {
return TRUE;
}
public function shortDescription() {
return t('Manual Web Task');
}
public function description() {
return $this
->t('Manual Web Task.');
}
public function getPluginId() {
return 'MaestroManualWeb';
}
public function getTaskColours() {
return '#0000ff';
}
public function execute() {
$queueRecord = \Drupal::entityTypeManager()
->getStorage('maestro_queue')
->load($this->queueID);
$queueRecord
->set('run_once', 1);
$queueRecord
->save();
return FALSE;
}
public function getExecutableForm($modal, MaestroExecuteInteractive $parent) {
}
public function handleExecuteSubmit(array &$form, FormStateInterface $form_state) {
}
public function getTaskEditForm(array $task, $templateMachineName) {
$form = [
'#markup' => t('Interactive Task Edit'),
];
$form['handler'] = [
'#type' => 'textfield',
'#title' => $this
->t('Handler'),
'#description' => $this
->t('The web location for this task to be sent to. This can be an external site prefixed with http:// or internal link.'),
'#default_value' => $task['handler'],
'#required' => TRUE,
];
$form['modal'] = [
'#type' => 'hidden',
'#default_value' => 'notmodal',
'#value' => 'notmodal',
'#required' => TRUE,
];
return $form;
}
public function validateTaskEditForm(array &$form, FormStateInterface $form_state) {
}
public function prepareTaskForSave(array &$form, FormStateInterface $form_state, array &$task) {
$task['handler'] = $form_state
->getValue('handler');
$task['data']['modal'] = $form_state
->getValue('modal');
}
public function performValidityCheck(array &$validation_failure_tasks, array &$validation_information_tasks, array $task) {
if (array_key_exists('handler', $task) && $task['handler'] == '' || !array_key_exists('handler', $task)) {
$validation_failure_tasks[] = [
'taskID' => $task['id'],
'taskLabel' => $task['label'],
'reason' => t('The Manual Web Task has not been set up properly. The handler is missing and thus the engine will be unable to execute this 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 Manual Web Task has not been set up properly. The modal option is missing.
This is a critical error with the task that you are unable to fix with the UI.
Please try to remove the task and add it back into your workflow.'),
];
}
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 Manual Web Task has not been set up properly. The Manual Web Task requires assignments to actors, roles or other assignment options.'),
];
}
}
public function getTemplateBuilderCapabilities() {
return [
'edit',
'drawlineto',
'removelines',
'remove',
];
}
}