Skip to content
Snippets Groups Projects
Commit 01911807 authored by Mikael Meulle's avatar Mikael Meulle Committed by christian.wiedemann
Browse files

Issue #3455076 by just_like_good_vibes: [2.0.0-alpha3] Move Field-related...

Issue #3455076 by just_like_good_vibes: [2.0.0-alpha3] Move Field-related sources from ui_pattern_field_formatters to ui_patterns
parent 51cdafbe
Branches
Tags
1 merge request!118Resolve #3455076 "2.0.0 alpha3 move field related"
Showing
with 205 additions and 303 deletions
......@@ -8,6 +8,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\ui_patterns\Plugin\Derivative\FieldPropertiesSourceDeriverBase;
use Drupal\ui_patterns\PropTypePluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -17,7 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @internal
* Plugin derivers are internal.
*/
class FieldPropertiesSourceSlotDeriver extends FieldPropertiesSourceDeriverBase {
class FieldFormatterSourceDeriver extends FieldPropertiesSourceDeriverBase {
/**
* Constructs new FieldBlockDeriver.
......@@ -71,12 +72,14 @@ class FieldPropertiesSourceSlotDeriver extends FieldPropertiesSourceDeriverBase
"prop_types" => ["slot"],
]
);
$derivative['ui_patterns_field_formatter'] = array_merge($derivative['ui_patterns_field_formatter'], [
$derivative['metadata'] = array_merge($derivative['metadata'], [
'field_formatter' => TRUE,
]);
$this->derivatives[$derivative['id']] = $derivative;
}
parent::getDerivativeDefinitionsForField($derivative_for_this_field, $field_storage_definition);
// Those will be covered using convert mechanism
// parent::getDerivativeDefinitionsForField(
// $derivative_for_this_field, $field_storage_definition);.
}
/**
......
......@@ -7,7 +7,7 @@ namespace Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\ui_patterns\SourcePluginBase;
use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
/**
* Plugin implementation of the 'component_all' formatter.
......@@ -53,7 +53,7 @@ class ComponentFormatter extends ComponentFormatterBase {
* Source contexts.
*/
protected function getComponentSourceContexts(): array {
return SourcePluginBase::addRequirementsToContext(parent::getComponentSourceContexts(), ["field_granularity:items"]);
return RequirementsContext::addToContext(["field_granularity:items"], parent::getComponentSourceContexts());
}
}
......@@ -4,13 +4,14 @@ declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContext;
use Drupal\ui_patterns\Form\ComponentSettingsFormBuilderTrait;
use Drupal\ui_patterns\SourcePluginBase;
use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -45,6 +46,13 @@ abstract class ComponentFormatterBase extends FormatterBase {
*/
protected $sampleEntityGenerator;
/**
* Entity Field Manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The provided plugin contexts.
*
......@@ -83,6 +91,7 @@ abstract class ComponentFormatterBase extends FormatterBase {
$instance->contextRepository = $container->get('context.repository');
$instance->entityTypeManager = $container->get('entity_type.manager');
$instance->sampleEntityGenerator = $container->get('ui_patterns.sample_entity_generator');
$instance->entityFieldManager = $container->get('entity_field.manager');
return $instance;
}
......@@ -148,7 +157,7 @@ abstract class ComponentFormatterBase extends FormatterBase {
// we properly get them especially source plugins
// with context_requirements having field_granularity:item.
if (is_array($this->context) && array_key_exists("context_requirements", $this->context) && $this->context["context_requirements"]->hasValue("field_granularity:item")) {
$injected_contexts = SourcePluginBase::addRequirementsToContext($injected_contexts, ["field_granularity:item"]);
$injected_contexts = RequirementsContext::addToContext(["field_granularity:item"], $injected_contexts);
}
return $this->componentSettingsForm($form, $form_state, $injected_contexts);
}
......@@ -165,17 +174,12 @@ abstract class ComponentFormatterBase extends FormatterBase {
$field_definition = $this->fieldDefinition;
$entity_type_id = $field_definition->getTargetEntityTypeId();
$contextEntityTypeDefinition = ContextDefinition::create('string');
$contextEntityTypeDefinition->setLabel("entity_type_id");
$contextEntityType = new Context($contextEntityTypeDefinition, $entity_type_id);
$contexts['entity_type_id'] = $contextEntityType;
$contextFieldNameDefinition = ContextDefinition::create('string');
$contextFieldNameDefinition->setLabel("field_name");
$contextFieldName = new Context($contextFieldNameDefinition, $field_definition->getName());
$contexts['field_name'] = $contextFieldName;
$contexts = SourcePluginBase::addRequirementsToContext($contexts, ["field_formatter"]);
$contexts = RequirementsContext::addToContext(["field_formatter"], $contexts);
$contextBundleDefinition = ContextDefinition::create('string');
$contextBundleDefinition->setLabel("bundle");
......@@ -183,12 +187,21 @@ abstract class ComponentFormatterBase extends FormatterBase {
if (NULL === $bundle) {
// Generate a default bundle when it is missing,
// this covers contexts like the display of a field in a view.
// the bundle selected should have the field in defintion...
$bundle = $entity_type_id;
$bundle_entity_type = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType();
if (NULL !== $bundle_entity_type) {
$bunle_list = $this->entityTypeManager->getStorage($bundle_entity_type)->loadMultiple();
if (count($bunle_list) > 0) {
$bundle = array_values($bunle_list)[0]->id();
foreach ($bunle_list as $bundle_entity) {
$bundle_to_test = $bundle_entity->id();
$definitions = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle_to_test);
if (array_key_exists($field_definition->getName(), $definitions)) {
$bundle = $bundle_to_test;
break;
}
}
// $bundle = array_values($bunle_list)[0]->id();
}
}
}
......@@ -205,7 +218,12 @@ abstract class ComponentFormatterBase extends FormatterBase {
}
}
if (!array_key_exists("entity", $contexts)) {
if (!array_key_exists("entity", $contexts) ||
(NULL === $contexts['entity']->getContextValue()) ||
!($contexts['entity']->getContextValue() instanceof EntityInterface) ||
($contexts['entity']->getContextValue()->getEntityTypeId() !== $entity_type_id) ||
($contexts['entity']->getContextValue()->bundle() !== $bundle)
) {
$contexts['entity'] = EntityContext::fromEntity($this->sampleEntityGenerator->get($entity_type_id, $bundle));
}
......@@ -213,37 +231,38 @@ abstract class ComponentFormatterBase extends FormatterBase {
}
/**
* Alter the configuration of the mapping, like index and langcode.
* Store extra data in component configuration for each prop and slot source.
*
* @param array $specific_config
* Array of specific configuration to insert.
*
* @return array
* The configuration array.
*/
protected function setComponentSettingsExtra(array $specific_config): array {
$configuration = $this->getComponentSettings();
if (!array_key_exists('ui_patterns', $configuration)) {
return $configuration;
}
if (!array_key_exists('props', $configuration['ui_patterns']) && !array_key_exists('slots', $configuration['ui_patterns'])) {
return $configuration;
}
// Loop on each ui patterns props.
$prop_ids = array_keys($configuration['ui_patterns']['props']);
foreach ($prop_ids as $prop_id) {
$configuration['ui_patterns']['props'][$prop_id]['source']['ui_patterns_field_formatter'] = $specific_config;
}
foreach ($configuration['ui_patterns']['slots'] as $slots_id => $slots) {
if (empty($slots['sources']) || !is_array($slots['sources'])) {
continue;
protected function setComponentSettingsExtra(array $specific_config): void {
$configuration = $this->getComponentConfiguration();
$somethingDone = FALSE;
// Loop on each ui patterns props and slots.
if (array_key_exists('props', $configuration)) {
foreach ($configuration['props'] as $prop_id => &$prop_configuration) {
$prop_configuration['source']['extra'] = $specific_config;
$somethingDone = TRUE;
}
foreach (array_keys($slots['sources']) as $source_id) {
$configuration['ui_patterns']['slots'][$slots_id]['sources'][$source_id]['source']['ui_patterns_field_formatter'] = $specific_config;
unset($prop_configuration);
}
if (array_key_exists('slots', $configuration)) {
foreach ($configuration['slots'] as $slots_id => &$slots) {
if (empty($slots['sources']) || !is_array($slots['sources'])) {
continue;
}
foreach ($slots['sources'] as $source_id => &$source_configuration) {
$source_configuration['source']['extra'] = $specific_config;
$somethingDone = TRUE;
}
unset($source_configuration);
}
unset($slots);
}
if ($somethingDone) {
$this->setComponentConfiguration($configuration);
}
$this->setComponentConfiguration($configuration['ui_patterns']);
return $configuration['ui_patterns'];
}
}
......@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\ui_patterns\SourcePluginBase;
use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
/**
* Plugin implementation of the 'component_each' formatter.
......@@ -46,7 +46,7 @@ class ComponentPerItemFormatter extends ComponentFormatterBase {
* Source contexts.
*/
protected function getComponentSourceContexts(): array {
return SourcePluginBase::addRequirementsToContext(parent::getComponentSourceContexts(), ["field_granularity:item"]);
return RequirementsContext::addToContext(["field_granularity:item"], parent::getComponentSourceContexts());
}
}
......@@ -5,20 +5,31 @@ declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Field\FormatterInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\ui_patterns\Plugin\UiPatterns\Source\FieldPropertySourceBase;
use Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\ComponentFormatterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Component field formatter, manage the form settings.
* Source plugin for field formater.
*
* @Source(
* id = "field_formater",
* label = @Translation("Field Formater"),
* description = @Translation("Entity Field formated with a field formater"),
* deriver =
* "Drupal\ui_patterns_field_formatters\Plugin\Derivative\FieldFormatterSourceDeriver",
* )
*/
abstract class FieldFormatterFormBase extends FieldFormatterSourceBase {
class FieldFormatterSource extends FieldPropertySourceBase {
use LoggerChannelTrait;
......@@ -70,24 +81,6 @@ abstract class FieldFormatterFormBase extends FieldFormatterSourceBase {
return $form;
}
/**
* Test if we can add the formatter field formatter.
*
* @return bool
* Result of the test.
*/
private function isApplicableFormatterFieldFormatter($plugin_definition) {
$field_formatter_metadata = $this->getCustomPluginMetadata('field_formatter');
if (!$field_formatter_metadata) {
return FALSE;
}
// Only available for slots.
if (!empty($plugin_definition['prop_types'][0]) && $plugin_definition['prop_types'][0] === 'slot') {
return TRUE;
}
return FALSE;
}
/**
* Callback to build field formatter form.
*
......@@ -103,10 +96,6 @@ abstract class FieldFormatterFormBase extends FieldFormatterSourceBase {
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
private function buildFieldFormatterForm(array &$form, FormStateInterface $form_state) {
$plugin_definition = $this->getPluginDefinition();
if (!$this->isApplicableFormatterFieldFormatter($plugin_definition)) {
return FALSE;
}
$field_definition = $this->getFieldDefinition();
if (!$field_definition instanceof FieldDefinitionInterface) {
return FALSE;
......@@ -295,4 +284,83 @@ abstract class FieldFormatterFormBase extends FieldFormatterSourceBase {
return $options;
}
/**
* Ajax callback for fields with AJAX callback to update form substructure.
*
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return array
* The replaced form substructure.
*/
public static function onFormatterTypeChange(array $form, FormStateInterface $form_state): array {
$triggeringElement = $form_state->getTriggeringElement();
// Dynamically return the dependent ajax for elements based on the
// triggering element. This shouldn't be done statically because
// settings forms may be different, e.g. for layout builder, core, ...
if (!empty($triggeringElement['#array_parents'])) {
$subformKeys = $triggeringElement['#array_parents'];
// Remove the triggering element itself and add the 'settings' below key.
array_pop($subformKeys);
$subformKeys[] = 'settings';
// Return the subform:
return NestedArray::getValue($form, $subformKeys);
}
return [];
}
/**
* Render field item(s) with the field formatter.
*
* @param \Drupal\Core\Field\FieldItemListInterface $items
* Items.
* @param int|null $field_delta
* Field delta.
*
* @return array
* Render array
*/
private function viewFieldItems(FieldItemListInterface $items, $field_delta = NULL): array {
$returned = [];
$configuration = $this->getConfiguration();
if (empty($configuration['settings']['type'])) {
// No formatter has been configured.
return $returned;
}
for ($delta = 0; $delta < $items->count(); $delta++) {
/** @var \Drupal\Core\Field\FieldItemInterface $item */
$item = $items->get($delta);
if ($field_delta !== NULL) {
if ($delta !== $field_delta) {
continue;
}
$returned[] = $item->view([
'type' => $configuration['settings']['type'],
'settings' => $configuration['settings']['settings'] ?? [],
]);
break;
}
$returned[] = $item->view([
'type' => $configuration['settings']['type'],
'settings' => $configuration['settings']['settings'],
]);
}
return $returned;
}
/**
* {@inheritdoc}
*/
public function getPropValue(): mixed {
$items = $this->getEntityFieldItemList();
if (!$items instanceof FieldItemListInterface) {
return [];
}
$field_index = $this->getConfiguredSettingsExtra('field_index') ?? NULL;
return $this->viewFieldItems($items, $field_index);
}
}
<?php
declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\LoggerChannelTrait;
/**
* Component field formatter, handle the data source.
*/
abstract class FieldFormatterSourceBase extends FieldPropertySourceBase {
use LoggerChannelTrait;
/**
* Ajax callback for fields with AJAX callback to update form substructure.
*
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return array
* The replaced form substructure.
*/
public static function onFormatterTypeChange(array $form, FormStateInterface $form_state): array {
$triggeringElement = $form_state->getTriggeringElement();
// Dynamically return the dependent ajax for elements based on the
// triggering element. This shouldn't be done statically because
// settings forms may be different, e.g. for layout builder, core, ...
if (!empty($triggeringElement['#array_parents'])) {
$subformKeys = $triggeringElement['#array_parents'];
// Remove the triggering element itself and add the 'settings' below key.
array_pop($subformKeys);
$subformKeys[] = 'settings';
// Return the subform:
return NestedArray::getValue($form, $subformKeys);
}
return [];
}
/**
* Render field item(s) with the field formatter.
*
* @param \Drupal\Core\Field\FieldItemListInterface $items
* Items.
* @param int|null $field_delta
* Field delta.
*
* @return array
* Render array
*/
private function viewFieldItems(FieldItemListInterface $items, $field_delta = NULL): array {
$returned = [];
$configuration = $this->getConfiguration();
if (empty($configuration['settings']['type'])) {
// No formatter has been configured.
return $returned;
}
for ($delta = 0; $delta < $items->count(); $delta++) {
/** @var \Drupal\Core\Field\FieldItemInterface $item */
$item = $items->get($delta);
if ($field_delta !== NULL) {
if ($delta !== $field_delta) {
continue;
}
$returned[] = $item->view([
'type' => $configuration['settings']['type'],
'settings' => $configuration['settings']['settings'] ?? [],
]);
break;
}
$returned[] = $item->view([
'type' => $configuration['settings']['type'],
'settings' => $configuration['settings']['settings'],
]);
}
return $returned;
}
/**
* {@inheritdoc}
*/
public function getPropValue(): mixed {
$items = $this->getEntityFieldItemList();
if (!$items instanceof FieldItemListInterface) {
return [];
}
$field_index = $this->getConfiguredSettingsExtra('field_index') ?? NULL;
return $this->viewFieldItems($items, $field_index);
}
}
......@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source;
use Drupal\ui_patterns\Plugin\UiPatterns\Source\FieldSourceBase;
/**
* Plugin implementation of the field_label source.
*
......
<?php
declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source;
/**
* Plugin implementation of the field_label slot source.
*
* @Source(
* id = "field_label_slot",
* label = @Translation("Field label"),
* description = @Translation("Field label source plugin."),
* prop_types = {
* "slot"
* }
* )
*/
class FieldLabelSourceSlot extends FieldLabelSource {
/**
* {@inheritdoc}
*/
public function getPropValue(): mixed {
return ["#markup" => parent::getPropValue()];
}
}
<?php
declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Plugin implementation of the slot source.
*
* @Source(
* id = "field_properties_source_slot",
* label = @Translation("Field Property (Slots)"),
* description = @Translation("Field property source plugin for slot."),
* deriver =
* "Drupal\ui_patterns_field_formatters\Plugin\Derivative\FieldPropertiesSourceSlotDeriver",
* )
*/
class FieldPropertySourceSlot extends FieldFormatterFormBase {
/**
* {@inheritdoc}
*/
public function getPropValue(): mixed {
$items = $this->getEntityFieldItemList();
if (!$items instanceof FieldItemListInterface) {
return [];
}
$field_index = $this->getConfiguredSettingsExtra('field_index') ?? NULL;
// Render using a display formater.
if ($this->getCustomPluginMetadata('field_formatter')) {
return parent::getPropValue();
}
$property = $this->getCustomPluginMetadata('property');
if (empty($property)) {
return [];
}
$lang_code = $this->getConfiguredSettingsExtra("lang_code") ?? 'und';
return $this->getDataItems($items, $property, $lang_code, $field_index);
}
/**
* Get Data items.
*
* @param \Drupal\Core\Field\FieldItemListInterface $items
* Items.
* @param string $property
* Property.
* @param string $lang_code
* Lang code.
* @param int|null $field_index
* Field index.
*
* @return mixed
* Items.
*
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
private function getDataItems(FieldItemListInterface $items, $property, $lang_code, $field_index = NULL): mixed {
$returned = [];
for ($delta = 0; $delta < $items->count(); $delta++) {
/** @var \Drupal\Core\Field\FieldItemInterface $fieldValue */
$fieldValue = $items->get($delta);
if ((NULL !== $field_index) && $delta != $field_index) {
continue;
}
$returned[] = ['#markup' => $this->extractPropertyValue($fieldValue, $property, $lang_code)];
}
return $returned;
}
}
......@@ -6,10 +6,10 @@ use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Field\FieldConfigInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\ui_patterns_field_formatters\Plugin\Derivative\FieldPropertiesSourcePropDeriver;
use Drupal\ui_patterns_field_formatters\Plugin\Derivative\FieldPropertiesSourceSlotDeriver;
use Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldPropertySourceProp;
use Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldPropertySourceSlot;
use Drupal\ui_patterns\Plugin\Derivative\FieldPropertiesSourcePropDeriver;
use Drupal\ui_patterns\Plugin\UiPatterns\Source\FieldPropertySourceProp;
use Drupal\ui_patterns_field_formatters\Plugin\Derivative\FieldFormatterSourceDeriver;
use Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource;
/**
* Tests the ui_patterns_field_formatters deriver plugin.
......@@ -97,8 +97,8 @@ class PluginTest extends UIPatternsFieldFormattersTestBase {
[
'deriver_type' => 'slot',
'prop_types' => ['slot'],
'deriver' => FieldPropertiesSourceSlotDeriver::class,
'class' => FieldPropertySourceSlot::class,
'deriver' => FieldFormatterSourceDeriver::class,
'class' => FieldFormatterSource::class,
],
[
'deriver_type' => 'prop',
......
......@@ -24,6 +24,9 @@ use Drupal\views\ViewExecutable;
* },
* context_requirements = {
* "views:row"
* },
* context_definitions = {
* "entity" = @ContextDefinition("entity:view", label = @Translation("View"))
* }
* )
*/
......
......@@ -21,8 +21,11 @@ use Drupal\Core\Form\FormStateInterface;
* "views"
* },
* context_requirements = {
* "views:style",
* "views:group"
* "views:style",
* "views:group"
* },
* context_definitions = {
* "entity" = @ContextDefinition("entity:view", label = @Translation("View"))
* }
* )
*/
......
......@@ -19,6 +19,9 @@ namespace Drupal\ui_patterns_views\Plugin\UiPatterns\Source;
* },
* context_requirements = {
* "views:style",
* },
* context_definitions = {
* "entity" = @ContextDefinition("entity:view", label = @Translation("View"))
* }
*
* )
......
......@@ -12,11 +12,14 @@ use Drupal\views\ViewExecutable;
* @Source(
* id = "view_title",
* label = @Translation("View title"),
* description = @Translation("The title of the view."),
* description = @Translation("The title of the view."),
* prop_types = {
* "string"
* },
* )
* "string"
* },
* context_definitions = {
* "entity" = @ContextDefinition("entity:view", label = @Translation("View"))
* }
* )
*/
class ViewTitleSource extends ViewsSourceBase {
......
......@@ -7,7 +7,6 @@ namespace Drupal\ui_patterns_views\Plugin\UiPatterns\Source;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\ui_patterns\SourcePluginBase;
/**
......@@ -68,16 +67,4 @@ abstract class ViewsSourceBase extends SourcePluginBase {
return $output;
}
/**
* We add a constraint to require a view for those sources.
*/
public static function getDiscoveryContexts() : array {
// Context for views entity type.
$entity_context = EntityContextDefinition::fromEntityTypeId('view')
->setLabel('view');
return [
'entity' => $entity_context,
];
}
}
......@@ -148,7 +148,7 @@ class ComponentStyle extends StylePluginBase {
$this->removeGroupTitleSource($slots["sources"]);
}
}
unset($slots, $sources);
unset($slots);
// Set value inside form state.
$form_state->setValue('style_options', $style_option);
$user_input = $form_state->getUserInput();
......@@ -162,11 +162,12 @@ class ComponentStyle extends StylePluginBase {
foreach ($slots as &$sources) {
$this->removeGroupTitleSource($sources);
}
unset($sources);
}
unset($slots);
$user_input['style_options'] = $style_option_input;
$form_state->setUserInput($user_input);
}
unset($slots, $sources);
return $group_title;
}
......
......@@ -11,7 +11,7 @@ use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContext;
use Drupal\Core\Plugin\PluginBase;
use Drupal\ui_patterns\SourcePluginBase;
use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
use Drupal\views\ViewExecutable;
/**
......@@ -50,7 +50,7 @@ class UiPatternsViewsManager {
if (is_array($more_context_requirements) && (count($more_context_requirements) > 0)) {
$context_requirements = array_merge($context_requirements, $more_context_requirements);
}
$context_source = SourcePluginBase::addRequirementsToContext($context_source, $context_requirements);
$context_source = RequirementsContext::addToContext($context_requirements, $context_source);
// Build context views id.
$context_id = ContextDefinition::create('string');
$context_id->setLabel("views_id");
......
......@@ -34,4 +34,11 @@ final class Source extends Plugin {
*/
public $context_requirements = [];
/**
* An array of metadata.
*
* @var array<string, mixed>
*/
public $metadata = [];
}
......@@ -42,7 +42,8 @@ use Drupal\Core\Plugin\Context\ContextDefinition;
*
* Additional Configuration:
*
* '#component_id' => Optional Component Id. If not set a component selector is set.
* '#component_id' => Optional Component Id.
* If unset a component selector is set.
* '#source_contexts' => The context of the sources.
* '#tag_filter' => Filter sources based on this tags.
*
......@@ -223,7 +224,7 @@ class ComponentForm extends ComponentFormBase {
'#type' => 'component_slots_form',
'#component_id' => $component_id,
'#source_contexts' => $element['#source_contexts'],
'#tag_filter' =>$element['#tag_filter'],
'#tag_filter' => $element['#tag_filter'],
'#ajax_url' => $element['#ajax_url'],
'#access' => $element['#render_slots'] ?? TRUE,
'#default_value' => [
......@@ -241,7 +242,7 @@ class ComponentForm extends ComponentFormBase {
'#type' => 'component_props_form',
'#component_id' => $component_id,
'#source_contexts' => $element['#source_contexts'],
'#tag_filter' =>$element['#tag_filter'],
'#tag_filter' => $element['#tag_filter'],
'#ajax_url' => $element['#ajax_url'],
'#access' => $element['#render_props'] ?? TRUE,
'#default_value' => [
......
......@@ -36,12 +36,13 @@ use Drupal\ui_patterns\SourcePluginBase;
*
* Configuration:
*
* '#component_id' => Optional Component ID. A slot can rendered without knowing any context.
* '#slot_id' => Optional Slot ID.
* '#source_contexts' => The context of the sources.
* '#tag_filter' => Filter sources based on these tags.
* '#display_remove' => Display or hide the remove button. Default = true
* '#cardinality_multiple' => Allow or disallow multiple slot items
* '#component_id' =>Optional Component ID.
* A slot can rendered without knowing any context.
* '#slot_id' =>Optional Slot ID.
* '#source_contexts' =>The context of the sources.
* '#tag_filter' =>Filter sources based on these tags.
* '#display_remove' =>Display or hide the remove button. Default = true
* '#cardinality_multiple' =>Allow or disallow multiple slot items
*
* @FormElement("component_slot_form")
*/
......@@ -91,7 +92,7 @@ class ComponentSlotForm extends ComponentFormBase {
/** @var \Drupal\ui_patterns\PropTypePluginManager $prop_type_manager */
$prop_type_manager = \Drupal::service("plugin.manager.ui_patterns_prop_type");
$definition = [
'ui_patterns' => $prop_type_manager->createInstance('slot', [])
'ui_patterns' => $prop_type_manager->createInstance('slot', []),
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment