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

Issue #3474113 by christian.wiedemann, just_like_good_vibes: [2.0.0-beta2]...

Issue #3474113 by christian.wiedemann, just_like_good_vibes: [2.0.0-beta2] Missing dependencies when configuring entity view displays
parent c4f9072c
Branches
Tags
1 merge request!209Added component dependencies
Pipeline #282258 passed with warnings
......@@ -5,12 +5,14 @@ declare(strict_types=1);
namespace Drupal\ui_patterns;
use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Plugin\Component;
use Drupal\Core\Theme\Component\ComponentValidator;
use Drupal\Core\Theme\Component\SchemaCompatibilityChecker;
use Drupal\Core\Theme\ComponentNegotiator;
......@@ -311,4 +313,33 @@ class ComponentPluginManager extends SdcPluginManager implements CategorizingPlu
return $extension;
}
/**
* Calculate dependencies of a component.
*
* @param \Drupal\Core\Plugin\Component $component
* The component.
*
* @return array
* Config Dependencies.
*/
public function calculateDependencies(Component $component) : array {
$definition = $component->getPluginDefinition();
$provider = ($definition instanceof PluginDefinitionInterface) ? $definition->getProvider() : (string) ($definition["provider"] ?? '');
$extension_type = $this->getExtensionType($provider);
return (empty($provider) || empty($extension_type)) ? [] : [$extension_type => [$provider]];
}
/**
* Get extension type (theme or module).
*/
protected function getExtensionType(string $extension): string {
if ($this->moduleHandler->moduleExists($extension)) {
return 'module';
}
if ($this->themeHandler->themeExists($extension)) {
return 'theme';
}
return '';
}
}
......@@ -7,6 +7,7 @@ namespace Drupal\ui_patterns\Element;
use Drupal\Core\Plugin\Component;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Theme\ComponentPluginManager;
use Drupal\ui_patterns\ComponentPluginManager as UiPatternsComponentPluginManager;
use Drupal\ui_patterns\PropTypeAdapterPluginManager;
use Drupal\ui_patterns\PropTypePluginManager;
use Drupal\ui_patterns\SourceInterface;
......@@ -198,10 +199,35 @@ class ComponentElementBuilder implements TrustedCallbackInterface {
* An array of dependencies keyed by the type of dependency.
*
* @see \Drupal\Core\Config\Entity\ConfigDependencyManager
*
* @throws \Drupal\Core\Render\Component\Exception\ComponentNotFoundException
*/
public function calculateComponentDependencies(?string $component_id = NULL, array $configuration = [], array $contexts = []) : array {
$dependencies = [];
$component = $this->componentPluginManager->find($component_id ?? $configuration['component_id']);
$dependencies = [];
if ($this->componentPluginManager instanceof UiPatternsComponentPluginManager) {
SourcePluginBase::mergeConfigDependencies($dependencies, $this->componentPluginManager->calculateDependencies($component));
}
SourcePluginBase::mergeConfigDependencies($dependencies, $this->calculateComponentDependenciesProps($component, $configuration, $contexts));
SourcePluginBase::mergeConfigDependencies($dependencies, $this->calculateComponentDependenciesSlots($component, $configuration, $contexts));
return $dependencies;
}
/**
* Calculate a component dependencies for props.
*
* @param \Drupal\Core\Plugin\Component $component
* Component instance.
* @param array $configuration
* Component Configuration.
* @param array $contexts
* Contexts.
*
* @return array
* An array of dependencies keyed by the type of dependency.
*/
protected function calculateComponentDependenciesProps(Component $component, array $configuration = [], array $contexts = []) : array {
$dependencies = [];
$props = $component->metadata->schema['properties'] ?? [];
foreach ($props as $prop_id => $definition) {
if ($prop_id === 'variant') {
......@@ -211,6 +237,24 @@ class ComponentElementBuilder implements TrustedCallbackInterface {
SourcePluginBase::mergeConfigDependencies($dependencies, $source->calculateDependencies());
}
}
return $dependencies;
}
/**
* Calculate a component dependencies for slots.
*
* @param \Drupal\Core\Plugin\Component $component
* Component instance.
* @param array $configuration
* Component Configuration.
* @param array $contexts
* Contexts.
*
* @return array
* An array of dependencies keyed by the type of dependency.
*/
protected function calculateComponentDependenciesSlots(Component $component, array $configuration = [], array $contexts = []) : array {
$dependencies = [];
$slots = $component->metadata->slots ?? [];
foreach ($slots as $slot_id => $definition) {
$slot_configuration = $configuration['slots'][$slot_id] ?? [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment