class WorkspacesHtmlEntityFormController
Same name in other branches
- 11.x core/modules/workspaces/src/Controller/WorkspacesHtmlEntityFormController.php \Drupal\workspaces\Controller\WorkspacesHtmlEntityFormController
Overrides the entity form controller service for workspaces operations.
Hierarchy
- class \Drupal\Core\Controller\FormController uses \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\workspaces\Controller\WorkspacesHtmlEntityFormController extends \Drupal\Core\Controller\FormController uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of WorkspacesHtmlEntityFormController
1 string reference to 'WorkspacesHtmlEntityFormController'
- workspaces.services.yml in core/
modules/ workspaces/ workspaces.services.yml - core/modules/workspaces/workspaces.services.yml
1 service uses WorkspacesHtmlEntityFormController
File
-
core/
modules/ workspaces/ src/ Controller/ WorkspacesHtmlEntityFormController.php, line 21
Namespace
Drupal\workspaces\ControllerView source
class WorkspacesHtmlEntityFormController extends FormController {
use DependencySerializationTrait;
use StringTranslationTrait;
public function __construct(FormController $entityFormController, WorkspaceManagerInterface $workspaceManager, WorkspaceInformationInterface $workspaceInfo, TypedDataManagerInterface $typedDataManager) {
}
/**
* {@inheritdoc}
*/
public function getContentResult(Request $request, RouteMatchInterface $route_match) : array {
$form_arg = $this->getFormArgument($route_match);
$form_object = $this->getFormObject($route_match, $form_arg);
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $form_object->getEntity();
if ($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 ($form_object->getOperation() !== '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 ($form_object->getOperation() === '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);
}
/**
* {@inheritdoc}
*/
protected function getFormArgument(RouteMatchInterface $route_match) : string {
return $this->entityFormController
->getFormArgument($route_match);
}
/**
* {@inheritdoc}
*/
protected function getFormObject(RouteMatchInterface $route_match, $form_arg) : FormInterface {
return $this->entityFormController
->getFormObject($route_match, $form_arg);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DependencySerializationTrait::$_entityStorages | protected | property | |||
DependencySerializationTrait::$_serviceIds | protected | property | |||
DependencySerializationTrait::__sleep | public | function | 1 | ||
DependencySerializationTrait::__wakeup | public | function | 2 | ||
FormController::$argumentResolver | protected | property | The argument resolver. | ||
FormController::$formBuilder | protected | property | The form builder. | ||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | ||
WorkspacesHtmlEntityFormController::getContentResult | public | function | Invokes the form and returns the result. | Overrides FormController::getContentResult | |
WorkspacesHtmlEntityFormController::getFormArgument | protected | function | Extracts the form argument string from a request. | Overrides FormController::getFormArgument | |
WorkspacesHtmlEntityFormController::getFormObject | protected | function | Returns the object used to build the form. | Overrides FormController::getFormObject | |
WorkspacesHtmlEntityFormController::__construct | public | function | Constructs a new \Drupal\Core\Controller\FormController object. | Overrides FormController::__construct |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.