Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
menu_manipulator
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_manipulator
Commits
4ab64263
Commit
4ab64263
authored
11 months ago
by
Matthieu Scarset
Browse files
Options
Downloads
Patches
Plain Diff
Check menu_link_content storage exists
#3251578
parent
f6b1dfd9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Menu/MenuLinkTreeManipulators.php
+29
-21
29 additions, 21 deletions
src/Menu/MenuLinkTreeManipulators.php
with
29 additions
and
21 deletions
src/Menu/MenuLinkTreeManipulators.php
+
29
−
21
View file @
4ab64263
...
@@ -26,6 +26,13 @@ use Drupal\Core\Url;
...
@@ -26,6 +26,13 @@ use Drupal\Core\Url;
*/
*/
class
MenuLinkTreeManipulators
{
class
MenuLinkTreeManipulators
{
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
/**
* The entity repository.
* The entity repository.
*
*
...
@@ -40,13 +47,6 @@ class MenuLinkTreeManipulators {
...
@@ -40,13 +47,6 @@ class MenuLinkTreeManipulators {
*/
*/
protected
$langcode
;
protected
$langcode
;
/**
* The menu_link_content storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected
$menuLinkContentStorage
;
/**
/**
* Our custom configuration.
* Our custom configuration.
*
*
...
@@ -83,7 +83,7 @@ class MenuLinkTreeManipulators {
...
@@ -83,7 +83,7 @@ class MenuLinkTreeManipulators {
Router
$router
Router
$router
)
{
)
{
$this
->
entityRepository
=
$entity_repository
;
$this
->
entityRepository
=
$entity_repository
;
$this
->
m
en
uLinkContentStor
age
=
$entity_type_manager
->
getStorage
(
'menu_link_content'
)
;
$this
->
en
tityTypeMan
age
r
=
$entity_type_manager
;
$this
->
langcode
=
$language_manager
->
getCurrentLanguage
()
->
getId
();
$this
->
langcode
=
$language_manager
->
getCurrentLanguage
()
->
getId
();
$this
->
config
=
$config_factory
->
get
(
'menu_manipulator.settings'
);
$this
->
config
=
$config_factory
->
get
(
'menu_manipulator.settings'
);
$this
->
router
=
$router
;
$this
->
router
=
$router
;
...
@@ -117,8 +117,8 @@ class MenuLinkTreeManipulators {
...
@@ -117,8 +117,8 @@ class MenuLinkTreeManipulators {
if
(
$element
->
hasChildren
&&
!
empty
(
$tree
[
$key
]
->
subtree
))
{
if
(
$element
->
hasChildren
&&
!
empty
(
$tree
[
$key
]
->
subtree
))
{
$element
->
subtree
=
$this
->
filterTreeByCurrentLanguage
(
$element
->
subtree
);
$element
->
subtree
=
$this
->
filterTreeByCurrentLanguage
(
$element
->
subtree
);
}
}
}
}
return
$tree
;
return
$tree
;
}
}
...
@@ -182,20 +182,23 @@ class MenuLinkTreeManipulators {
...
@@ -182,20 +182,23 @@ class MenuLinkTreeManipulators {
* Force the MenuLinkBase to tell us its language code.
* Force the MenuLinkBase to tell us its language code.
*
*
* @param \Drupal\Core\Menu\MenuLinkBase $link
* @param \Drupal\Core\Menu\MenuLinkBase $link
* `The Menu Link Content entity.
* The Menu Link item - usually an menu_link_content entity but it can be a
* config from Views or something else we don't even know about yet.
*
*
* @return string
* @return string
* The menu Link language ID or a default value.
* The menu Link language ID or a default value.
*
* @todo Handle config links such as those added by Views (e.g. get language).
*/
*/
protected
function
getLinkLanguage
(
MenuLinkBase
$link
)
{
protected
function
getLinkLanguage
(
MenuLinkBase
$link
)
{
$metadata
=
$link
->
getMetaData
();
$metadata
=
$link
->
getMetaData
();
if
(
!
isset
(
$metadata
[
'entity_id'
]))
{
$entity_id
=
$metadata
[
'entity_id'
]
??
NULL
;
return
LanguageInterface
::
LANGCODE_NOT_APPLICABLE
;
}
if
(
$loaded_link
=
$this
->
menuLinkContentStorage
->
load
(
$metadata
[
'entity_id'
]))
{
if
(
$entity_id
&&
$this
->
entityTypeManager
->
hasHandler
(
'menu_link_content'
,
'storage'
))
{
if
(
$loaded_lang_link
=
$this
->
entityRepository
->
getTranslationFromContext
(
$loaded_link
))
{
if
(
$loaded_link
=
$this
->
entityTypeManager
->
getStorage
(
'menu_link_content'
)
->
load
(
$entity_id
))
{
return
$loaded_lang_link
->
language
()
->
getId
();
if
(
$loaded_lang_link
=
$this
->
entityRepository
->
getTranslationFromContext
(
$loaded_link
))
{
return
$loaded_lang_link
->
language
()
->
getId
();
}
}
}
}
}
...
@@ -217,11 +220,16 @@ class MenuLinkTreeManipulators {
...
@@ -217,11 +220,16 @@ class MenuLinkTreeManipulators {
return
NULL
;
return
NULL
;
}
}
$loaded_link
=
$this
->
menuLinkContentStorage
->
load
(
$metadata
[
'entity_id'
]);
if
(
$this
->
entityTypeManager
->
hasHandler
(
'menu_link_content'
,
'storage'
))
{
$uri
=
$loaded_link
->
get
(
'link'
)
->
getString
();
/** @var \Drupal\Core\Menu\MenuLinkInterface $loaded_link */
$url
=
Url
::
fromUri
(
$uri
);
$loaded_link
=
$this
->
entityTypeManager
->
getStorage
(
'menu_link_content'
)
if
(
!
$url
instanceof
Url
||
!
$url
->
isRouted
())
{
->
load
(
$metadata
[
'entity_id'
]);
return
FALSE
;
$uri
=
$loaded_link
->
get
(
'link'
)
->
getString
();
$url
=
Url
::
fromUri
(
$uri
);
if
(
!
$url
instanceof
Url
||
!
$url
->
isRouted
())
{
return
FALSE
;
}
}
}
try
{
try
{
...
...
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