function WorkspacesHtmlEntityFormController::getContentResult
Same name and namespace in other branches
- 10 core/modules/workspaces/src/Controller/WorkspacesHtmlEntityFormController.php \Drupal\workspaces\Controller\WorkspacesHtmlEntityFormController::getContentResult()
Invokes the form and returns the result.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
Return value
array The render array that results from invoking the controller.
Overrides FormController::getContentResult
File
-
core/
modules/ workspaces/ src/ Controller/ WorkspacesHtmlEntityFormController.php, line 36
Class
- WorkspacesHtmlEntityFormController
- Overrides the entity form controller service for workspaces operations.
Namespace
Drupal\workspaces\ControllerCode
public function getContentResult(Request $request, RouteMatchInterface $route_match) : array {
$form_arg = $this->getFormArgument($route_match);
// If no operation is provided, use 'default'.
$form_arg .= '.default';
[
$entity_type_id,
$operation,
] = explode('.', $form_arg);
if ($route_match->getRawParameter($entity_type_id) !== NULL) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $route_match->getParameter($entity_type_id);
}
if (isset($entity) && $this->workspaceInfo
->isEntitySupported($entity)) {
$active_workspace = $this->workspaceManager
->getActiveWorkspace();
// Prepare a minimal render array in case we need to return it.
$build['#cache']['contexts'] = $entity->getCacheContexts();
$build['#cache']['tags'] = $entity->getCacheTags();
$build['#cache']['max-age'] = $entity->getCacheMaxAge();
// Prevent entities from being edited if they're tracked in workspace.
if ($operation !== 'delete') {
$constraints = array_values(array_filter($entity->getTypedData()
->getConstraints(), function ($constraint) {
return $constraint instanceof EntityWorkspaceConflictConstraint;
}));
if (!empty($constraints)) {
$violations = $this->typedDataManager
->getValidator()
->validate($entity->getTypedData(), $constraints[0]);
if (count($violations)) {
$build['#markup'] = $violations->get(0)
->getMessage();
return $build;
}
}
}
// Prevent entities from being deleted in a workspace if they have a
// published default revision.
if ($operation === 'delete' && $active_workspace && !$this->workspaceInfo
->isEntityDeletable($entity, $active_workspace)) {
$build['#markup'] = $this->t('This @entity_type_label can only be deleted in the Live workspace.', [
'@entity_type_label' => $entity->getEntityType()
->getSingularLabel(),
]);
return $build;
}
}
return $this->entityFormController
->getContentResult($request, $route_match);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.