function WorkflowStateEditForm::form
Same name in other branches
- 8.9.x core/modules/workflows/src/Form/WorkflowStateEditForm.php \Drupal\workflows\Form\WorkflowStateEditForm::form()
- 10 core/modules/workflows/src/Form/WorkflowStateEditForm.php \Drupal\workflows\Form\WorkflowStateEditForm::form()
- 11.x core/modules/workflows/src/Form/WorkflowStateEditForm.php \Drupal\workflows\Form\WorkflowStateEditForm::form()
Overrides EntityForm::form
File
-
core/
modules/ workflows/ src/ Form/ WorkflowStateEditForm.php, line 72
Class
- WorkflowStateEditForm
- Entity form variant for editing workflow states.
Namespace
Drupal\workflows\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->getEntity();
$workflow_type = $workflow->getTypePlugin();
$state = $workflow->getTypePlugin()
->getState($this->stateId);
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('State label'),
'#maxlength' => 255,
'#default_value' => $state->label(),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $this->stateId,
'#machine_name' => [
'exists' => [
$this,
'exists',
],
],
'#disabled' => TRUE,
];
// Add additional form fields from the workflow type plugin.
if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
$form['type_settings'] = [
'#tree' => TRUE,
];
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$subform_state->set('state', $state);
$form['type_settings'] += $this->pluginFormFactory
->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
->buildConfigurationForm($form['type_settings'], $subform_state);
}
$header = [
'label' => $this->t('Transition'),
'state' => $this->t('To'),
'operations' => $this->t('Operations'),
];
$form['transitions'] = [
'#type' => 'table',
'#header' => $header,
'#empty' => $this->t('There are no transitions to or from this state yet.'),
];
foreach ($state->getTransitions() as $transition) {
$links['edit'] = [
'title' => $this->t('Edit'),
'url' => Url::fromRoute('entity.workflow.edit_transition_form', [
'workflow' => $workflow->id(),
'workflow_transition' => $transition->id(),
]),
];
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('entity.workflow.delete_transition_form', [
'workflow' => $workflow->id(),
'workflow_transition' => $transition->id(),
]),
];
$form['transitions'][$transition->id()] = [
'label' => [
'#markup' => $transition->label(),
],
'state' => [
'#markup' => $transition->to()
->label(),
],
'operations' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.