abstract class WorkflowConfigTransitionFormBase in Workflow 8
Defines a class to build a draggable listing of Workflow Config Transitions entities.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\workflow\Form\WorkflowConfigTransitionFormBase
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of WorkflowConfigTransitionFormBase
See also
\Drupal\workflow\Entity\WorkflowConfigTransition
1 file declares its use of WorkflowConfigTransitionFormBase
- WorkflowAccessRoleForm.php in modules/
workflow_access/ src/ Form/ WorkflowAccessRoleForm.php
File
- src/
Form/ WorkflowConfigTransitionFormBase.php, line 16
Namespace
Drupal\workflow\FormView source
abstract class WorkflowConfigTransitionFormBase extends ConfigFormBase {
/**
* The key to use for the form element containing the entities.
*
* @var string
*/
protected $entitiesKey = 'entities';
/**
* The WorkflowConfigTransition form type.
*
* @var string
*/
protected $type;
/**
* The entities being listed.
*
* @var \Drupal\Core\Entity\EntityInterface[]
*/
protected $entities = [];
/**
* The workflow object.
*
* @var \Drupal\workflow\Entity\Workflow
*/
protected $workflow;
/**
* The messenger / logger service.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* {@inheritdoc}
*/
public function __construct(ConfigFactoryInterface $config_factory, LoggerInterface $logger) {
// N.B. The $this->type and $this->entitiesKey must be set in the var section.
parent::__construct($config_factory);
$this->logger = $logger;
// Get the Workflow from the page.
$this->workflow = workflow_url_get_workflow();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('logger.factory')
->get('workflow'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'workflow_config_transition_' . $this->type . '_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [];
}
/**
* {@inheritdoc}
*
* Create an $entity for every ConfigTransition.
*/
public function load() {
$entities = [];
$entity_type = $this->entitiesKey;
$workflow = $this->workflow;
$states = $workflow
->getStates($all = 'CREATION');
if ($states) {
/** @var \Drupal\workflow\Entity\WorkflowState $from_state */
/** @var \Drupal\workflow\Entity\WorkflowState $to_state */
switch ($entity_type) {
case 'workflow_state':
foreach ($states as $from_state) {
$from_sid = $from_state
->id();
$entities[$from_sid] = $from_state;
}
break;
case 'workflow_config_transition':
foreach ($states as $from_state) {
$from_sid = $from_state
->id();
foreach ($states as $to_state) {
$to_sid = $to_state
->id();
// Don't allow transition TO (creation).
if ($to_state
->isCreationState()) {
continue;
}
// Only allow transitions from $from_state.
if ($to_sid != $from_sid) {
// continue.
}
// Load existing config_transitions. Create if not found.
$config_transitions = $workflow
->getTransitionsByStateId($from_sid, $to_sid);
if (!($config_transition = reset($config_transitions))) {
$config_transition = $workflow
->createTransition($from_sid, $to_sid);
}
$entities[] = $config_transition;
}
}
break;
default:
$this
->messenger()
->addError($this
->t('Improper type provided in load method.'));
$this->logger
->notice('Improper type provided in load method.', []);
}
}
return $entities;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = [];
if (!$this->workflow) {
return $form;
}
/*
* Begin of copied code DraggableListBuilder::buildForm()
*/
$form[$this->entitiesKey] = [
'#type' => 'table',
'#header' => $this
->buildHeader(),
'#sticky' => TRUE,
'#empty' => $this
->t('There is no @label yet.', [
'@label' => 'Transition',
]),
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'weight',
],
],
];
$this->entities = $this
->load();
$delta = 10;
// Change the delta of the weight field if have more than 20 entities.
if (!empty($this->weightKey)) {
$count = count($this->entities);
if ($count > 20) {
$delta = ceil($count / 2);
}
}
foreach ($this->entities as $entity) {
$row = $this
->buildRow($entity);
if (isset($row['label'])) {
$row['label'] = [
'#markup' => $row['label'],
];
}
if (isset($row['weight'])) {
$row['weight']['#delta'] = $delta;
}
$form[$this->entitiesKey][$entity
->id()] = $row;
}
/*
* End of copied code DraggableListBuilder::buildForm()
*/
$form = parent::buildForm($form, $form_state);
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public | function |
Form submission handler. Overrides FormInterface:: |
26 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
WorkflowConfigTransitionFormBase:: |
protected | property | The entities being listed. | |
WorkflowConfigTransitionFormBase:: |
protected | property | The key to use for the form element containing the entities. | 3 |
WorkflowConfigTransitionFormBase:: |
protected | property | The messenger / logger service. | |
WorkflowConfigTransitionFormBase:: |
protected | property | The WorkflowConfigTransition form type. | 3 |
WorkflowConfigTransitionFormBase:: |
protected | property | The workflow object. | |
WorkflowConfigTransitionFormBase:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
WorkflowConfigTransitionFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
WorkflowConfigTransitionFormBase:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
1 |
WorkflowConfigTransitionFormBase:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
1 |
WorkflowConfigTransitionFormBase:: |
public | function | Create an $entity for every ConfigTransition. | |
WorkflowConfigTransitionFormBase:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |