Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tooltip_taxonomy
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
tooltip_taxonomy
Commits
482efab2
Commit
482efab2
authored
3 weeks ago
by
Randal V
Committed by
Mingsong
3 weeks ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3479567
by randalv, mingsong: TermStorage::loadTree is not language aware
parent
a1e5c067
No related branches found
No related tags found
1 merge request
!13
Issue #3479567: TermStorage::loadTree is not language aware
Pipeline
#408784
passed with warnings
3 weeks ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Services/TooltipManager.php
+48
-40
48 additions, 40 deletions
src/Services/TooltipManager.php
tooltip_taxonomy.services.yml
+1
-1
1 addition, 1 deletion
tooltip_taxonomy.services.yml
with
49 additions
and
41 deletions
src/Services/TooltipManager.php
+
48
−
40
View file @
482efab2
...
...
@@ -5,6 +5,7 @@ namespace Drupal\tooltip_taxonomy\Services;
use
Drupal\Core\Entity\ContentEntityBase
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Component\Plugin\Factory\FactoryInterface
;
use
Drupal\Core\Entity\EntityRepositoryInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Render\RendererInterface
;
use
Drupal\node\Entity\Node
;
...
...
@@ -43,6 +44,13 @@ class TooltipManager {
*/
protected
$entityTypeManager
;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected
$entityRepository
;
/**
* The term storage.
*
...
...
@@ -76,11 +84,12 @@ class TooltipManager {
* @param \Drupal\Core\Render\RendererInterface $renderer
* Render service instance.
*/
public
function
__construct
(
FactoryInterface
$plugin_factory
,
FieldTypeManager
$field_type_manager
,
EntityTypeManagerInterface
$entity_type_manager
,
RendererInterface
$renderer
)
{
public
function
__construct
(
FactoryInterface
$plugin_factory
,
FieldTypeManager
$field_type_manager
,
EntityTypeManagerInterface
$entity_type_manager
,
EntityRepositoryInterface
$entity_repository
,
RendererInterface
$renderer
)
{
$this
->
pathCondition
=
$plugin_factory
->
createInstance
(
'request_path'
);
$this
->
contentTypeCondition
=
$plugin_factory
->
createInstance
(
'entity_bundle:node'
);
$this
->
fieldTypeManager
=
$field_type_manager
;
$this
->
entityTypeManager
=
$entity_type_manager
;
$this
->
entityRepository
=
$entity_repository
;
$this
->
renderer
=
$renderer
;
$this
->
termStorage
=
$this
->
entityTypeManager
->
getStorage
(
'taxonomy_term'
);
}
...
...
@@ -307,45 +316,41 @@ class TooltipManager {
}
foreach
(
$vids
as
$vid
)
{
$term_tree
=
$this
->
loadAllTaxonomyTerms
(
$vid
);
if
(
!
empty
(
$term_tree
))
{
foreach
(
$term_tree
as
$term
)
{
if
(
$term
instanceof
TermInterface
)
{
$access
=
$term
->
access
(
'view'
);
}
else
{
$access
=
$term
->
status
??
FALSE
;
}
if
(
!
$access
)
{
continue
;
}
$term_ids
=
$this
->
loadAllTaxonomyTermIds
(
$vid
);
foreach
(
$term_ids
as
$tid
)
{
$term
=
$this
->
termStorage
->
load
(
$tid
);
if
(
!
$term
instanceof
TermInterface
||
!
$term
->
access
(
'view'
))
{
continue
;
}
$des
=
strip_tags
((
string
)
$term
->
description__value
,
$allowed_html_tags
);
if
(
empty
(
$des
))
{
continue
;
}
$tooltip_render
=
[
'#theme'
=>
'tooltip_taxonomy'
,
'#tooltip_id'
=>
$term
->
vid
.
'-'
.
$term
->
tid
,
'#term_name'
=>
$term
->
name
,
'#description'
=>
$des
,
];
$name_pattern
=
'/\b'
.
preg_quote
(
$term
->
name
,
'/'
)
.
'\b/'
;
// Check if there is a same term name.
$name_key
=
array_search
(
$name_pattern
,
$pattern_map
[
'search'
]);
if
(
$name_key
===
FALSE
)
{
// New term.
$pattern_map
[
'search'
][]
=
$name_pattern
;
$pattern_map
[
'replace'
][]
=
$this
->
renderer
->
renderPlain
(
$tooltip_render
);
}
else
{
// Overwrite existing term.
// Conditions that has bigger weight value
// will overwrite the same term name.
$pattern_map
[
'replace'
][
$name_key
]
=
$this
->
renderer
->
renderPlain
(
$tooltip_render
);
}
$count
++
;
/** @var \Drupal\taxonomy\TermInterface $term */
$term
=
$this
->
entityRepository
->
getTranslationFromContext
(
$term
);
$des
=
strip_tags
(
$term
->
get
(
'description'
)
->
value
,
$allowed_html_tags
);
if
(
empty
(
$des
))
{
continue
;
}
$tooltip_render
=
[
'#theme'
=>
'tooltip_taxonomy'
,
'#tooltip_id'
=>
$term
->
bundle
()
.
'-'
.
$term
->
id
(),
'#term_name'
=>
$term
->
getName
(),
'#description'
=>
$des
,
];
$name_pattern
=
'/\b'
.
preg_quote
(
$term
->
getName
(),
'/'
)
.
'\b/'
;
// Check if there is a same term name.
$name_key
=
array_search
(
$name_pattern
,
$pattern_map
[
'search'
]);
if
(
$name_key
===
FALSE
)
{
// New term.
$pattern_map
[
'search'
][]
=
$name_pattern
;
$pattern_map
[
'replace'
][]
=
$this
->
renderer
->
renderInIsolation
(
$tooltip_render
);
}
else
{
// Overwrite existing term.
// Conditions that has bigger weight value
// will overwrite the same term name.
$pattern_map
[
'replace'
][
$name_key
]
=
$this
->
renderer
->
renderInIsolation
(
$tooltip_render
);
}
$count
++
;
}
}
...
...
@@ -361,8 +366,11 @@ class TooltipManager {
* @return array
* All entities in the entity bundle.
*/
protected
function
loadAllTaxonomyTerms
(
string
$vid
)
{
return
$this
->
termStorage
->
loadTree
(
$vid
);
protected
function
loadAllTaxonomyTermIds
(
string
$vid
)
{
return
$this
->
termStorage
->
getQuery
()
->
accessCheck
()
->
condition
(
'vid'
,
$vid
)
->
execute
();
}
/**
...
...
This diff is collapsed.
Click to expand it.
tooltip_taxonomy.services.yml
+
1
−
1
View file @
482efab2
...
...
@@ -7,6 +7,6 @@ services:
# Tooltip filter condition manager
tooltip_taxonomy.tooltip_manager
:
class
:
\Drupal\tooltip_taxonomy\Services\TooltipManager
arguments
:
[
'
@plugin.manager.condition'
,
'
@tooltip_taxonomy.field_type_manager'
,
'
@entity_type.manager'
,
'
@renderer'
]
arguments
:
[
'
@plugin.manager.condition'
,
'
@tooltip_taxonomy.field_type_manager'
,
'
@entity_type.manager'
,
'
@entity.repository'
,
'
@renderer'
]
tags
:
-
{
name
:
tooltip_taxonomy.tooltip_manager
,
priority
:
1000
}
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