function workflow_url_get_entity in Workflow 8
Helper function to get the entity from a route.
This is a hack. It should be solved by using $route_match.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: An optional entity.
\Drupal\Core\Routing\RouteMatchInterface $route_match: A route.
Return value
\Drupal\Core\Entity\EntityInterface Entity from the route.
4 calls to workflow_url_get_entity()
- WorkflowHistoryAccess::access in src/
Access/ WorkflowHistoryAccess.php - Check if the user has permissions to view this workflow.
- WorkflowTransitionBlock::blockAccess in src/
Plugin/ Block/ WorkflowTransitionBlock.php - Indicates whether the block should be shown.
- WorkflowTransitionBlock::build in src/
Plugin/ Block/ WorkflowTransitionBlock.php - Builds and returns the renderable array for this block plugin.
- WorkflowTransitionListController::historyOverview in src/
Controller/ WorkflowTransitionListController.php - Shows a list of an entity's state transitions, but only if WorkflowHistoryAccess::access() allows it.
File
- ./
workflow.module, line 659 - Support workflows made up of arbitrary states.
Code
function workflow_url_get_entity(EntityInterface $entity = NULL, RouteMatchInterface $route_match = NULL) {
if ($entity) {
return $entity;
}
if (!$route_match) {
$route_match = \Drupal::routeMatch();
}
$entities = [];
foreach ($route_match
->getParameters() as $param) {
if ($param instanceof EntityInterface) {
$entities[] = $param;
}
}
$value = reset($entities);
if ($value && is_object($value)) {
return $value;
}
if ($value && !is_object($value)) {
// On workflow tab, we'd get an id.
// This is an indicator that the route is mal-configured.
workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'route declaration is not optimal.');
/* Return $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value); */
return NULL;
}
return $value;
}