class MaestroNonInteractiveExampleTask in Maestro 3.x
Same name and namespace in other branches
- 8.2 modules/examples/maestro_noninteractive_task_plugin_example/src/Plugin/EngineTasks/MaestroNonInteractiveExampleTask.php \Drupal\maestro_noninteractive_task_plugin_example\Plugin\EngineTasks\MaestroNonInteractiveExampleTask
Maestro Non Interactive Example Task Plugin.
The plugin annotations below should include: 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.
Plugin annotation
@Plugin(
id = "MaestroNonIntExample",
task_description = @Translation("The Maestro Engine's Non Interactive Example task."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\maestro_noninteractive_task_plugin_example\Plugin\EngineTasks\MaestroNonInteractiveExampleTask implements MaestroEngineTaskInterface uses MaestroTaskTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MaestroNonInteractiveExampleTask
File
- modules/
examples/ maestro_noninteractive_task_plugin_example/ src/ Plugin/ EngineTasks/ MaestroNonInteractiveExampleTask.php, line 25
Namespace
Drupal\maestro_noninteractive_task_plugin_example\Plugin\EngineTasksView source
class MaestroNonInteractiveExampleTask extends PluginBase implements MaestroEngineTaskInterface {
// Please see the \Drupal\maestro\MaestroTaskTrait for details on what's included.
use MaestroTaskTrait;
/**
* Constructor.
*
* @param array $configuration
* The incoming configuration information from the engine execution.
* [0] - is the process ID
* [1] - is the queue ID
* The processID and queueID properties are defined in the MaestroTaskTrait.
*/
public function __construct(array $configuration = NULL) {
if (is_array($configuration)) {
$this->processID = $configuration[0];
$this->queueID = $configuration[1];
}
}
/**
* {@inheritDoc}
*/
public function isInteractive() {
/*
* You would return a TRUE here if this task required manual human intervention to complete.
* This only applies to a task that must present options to the end user for completion in a task console.
* For this example, we return FALSE.
*
* See the MaestroInteractiveTask type code for how to return an interactive task.
*/
return FALSE;
}
/**
* {@inheritDoc}
*/
public function shortDescription() {
// Descriptions used however the template builder sees fit.
return $this
->t('Non-Int Example Task');
// If the task name is too long, you could abbreviate it here and use
// in a template builder UI.
}
/**
* {@inheritDoc}
*/
public function description() {
// Same as shortDescription, but just longer! (if need be obviously)
return $this
->t('Non Interactive Example Task.');
}
/**
* {@inheritDoc}
*
* @see \Drupal\Component\Plugin\PluginBase::getPluginId()
*/
public function getPluginId() {
// The ID of the plugin. Should match the @id shown in the annotation.
return 'MaestroNonIntExample';
}
/**
* {@inheritDoc}
*/
public function getTaskColours() {
// This is the hex colour code used in the template builder to differentiate tasks from one another.
return '#606060';
// The colour chosen here is purely for example purposes.
}
/**
* Part of the ExecutableInterface
* Execution of the Example task returns TRUE and does nothing else.
* {@inheritdoc}.
*/
public function execute() {
/*
* You can refer to other Maestro task types, however, in this execute method you must do any of the heavy
* lifting required by the task to complete.
*
* Returning TRUE tells the engine you've completed execution properly and the task is complete.
* Return a FALSE to not tell the engine to archive and flag the task as complete.
*/
return TRUE;
}
/**
* {@inheritDoc}
*/
public function getExecutableForm($modal, MaestroExecuteInteractive $parent) {
/*
* This task has been set to be a non-interactive task, therefore we do not need to return a form
*/
}
/**
* {@inheritDoc}
*/
public function handleExecuteSubmit(array &$form, FormStateInterface $form_state) {
/*
* We don't need to do anything in this submit handler as we do not have any executable interface.
*/
}
/**
* {@inheritDoc}
*/
public function getTaskEditForm(array $task, $templateMachineName) {
/*
* If you require any additional form elements, you manage those in here.
* Return a Form API array.
*/
return [];
}
/**
* {@inheritDoc}
*/
public function validateTaskEditForm(array &$form, FormStateInterface $form_state) {
/*
* Need to validate anything on your edit form? Do that here.
*/
}
/**
* {@inheritDoc}
*/
public function prepareTaskForSave(array &$form, FormStateInterface $form_state, array &$task) {
/*
* Do you need to massage the edited and saved data in for this task before it is saved to the template?
* This is where you do that. Generally you'd place task data into the 'data' property of the template as shown
* in the example here:
*
* $task['handler'] = $form_state->getValue('handler'); //if you have a handler field, this is how you'd populate the task with it
* $task['data']['my_field'] = ...do some work here....;
*
*/
}
/**
* {@inheritDoc}
*/
public function performValidityCheck(array &$validation_failure_tasks, array &$validation_information_tasks, array $task) {
/*
* When you use a task in the template builder, it will be up to the task to provide any sort of debugging and validation
* information to the end user. Do you have a field that MUST be set in order for the task to execute?
* How about a field that doesn't have the right values? This is where you would populate the
* $validation_failure_tasks array with failure information and the
* $validation_information_tasks with informational messages.
*
* See the MaestroEngineTaskInterface.php interface declaration of this method for details.
*/
}
/**
* {@inheritDoc}
*/
public function getTemplateBuilderCapabilities() {
/*
* This method is used by the template builder to signal to the UI what this task can or cannot do.
* Look at the function declaration for more info and other tasks for what they return.
* Generally, the capabilities listed here are the general four that a task should be able to accomodate.
*/
return [
'edit',
'drawlineto',
'removelines',
'remove',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MaestroNonInteractiveExampleTask:: |
public | function |
Longer description. This generally follows the short Description but can be used to be more descriptive if you
wish to surface this description in a UI element. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Part of the ExecutableInterface
Execution of the Example task returns TRUE and does nothing else.
. Overrides ExecutableInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Gets the Maestro executable form for a task console. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Overrides PluginBase:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Returns the task's defined colours. This is useful if you want to let the tasks decide on what colours to paint themselves in the UI. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Method to allow a task to add their own fields to the task edit form. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Returns an array of consistenly keyed array elements that define what this task can do in the template builder.
Elements are:
edit, drawlineto, drawfalselineto, removelines, remove. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Interactive tasks, or tasks that signal themselves as requiring human interaction will have the resulting form submissions
sent to their own handler for processing to determine if the task should be completed or not or to carry out any task
processing… Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Returns TRUE or FALSE to denote if this task has an interactive interface that needs to be shown in the Task Console
and for any other requirements of the task. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Lets the task perform validation on itself. If the task is missing any internal requirements, it can flag itself as having an issue.
Return array MUST be in the format of array(
'taskID' => the task machine name,
'taskLabel'… Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
The specific task's manipulation of the values to save for a template save. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Get the task's short description. Useful for things like labels. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
This method must be called by the template builder in order to validate the form entry values before saving. Overrides MaestroEngineTaskInterface:: |
|
MaestroNonInteractiveExampleTask:: |
public | function |
Constructor. Overrides PluginBase:: |
|
MaestroTaskTrait:: |
protected | property | Default will be that the task completed normally. | |
MaestroTaskTrait:: |
protected | property | The default will be success for the execution status. | |
MaestroTaskTrait:: |
protected | property | The Maestro Process ID. | |
MaestroTaskTrait:: |
protected | property | The Maestro queue ID. | |
MaestroTaskTrait:: |
public | function | Retrieve the core Maestro form edit elements for Assignments and Notifications. | |
MaestroTaskTrait:: |
public | function | Retrieve the core Maestro form edit elements that all tasks MUST adhere to. | |
MaestroTaskTrait:: |
public | function | Returns the value of the completion status protected variable denoting any special completion status condition the task wishes to pass along. | |
MaestroTaskTrait:: |
public | function | Returns the value of the execution status protected variable denoting if the execution of this task is complete. | |
MaestroTaskTrait:: |
public | function | Available for all tasks -- this does the general task construction for us, ensuring we have sanity in the saved Config Entity for the task. Assignments and Notifications are the two main elements this method worries about. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |