Skip to content
Snippets Groups Projects

Issue #3440278 + bonus : various bugfixes to allow correct nesting, correct source plugins context filtering. super nice

Merged Issue #3440278 + bonus : various bugfixes to allow correct nesting, correct source plugins context filtering. super nice
21 files
+ 242
128
Compare changes
  • Side-by-side
  • Inline

Files

@@ -112,11 +112,14 @@ abstract class FieldPropertiesSourceDeriverBase extends DeriverBase implements C
$field_name_context = new ContextDefinition('string');
$field_name_context
->setRequired()
->setLabel("field_name")
->setDefaultValue($field_name)
->addConstraint('AllowedValues', [$field_name]);
$bundle_context = new ContextDefinition('string');
$bundle_context
->setRequired()
->setLabel("bundle")
// @todo check exactly why there is "" in the allowed values.
->addConstraint('AllowedValues', array_merge(array_values($bundles), [""]));
$derivative_for_this_field = array_merge($base_plugin_definition, [
// The base id for the derivatives.
@@ -165,6 +168,13 @@ abstract class FieldPropertiesSourceDeriverBase extends DeriverBase implements C
public function getDerivativeDefinitionsForField(array $derivative_for_this_field, FieldStorageDefinitionInterface $field_storage_definition) {
// Generate one plugin for each field property,
// compatible only for the corresponding bundles.
$ui_patterns_component_per_item_context = new ContextDefinition('string');
$ui_patterns_component_per_item_context
->setRequired(TRUE)
->setLabel("ui_patterns_entity_field_granularity")
->setDefaultValue("item")
// This line is fundamental, and does what we want to achieve.
->addConstraint("AllowedValues", ["item"]);
foreach ($field_storage_definition->getPropertyDefinitions() as $property_id => $property_definition) {
// Skip entity reference
// Description could have been more precise,
@@ -184,6 +194,8 @@ abstract class FieldPropertiesSourceDeriverBase extends DeriverBase implements C
"prop_types" => $this->getPropTypesDeriver($property_definition),
]
);
$derivative['context_definitions'] = array_merge(
$derivative['context_definitions'], ["ui_patterns_entity_field_granularity" => $ui_patterns_component_per_item_context]);
$derivative['id'] = implode(PluginBase::DERIVATIVE_SEPARATOR, [
$derivative['id'],
$property_id,
@@ -191,7 +203,11 @@ abstract class FieldPropertiesSourceDeriverBase extends DeriverBase implements C
$derivative['ui_patterns_field_formatter'] = array_merge($derivative['ui_patterns_field_formatter'], [
'property' => $property_id,
]);
$this->derivatives[$derivative['id']] = $derivative;
// If no compatible prop types were inferred, we discard the plugin.
if (count($derivative["prop_types"]) > 0) {
$this->derivatives[$derivative['id']] = $derivative;
}
}
}
Loading