protected function State::getWorkflows in State Machine 8
Gets the workflows used the current entity field.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The current entity type.
string $field_name: The current field name.
Return value
\Drupal\state_machine\Plugin\Workflow\WorkflowInterface[] The workflows.
1 call to State::getWorkflows()
- State::getValueOptions in src/
Plugin/ views/ filter/ State.php - Child classes should be used to override this function and set the 'value options', unless 'options callback' is defined as a valid function or static public method to generate these values.
File
- src/
Plugin/ views/ filter/ State.php, line 131
Class
- State
- Filter by workflow state.
Namespace
Drupal\state_machine\Plugin\views\filterCode
protected function getWorkflows(EntityTypeInterface $entity_type, $field_name) {
// Only the StateItem knows which workflow it's using. This requires us
// to create an entity for each bundle in order to get the state field.
$storage = $this->entityTypeManager
->getStorage($entity_type
->id());
$bundles = $this
->getBundles($entity_type, $field_name);
$workflows = [];
foreach ($bundles as $bundle) {
$values = [];
if ($bundle_key = $entity_type
->getKey('bundle')) {
$values[$bundle_key] = $bundle;
}
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $storage
->create($values);
if ($entity
->hasField($field_name)) {
$workflow = $entity
->get($field_name)
->first()
->getWorkflow();
$workflows[$workflow
->getId()] = $workflow;
}
}
return $workflows;
}