Skip to content
Snippets Groups Projects
Commit 52d01b04 authored by Mikael Meulle's avatar Mikael Meulle Committed by Pierre Dureau
Browse files

fixed

parent 45e38fba
No related branches found
No related tags found
1 merge request!320Issue #3499625 by just_like_good_vibes: Introduce a new source to get access to the current "i-th" referenced entity from a field entity reference in the context of component per item field formatter
......@@ -77,9 +77,17 @@ class EntityReferencedDerivableContext extends DerivableContextPluginBase {
*/
public function getDerivedContexts(): array {
$referenced_entities = $this->getEntities();
$removed_context_keys = ["entity", "ui_patterns:field:index", "ui_patterns:field:items", "bundle"];
$removed_context_keys = ["entity", "ui_patterns:field:", "bundle"];
$base_context = array_filter($this->context, function ($one_context, $one_context_id) use (&$removed_context_keys) {
return !in_array($one_context_id, $removed_context_keys);
if (in_array($one_context_id, $removed_context_keys)) {
return FALSE;
}
foreach ($removed_context_keys as $removed_context_key) {
if (str_starts_with($one_context_id, $removed_context_key)) {
return FALSE;
}
}
return TRUE;
}, ARRAY_FILTER_USE_BOTH);
$base_context = RequirementsContext::removeFromContext(["field_granularity:item"], $base_context);
$metadata = $this->getMetadata();
......
......@@ -104,6 +104,16 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
return empty($returned) ? NULL : $returned;
}
/**
* Get the context to pass to the derivable context plugin.
*
* @return array
* The context.
*/
protected function getContextForDerivation(): array {
return $this->context;
}
/**
* Set the source plugin according to configuration.
*
......@@ -117,7 +127,7 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
return $this->sourcePlugins;
}
/** @var \Drupal\ui_patterns\DerivableContextInterface $derivable_context_plugin */
$derivable_context_plugin = $this->derivableContextManager->createInstance($derivable_context, DerivableContextPluginBase::buildConfiguration($this->context));
$derivable_context_plugin = $this->derivableContextManager->createInstance($derivable_context, DerivableContextPluginBase::buildConfiguration($this->getContextForDerivation()));
if (!$derivable_context_plugin) {
return $this->sourcePlugins;
}
......
......@@ -31,6 +31,18 @@ class EntityReferencedSource extends DerivableContextSourceBase {
return $form;
}
/**
* Get the context to pass to the derivable context plugin.
*
* @return array
* The context.
*/
protected function getContextForDerivation(): array {
return array_filter($this->context, function ($key) {
return $key !== 'ui_patterns:field:index';
}, ARRAY_FILTER_USE_KEY);
}
/**
* {@inheritDoc}
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment