Skip to content
Snippets Groups Projects
Commit 5487408a authored by Alexandre Mallet's avatar Alexandre Mallet Committed by Alexandre Mallet
Browse files

Issue #2880567 by woprrr: Wrong entity title label by operation

parent 7d036877
No related branches found
No related tags found
No related merge requests found
......@@ -184,13 +184,42 @@ abstract class EntityFormModeBase extends ControllerBase implements ContainerInj
* The page title.
*/
public function addPageTitle(RouteMatchInterface $route_match) {
return $this->pageTitle($route_match, $this->t('Create'));
}
/**
* The _title_callback for the entity.add routes.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return string
* The page title.
*/
public function editPageTitle(RouteMatchInterface $route_match) {
return $this->pageTitle($route_match, $this->t('Edit'));
}
/**
* The _title_callback for the entity.add routes.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param string $operation
* Name of current context operation to display title (create/edit).
*
* @return string
* The page title.
*/
public function pageTitle(RouteMatchInterface $route_match, $operation) {
$entity_storage = $this->getEntityBundle($route_match);
$form_mode_label = $route_match->getRouteObject()
->getOption('parameters')['form_mode']['label'];
return $this->t('Create @name as @form_mode_label', [
return $this->t('@op @name as @form_mode_label', [
'@name' => (!$entity_storage instanceof UserStorageInterface) ? $entity_storage->get('name') : $entity_storage->getEntityType()
->id(),
'@form_mode_label' => $form_mode_label,
'@op' => $operation,
]);
}
......
......@@ -324,7 +324,12 @@ class RouteSubscriber extends RouteSubscriberBase {
* Form Mode Manager route to be added on entity collection.
*/
private function setRoutes(Route $parent_route, EntityTypeInterface $entity_type, array $form_mode) {
$route_defaults = array_merge($parent_route->getDefaults(), $this->getFormModeManagerDefaults($form_mode));
$op = 'create';
if (preg_match_all('/^.*?\/edit[^$]*/', $parent_route->getPath(), $matches, PREG_SET_ORDER, 0)) {
$op = 'edit';
}
$route_defaults = array_merge($parent_route->getDefaults(), $this->getFormModeManagerDefaults($form_mode, $op));
$roue_options = array_merge($parent_route->getOptions(), $this->getFormModeManagerOptions($form_mode, $entity_type));
$route_requirements = array_merge($parent_route->getRequirements(), $this->getFormModeManagerRequirements($form_mode, $entity_type));
......@@ -377,16 +382,24 @@ class RouteSubscriber extends RouteSubscriberBase {
*
* @param array $form_mode
* The form mode info.
* @param string $operation
* Operation context (create or edit).
*
* @return array
* Array contain defaults routes parameters.
*/
private function getFormModeManagerDefaults(array $form_mode) {
return [
private function getFormModeManagerDefaults(array $form_mode, $operation) {
$properties = [
'_entity_form' => $form_mode['id'],
'_controller' => '\Drupal\form_mode_manager\Controller\EntityFormModeController::entityAdd',
'_title_callback' => '\Drupal\form_mode_manager\Controller\EntityFormModeController::addPageTitle',
];
if ('edit' === $operation) {
$properties['_title_callback'] = '\Drupal\form_mode_manager\Controller\EntityFormModeController::editPageTitle';
}
return $properties;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment