Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
form_mode_manager-3297262
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
form_mode_manager-3297262
Commits
5487408a
Commit
5487408a
authored
7 years ago
by
Alexandre Mallet
Committed by
Alexandre Mallet
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Controller/EntityFormModeBase.php
+30
-1
30 additions, 1 deletion
src/Controller/EntityFormModeBase.php
src/Routing/RouteSubscriber.php
+16
-3
16 additions, 3 deletions
src/Routing/RouteSubscriber.php
with
46 additions
and
4 deletions
src/Controller/EntityFormModeBase.php
+
30
−
1
View file @
5487408a
...
...
@@ -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
,
]);
}
...
...
This diff is collapsed.
Click to expand it.
src/Routing/RouteSubscriber.php
+
16
−
3
View file @
5487408a
...
...
@@ -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
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment