Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
menu_save_add_another
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
menu_save_add_another
Commits
538ab871
Commit
538ab871
authored
3 years ago
by
Andy Hebrank
Browse files
Options
Downloads
Patches
Plain Diff
work with menu link edit as well as add
parent
f2bb98d8
Branches
1.x
Branches containing commit
Tags
1.0.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
menu_save_add_another.info.yml
+2
-0
2 additions, 0 deletions
menu_save_add_another.info.yml
menu_save_add_another.module
+26
-6
26 additions, 6 deletions
menu_save_add_another.module
with
28 additions
and
6 deletions
menu_save_add_another.info.yml
+
2
−
0
View file @
538ab871
...
...
@@ -4,3 +4,5 @@ description: Make menu item stubbing easier. Fix the menu add item redirect and
package
:
Menu
core
:
8.x
core_version_requirement
:
^8 || ^9
dependencies
:
-
drupal:menu_ui
This diff is collapsed.
Click to expand it.
menu_save_add_another.module
+
26
−
6
View file @
538ab871
...
...
@@ -7,6 +7,7 @@
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Url
;
use
Drupal\Core\Render\Element
;
/**
* Implements hook_menu_local_actions_alter().
...
...
@@ -21,16 +22,26 @@ function menu_save_add_another_menu_local_actions_alter(array &$local_actions) {
/**
* Implements hook_form_alter().
*/
function
menu_save_add_another_form_menu_link_content_form_alter
(
array
&
$form
,
FormStateInterface
$form_state
,
$form_id
)
{
// Set redirect on the original save button (since we've removed the ?destination).
$form
[
'actions'
][
'submit'
][
'#submit'
][]
=
'_menu_save_add_another_redirect_menu'
;
function
menu_save_add_another_form_menu_edit_form_alter
(
array
&
$form
,
FormStateInterface
$form_state
,
$form_id
)
{
// Unset the edit link redirects.
foreach
(
Element
::
children
(
$form
[
'links'
][
'links'
])
as
$link
)
{
$form
[
'links'
][
'links'
][
$link
][
'operations'
][
'#links'
][
'edit'
][
'query'
]
=
[];
}
}
/**
* Implements hook_form_alter().
*/
function
menu_save_add_another_form_menu_link_content_form_alter
(
array
&
$form
,
FormStateInterface
$form_state
,
$form_id
)
{
// Add another save button.
$form
[
'actions'
][
'submit_and_add'
]
=
$form
[
'actions'
][
'submit'
];
$form
[
'actions'
][
'submit_and_add'
][
'#value'
]
=
t
(
'Save and Add Another'
);
$form
[
'actions'
][
'submit_and_add'
][
'#weight'
]
=
6
;
$form
[
'actions'
][
'submit_and_add'
][
'#button_type'
]
=
''
;
$form
[
'actions'
][
'submit_and_add'
][
'#submit'
][]
=
'_menu_save_add_another_redirect_add'
;
// Set redirect on the original save button (since we've removed the ?destination).
$form
[
'actions'
][
'submit'
][
'#submit'
][]
=
'_menu_save_add_another_redirect_menu'
;
}
/**
...
...
@@ -49,7 +60,16 @@ function _menu_save_add_another_redirect_add(array $form, FormStateInterface $fo
function
_menu_save_add_another_set_redirect
(
FormStateInterface
$form_state
,
$route_name
)
{
$route_match
=
\Drupal
::
routeMatch
();
// Route params are the same for the menu and for the menu item.
$options
=
$route_match
->
getRawParameters
()
->
all
();
$form_state
->
setRedirect
(
$route_name
,
$options
);
// Route params might either include a menu (for new items) or the menu_link_content (for existing).
$menu
=
$route_match
->
getRawParameter
(
'menu'
);
if
(
!
$menu
)
{
$menu_link
=
$route_match
->
getParameter
(
'menu_link_content'
);
if
(
$menu_link
)
{
// Look up the menu for the link.
$menu
=
$menu_link
->
getMenuName
();
}
}
if
(
$menu
)
{
$form_state
->
setRedirect
(
$route_name
,
[
'menu'
=>
$menu
]);
}
}
\ No newline at end of file
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