Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
profile_manager
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
profile_manager
Commits
fea16f10
Commit
fea16f10
authored
4 months ago
by
Tim Bozeman
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3488427
by tim bozeman: Integrate with navigation module
parent
9e5049cf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
profile_manager.module
+41
-5
41 additions, 5 deletions
profile_manager.module
src/Plugin/Menu/RemovableMenuLink.php
+12
-0
12 additions, 0 deletions
src/Plugin/Menu/RemovableMenuLink.php
src/Routing/RouteSubscriber.php
+12
-17
12 additions, 17 deletions
src/Routing/RouteSubscriber.php
with
65 additions
and
22 deletions
profile_manager.module
+
41
−
5
View file @
fea16f10
...
...
@@ -23,11 +23,38 @@ function profile_manager_preprocess_navigation(array &$variables) {
$manager
=
\Drupal
::
service
(
'plugin.manager.block'
);
/** @var \Drupal\Core\Block\BlockPluginInterface $block */
$block
=
$manager
->
createInstance
(
'navigation_menu:profile-manager'
,
[
'level'
=>
2
,
'depth'
=>
2
]);
$uuid
=
\Drupal
::
service
(
'uuid'
)
->
generate
();
$variables
[
'content'
][
'content'
][
$uuid
]
=
$block
->
build
();
$variables
[
'content'
][
'content'
][
$uuid
][
'#weight'
]
=
-
10
;
$variables
[
'content'
][
'content'
][
$uuid
][
'#prefix'
]
=
"<div data-layout-builder-block-uuid=
\"
$uuid
\"
data-layout-builder-region=
\"
content
\"
class=
\"
toolbar-block
\"
>"
;
$variables
[
'content'
][
'content'
][
$uuid
][
'#suffix'
]
=
'</div>'
;
$menu
=
\Drupal
::
configFactory
()
->
get
(
'system.menu.profile-manager'
);
$uuid
=
$menu
->
get
(
'uuid'
);
$variables
[
'content'
][
'content'
][
$uuid
]
=
[
'content'
=>
$block
->
build
(),
'#theme'
=>
'block__navigation'
,
'#configuration'
=>
[
'id'
=>
'navigation_menu:profile-manager'
,
'label'
=>
'Profile manager'
,
'label_display'
=>
"0"
,
'provider'
=>
'navigation'
,
'level'
=>
2
,
'depth'
=>
2
,
],
'#plugin_id'
=>
"navigation_menu:profile-manager"
,
'#base_plugin_id'
=>
'navigation_menu'
,
'#derivative_plugin_id'
=>
'profile-manager'
,
'#weight'
=>
-
10
,
'#cache'
=>
[
'contexts'
=>
[
'user.permissions'
,
'user.roles'
],
'tags'
=>
[
'config:system.menu.profile-manager'
],
'max-age'
=>
-
1
,
'#attributes'
=>
[
'data-layout-builder-block-uuid'
=>
$uuid
,
'data-layout-builder-region'
=>
'content'
]
]
];
}
/**
...
...
@@ -250,3 +277,12 @@ function profile_manager_get_rendered_subtrees() {
});
return
[
$data
[
'#subtrees'
],
CacheableMetadata
::
createFromRenderArray
(
$data
)];
}
function
profile_manager_preprocess_navigation_menu__profile_manager
(
&
$variables
)
{
$variables
[
'items'
][
'cloudsites.create'
][
'class'
]
=
'navigation-create'
;
$variables
[
'items'
][
'cloudsites_misc.admin_content'
][
'class'
]
=
'navigation-content'
;
$variables
[
'items'
][
'cloudsites_misc.admin_media'
][
'class'
]
=
'navigation-media'
;
$variables
[
'items'
][
'cloudsites.appearance'
][
'class'
]
=
'system-themes-page'
;
$variables
[
'items'
][
'profile_manager.add_ons'
][
'class'
]
=
'system-modules-list'
;
$variables
[
'items'
][
'profile_manager.site_section'
][
'class'
]
=
'system-admin-config'
;
}
This diff is collapsed.
Click to expand it.
src/Plugin/Menu/RemovableMenuLink.php
+
12
−
0
View file @
fea16f10
...
...
@@ -16,6 +16,18 @@ use Drupal\Core\Menu\MenuLinkDefault;
*/
class
RemovableMenuLink
extends
MenuLinkDefault
{
/**
* {@inheritdoc}
*/
protected
$overrideAllowed
=
[
'menu_name'
=>
1
,
'parent'
=>
1
,
'weight'
=>
1
,
'expanded'
=>
1
,
'enabled'
=>
1
,
'title'
=>
1
,
];
/**
* {@inheritdoc}
*/
...
...
This diff is collapsed.
Click to expand it.
src/Routing/RouteSubscriber.php
+
12
−
17
View file @
fea16f10
...
...
@@ -86,7 +86,6 @@ class RouteSubscriber extends RouteSubscriberBase {
/** @var ProfileManagerDefinition $plugin_definition */
// @todo move this loop to config entities that store route access config for the plugin instances.
$definitions
=
$this
->
profileManagerPluginManager
->
getDefinitions
();
$this
->
cleanUpPluginLinks
(
...
array_values
(
$definitions
));
foreach
(
$definitions
as
$plugin_definition
)
{
$module_route
=
$collection
->
get
(
$plugin_definition
->
getRouteName
());
if
(
!
$module_route
)
{
...
...
@@ -114,9 +113,6 @@ class RouteSubscriber extends RouteSubscriberBase {
'_permission'
=>
'access profile manager overview'
]
);
if
(
$this
->
linkManager
->
hasDefinition
(
'profile_manager.overview'
))
{
$this
->
linkManager
->
removeDefinition
(
'profile_manager.overview'
);
}
$collection
->
add
(
'profile_manager.overview'
,
$route
);
$link
=
[
'class'
=>
RemovableMenuLink
::
class
,
...
...
@@ -126,7 +122,12 @@ class RouteSubscriber extends RouteSubscriberBase {
'menu_name'
=>
'profile-manager'
,
'provider'
=>
'profile_manager'
,
];
$this
->
linkManager
->
addDefinition
(
'profile_manager.overview'
,
$link
);
if
(
$this
->
linkManager
->
hasDefinition
(
'profile_manager.overview'
))
{
$this
->
linkManager
->
updateDefinition
(
'profile_manager.overview'
,
$link
);
}
else
{
$this
->
linkManager
->
addDefinition
(
'profile_manager.overview'
,
$link
);
}
}
protected
function
setupAvailableModules
(
RouteCollection
$collection
)
{
...
...
@@ -143,17 +144,6 @@ class RouteSubscriber extends RouteSubscriberBase {
$collection
->
add
(
'profile_manager.optional_modules'
,
$route
);
}
protected
function
cleanUpPluginLinks
(
ProfileManagerDefinition
...
$definitions
)
{
foreach
(
$definitions
as
$plugin_definition
)
{
/** @var ProfileManagerInterface $plugin */
$plugin
=
$this
->
profileManagerPluginManager
->
createInstance
(
$plugin_definition
->
id
());
// @todo how do we clean up menu items when a module is uninstalled?
if
(
$this
->
linkManager
->
hasDefinition
(
$plugin
->
getTransformedRouteName
()))
{
$this
->
linkManager
->
removeDefinition
(
$plugin
->
getTransformedRouteName
());
}
}
}
protected
function
setupPlugin
(
RouteCollection
$collection
,
ProfileManagerDefinition
$plugin_definition
,
Route
$module_route
)
{
/** @var ProfileManagerInterface $plugin */
$plugin
=
$this
->
profileManagerPluginManager
->
createInstance
(
$plugin_definition
->
id
());
...
...
@@ -183,7 +173,12 @@ class RouteSubscriber extends RouteSubscriberBase {
if
(
!
empty
(
$plugin_definition
->
getDefinition
()[
'route_parameters'
]))
{
$link
[
'route_parameters'
]
=
$plugin_definition
->
getDefinition
()[
'route_parameters'
];
}
$this
->
linkManager
->
addDefinition
(
$plugin
->
getTransformedRouteName
(),
$link
);
if
(
$this
->
linkManager
->
hasDefinition
(
$plugin
->
getTransformedRouteName
()))
{
$this
->
linkManager
->
updateDefinition
(
$plugin
->
getTransformedRouteName
(),
$link
);
}
else
{
$this
->
linkManager
->
addDefinition
(
$plugin
->
getTransformedRouteName
(),
$link
);
}
}
foreach
(
$this
->
getDelayedPlugin
(
$plugin
->
getTransformedRouteName
())
as
$plugin_data
)
{
$this
->
setupPlugin
(
$collection
,
$plugin_data
[
'definition'
],
$plugin_data
[
'route'
]);
...
...
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