Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui_patterns-3465453
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
ui_patterns-3465453
Commits
e2fc75b3
Commit
e2fc75b3
authored
11 months ago
by
Mikael Meulle
Browse files
Options
Downloads
Patches
Plain Diff
SourcePluginManager: bug fix to better handle context requirements at plugin discovery (suite)
parent
77eb86b8
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/SourcePluginManager.php
+17
-3
17 additions, 3 deletions
src/SourcePluginManager.php
ui_patterns.services.yml
+1
-0
1 addition, 0 deletions
ui_patterns.services.yml
with
18 additions
and
3 deletions
src/SourcePluginManager.php
+
17
−
3
View file @
e2fc75b3
...
...
@@ -8,6 +8,7 @@ use Drupal\Core\Cache\CacheBackendInterface;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface
;
use
Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait
;
use
Drupal\Core\Plugin\Context\ContextHandlerInterface
;
use
Drupal\Core\Plugin\DefaultPluginManager
;
use
Drupal\ui_patterns
\Annotation\Source
;
use
Drupal\ui_patterns
\Plugin\Context\RequirementsContextDefinition
;
...
...
@@ -27,6 +28,7 @@ class SourcePluginManager extends DefaultPluginManager implements ContextAwarePl
CacheBackendInterface
$cache_backend
,
ModuleHandlerInterface
$module_handler
,
protected
PropTypePluginManager
$prop_type_manager
,
protected
ContextHandlerInterface
$context_handler
,
)
{
parent
::
__construct
(
'Plugin/UiPatterns/Source'
,
...
...
@@ -275,12 +277,17 @@ class SourcePluginManager extends DefaultPluginManager implements ContextAwarePl
*
* In addition to getDefinitionsForContexts(), this method
* checks context_definitions of plugins according to their keys.
* When required in def, a context must be present with same key.
* When required in def, a context must be present with same key,
* and it must satisfy the context definition.
*/
public
function
getDefinitionsForContextsRefined
(
array
$contexts
=
[])
{
$definitions
=
$this
->
getDefinitionsForContexts
(
$contexts
);
$definitions
=
array_filter
(
$definitions
,
function
(
$definition
)
use
(
$contexts
)
{
$context_definitions
=
$definition
[
"context_definitions"
]
??
[];
$checked_context_by_keys
=
[];
foreach
(
$contexts
as
$key
=>
$context
)
{
$checked_context_by_keys
[
$key
]
=
[];
}
$definitions
=
array_filter
(
$definitions
,
function
(
$definition
)
use
(
$contexts
,
&
$checked_context_by_keys
)
{
$context_definitions
=
isset
(
$definition
[
'context_definitions'
])
?
$definition
[
'context_definitions'
]
??
[]
:
[];
foreach
(
$context_definitions
as
$key
=>
$context_definition
)
{
if
(
!
$context_definition
->
isRequired
())
{
continue
;
...
...
@@ -288,6 +295,13 @@ class SourcePluginManager extends DefaultPluginManager implements ContextAwarePl
if
(
!
array_key_exists
(
$key
,
$contexts
))
{
return
FALSE
;
}
$context_definition_key
=
hash
(
'sha256'
,
serialize
(
$context_definition
));
if
(
!
isset
(
$checked_context_by_keys
[
$key
][
$context_definition_key
]))
{
$checked_context_by_keys
[
$key
][
$context_definition_key
]
=
$context_definitions
->
isSatisfiedBy
(
$contexts
[
$key
]);
}
if
(
!
$checked_context_by_keys
[
$key
][
$context_definition_key
])
{
return
FALSE
;
}
}
return
TRUE
;
});
...
...
This diff is collapsed.
Click to expand it.
ui_patterns.services.yml
+
1
−
0
View file @
e2fc75b3
...
...
@@ -29,6 +29,7 @@ services:
parent
:
default_plugin_manager
arguments
:
-
"
@plugin.manager.ui_patterns_prop_type"
-
'
@context.handler'
plugin.manager.ui_patterns_derivable_context
:
class
:
Drupal\ui_patterns\DerivableContextPluginManager
parent
:
default_plugin_manager
...
...
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