public function MaestroTemplateBuilderAddNew::buildForm in Maestro 3.x
Same name and namespace in other branches
- 8.2 modules/maestro_template_builder/src/Form/MaestroTemplateBuilderAddNew.php \Drupal\maestro_template_builder\Form\MaestroTemplateBuilderAddNew::buildForm()
Ajax callback for add-new-form button click.
Overrides FormInterface::buildForm
File
- modules/
maestro_template_builder/ src/ Form/ MaestroTemplateBuilderAddNew.php, line 127
Class
- MaestroTemplateBuilderAddNew
- Maestro Template Builder Add New form.
Namespace
Drupal\maestro_template_builder\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $templateMachineName = '') {
$template = MaestroEngine::getTemplate($templateMachineName);
// Need to validate this template to ensure that it exists.
if ($template == NULL) {
$form = [
'#title' => $this
->t('Error!'),
'#markup' => $this
->t("The template you are attempting to add a task to doesn't exist"),
];
return $form;
}
$form = [
'#title' => $this
->t('Add a new task'),
'#markup' => '<div id="maestro-template-error" class="messages messages--error">dddd</div>',
];
$form['#prefix'] = '<div id="template-add-new-form">';
$form['#suffix'] = '</div>';
// Add all the task types here.
$manager = \Drupal::service('plugin.manager.maestro_tasks');
$plugins = $manager
->getDefinitions();
$options = [];
foreach ($plugins as $plugin) {
if ($plugin['id'] != 'MaestroStart') {
$task = $manager
->createInstance($plugin['id'], [
0,
0,
]);
$options[$task
->getPluginId()] = $task
->shortDescription();
}
}
$form['template_machine_name'] = [
'#type' => 'hidden',
'#title' => $this
->t('machine name of the template'),
'#default_value' => $templateMachineName,
'#required' => TRUE,
];
$form['task_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('The Label for the new task'),
'#required' => TRUE,
];
$form['task_machine_name'] = [
'#type' => 'machine_name',
'#title' => $this
->t('A unique name for this task'),
'#machine_name' => [
'exists' => [
get_class($this),
'exists',
],
],
];
$form['choose_task'] = [
'#type' => 'radios',
'#options' => $options,
'#title' => $this
->t('Which task would you like to create?'),
'#required' => TRUE,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['create'] = [
'#type' => 'submit',
'#value' => $this
->t('Create Task'),
'#required' => TRUE,
'#submit' => [],
'#ajax' => [
'callback' => '::submitForm',
'event' => 'click',
],
];
$form['actions']['cancel'] = [
'#type' => 'button',
'#value' => $this
->t('Cancel'),
'#required' => TRUE,
'#ajax' => [
'callback' => [
$this,
'cancelForm',
],
'wrapper' => '',
],
];
return $form;
}