Issue #3409456 by plopesc, smustgrave, quietone, e0ipso, catch: Remove SDC deprecated code before 11.0.0

merge-requests/6955/merge
Alex Pott 2024-04-03 11:41:05 +01:00
parent 8fe4fb0622
commit b8037acd20
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
8 changed files with 14 additions and 193 deletions

View File

@ -95,10 +95,10 @@ class LibraryDiscoveryParser {
* The libraries directory file finder. * The libraries directory file finder.
* @param \Drupal\Core\Extension\ExtensionPathResolver $extension_path_resolver * @param \Drupal\Core\Extension\ExtensionPathResolver $extension_path_resolver
* The extension path resolver. * The extension path resolver.
* @param \Drupal\Core\Theme\ComponentPluginManager|null $component_plugin_manager * @param \Drupal\Core\Theme\ComponentPluginManager $component_plugin_manager
* The component plugin manager. * The component plugin manager.
*/ */
public function __construct($root, ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager, StreamWrapperManagerInterface $stream_wrapper_manager, LibrariesDirectoryFileFinder $libraries_directory_file_finder, ExtensionPathResolver $extension_path_resolver, ?ComponentPluginManager $component_plugin_manager = NULL) { public function __construct($root, ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager, StreamWrapperManagerInterface $stream_wrapper_manager, LibrariesDirectoryFileFinder $libraries_directory_file_finder, ExtensionPathResolver $extension_path_resolver, ComponentPluginManager $component_plugin_manager) {
$this->root = $root; $this->root = $root;
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
$this->themeManager = $theme_manager; $this->themeManager = $theme_manager;
@ -106,10 +106,6 @@ class LibraryDiscoveryParser {
$this->librariesDirectoryFileFinder = $libraries_directory_file_finder; $this->librariesDirectoryFileFinder = $libraries_directory_file_finder;
$this->extensionPathResolver = $extension_path_resolver; $this->extensionPathResolver = $extension_path_resolver;
$this->fileCache = FileCacheFactory::get('library_parser'); $this->fileCache = FileCacheFactory::get('library_parser');
if (!isset($component_plugin_manager)) {
@trigger_error('Calling ' . __METHOD__ . '() without the $component_plugin_manager argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3410260', E_USER_DEPRECATED);
$component_plugin_manager = \Drupal::service('plugin.manager.sdc');
}
$this->componentPluginManager = $component_plugin_manager; $this->componentPluginManager = $component_plugin_manager;
} }

View File

@ -44,12 +44,6 @@ final class ComponentsTwigExtension extends AbstractExtension {
return [ return [
new TwigFunction('add_component_context', [$this, 'addAdditionalContext'], ['needs_context' => TRUE]), new TwigFunction('add_component_context', [$this, 'addAdditionalContext'], ['needs_context' => TRUE]),
new TwigFunction('validate_component_props', [$this, 'validateProps'], ['needs_context' => TRUE]), new TwigFunction('validate_component_props', [$this, 'validateProps'], ['needs_context' => TRUE]),
// @todo remove in drupal:11.0.0.
// @see https://www.drupal.org/project/drupal/issues/3409456.
// Start of BC layer.
new TwigFunction('sdc_additional_context', [$this, 'addAdditionalContext'], ['needs_context' => TRUE, 'deprecated' => '10.3.0', 'alternative' => 'add_component_context']),
new TwigFunction('sdc_validate_props', [$this, 'validateProps'], ['needs_context' => TRUE, 'deprecated' => '10.3.0', 'alternative' => 'validate_component_props']),
// End of BC layer.
]; ];
} }

View File

@ -1,26 +0,0 @@
The API of Single Directory Components includes:
- The component plugin manager (the service with name plugin.manager.sdc).
This service will be needed by modules that need to find and instantiate
components.
- The exceptions. Code using Single Directory Components can rely, and extend,
the exceptions provided by the experimental module.
- The folder structure of a component and the naming conventions of the files
in it.
- The structure of the component metadata (the my-component.component.yml).
Note that the metadata of the component is described, and optionally
validated, by the schema in metadata.schema.json (this file is for internal validation and not part of the API).
- The render element and its class \Drupal\Core\Render\Element\ComponentElement.
- The naming convention for the ID when using Twig's include, embed, and
extends. This naming convention is [module/theme]:[component machine name].
See the example below.
{% embed 'my-theme:my-component' with { prop1: content.field_for_prop1 } %}
{% block slot1 %}
{{ content|without('field_for_prop1') }}
{% endblock %}
{% endembed %}
This way of specifying the component for Twig's include, embed, and
extends('my-theme:my-component' in the example) will not change, as it is
considered an API.

View File

@ -3,7 +3,8 @@ type: module
description: 'Allows discovery and rendering of self-contained UI components.' description: 'Allows discovery and rendering of self-contained UI components.'
version: VERSION version: VERSION
package: Core (Experimental) package: Core (Experimental)
lifecycle: deprecated lifecycle: obsolete
lifecycle_link: 'https://www.drupal.org/docs/core-modules-and-themes/deprecated-and-obsolete#s-understanding-deprecated-extensions' lifecycle_link: https://www.drupal.org/node/3223395#s-sdc
dependencies: dependencies:
- drupal:serialization - drupal:serialization
hidden: true

View File

@ -1,64 +0,0 @@
<?php
/**
* @file
* Module implementation file.
*/
use Drupal\Core\Theme\ComponentPluginManager;
use Drupal\Core\Plugin\Component;
@class_alias('Drupal\Core\Render\Element', 'Drupal\sdc\Utilities');
@class_alias('Drupal\Core\Render\Element\ComponentElement', 'Drupal\sdc\Element\ComponentElement');
@class_alias('Drupal\Core\Render\Component\Exception\ComponentNotFoundException', 'Drupal\sdc\Exception\ComponentNotFoundException');
@class_alias('Drupal\Core\Render\Component\Exception\IncompatibleComponentSchema', 'Drupal\sdc\Exception\IncompatibleComponentSchema');
@class_alias('Drupal\Core\Render\Component\Exception\InvalidComponentDataException', 'Drupal\sdc\Exception\InvalidComponentDataException');
@class_alias('Drupal\Core\Render\Component\Exception\InvalidComponentException', 'Drupal\sdc\Exception\InvalidComponentException');
@class_alias('Drupal\Core\Theme\Component\ComponentMetadata', 'Drupal\sdc\Component\ComponentMetadata');
@class_alias('Drupal\Core\Theme\Component\ComponentValidator', 'Drupal\sdc\Component\ComponentValidator');
@class_alias('Drupal\Core\Theme\Component\SchemaCompatibilityChecker', 'Drupal\sdc\Component\SchemaCompatibilityChecker');
@class_alias('Drupal\Core\Plugin\Component', 'Drupal\sdc\Plugin\Component');
@class_alias('Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery', 'Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataDiscovery');
@class_alias('Drupal\Core\Plugin\Discovery\DirectoryWithMetadataPluginDiscovery', 'Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataPluginDiscovery');
@class_alias('Drupal\Core\Plugin\Discovery\RegexRecursiveFilterIterator', 'Drupal\sdc\Plugin\Discovery\RegexRecursiveFilterIterator');
@class_alias('Drupal\Core\Template\ComponentNodeVisitor', 'Drupal\sdc\Twig\ComponentNodeVisitor');
@class_alias('Drupal\Core\Template\Loader\ComponentLoader', 'Drupal\sdc\Twig\TwigComponentLoader');
@class_alias('Drupal\Core\Theme\ComponentNegotiator', 'Drupal\sdc\ComponentNegotiator');
@class_alias('Drupal\Core\Theme\ComponentPluginManager', 'Drupal\sdc\ComponentPluginManager');
@class_alias('Drupal\Core\Theme\ExtensionType', 'Drupal\sdc\ExtensionType');
/**
* Implements hook_library_info_build().
*/
function sdc_library_info_build() {
$deprecation_message = 'The %library_id% asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. Use the core/components.[component-id] library instead. See https://www.drupal.org/node/3410260';
// Iterate over all the components to get the CSS and JS files.
$plugin_manager = \Drupal::service('plugin.manager.sdc');
assert($plugin_manager instanceof ComponentPluginManager);
$components = $plugin_manager->getAllComponents();
// Generate backwards compatible deprecated libraries that depend on the new
// library name scheme.
$libraries = array_reduce(
$components,
static function (array $libraries, Component $component) use ($deprecation_message) {
// The library name is something like core/components.my-theme--my-comp.
$library_name = $component->getLibraryName();
// The library ID is something like my-theme--my-comp.
$library_id = str_replace('core/components.', '', $library_name);
// Adding these libraries will result in the old 'sdc/my-theme--my-comp'.
return array_merge($libraries, [
$library_id => [
'dependencies' => [$library_name],
'deprecated' => $deprecation_message,
],
]);
},
[]
);
// Alias the library sdc/all to core/components.all.
$libraries['all'] = [
'dependencies' => ['core/components.all'],
'deprecated' => 'The %library_id% asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. Use the core/components.all library instead. See https://www.drupal.org/node/3410260',
];
return $libraries;
}

View File

@ -1,44 +0,0 @@
services:
_defaults:
public: false
# This service is deprecated, use the one defined in core instead.
Drupal\sdc\Twig\TwigComponentLoader:
alias: 'Drupal\Core\Template\Loader\ComponentLoader'
deprecated:
package: 'drupal/core'
version: '10.3.0'
message: The "%alias_id%" service is deprecated since drupal/core 10.3.0 and will be removed in 11.0.
# This service is deprecated, use the one defined in core instead.
Drupal\sdc\ComponentNegotiator:
alias: 'Drupal\Core\Theme\ComponentNegotiator'
deprecated:
package: 'drupal/core'
version: '10.3.0'
message: The "%alias_id%" service is deprecated since drupal/core 10.3.0 and will be removed in 11.0.
# This service defines the deprecated twig functions related to SDC.
# Use the ones defined in core instead.
Drupal\sdc\Twig\TwigExtension:
alias: 'Drupal\Core\Template\ComponentsTwigExtension'
deprecated:
package: 'drupal/core'
version: '10.3.0'
message: The "%alias_id%" service is deprecated since drupal/core 10.3.0 and will be removed in 11.0.
# This service is deprecated, use the one defined in core instead.
Drupal\sdc\Component\SchemaCompatibilityChecker:
alias: 'Drupal\Core\Theme\Component\SchemaCompatibilityChecker'
deprecated:
package: 'drupal/core'
version: '10.3.0'
message: The "%alias_id%" service is deprecated since drupal/core 10.3.0 and will be removed in 11.0.
# This service is deprecated, use the one defined in core instead.
Drupal\sdc\Component\ComponentValidator:
alias: 'Drupal\Core\Theme\Component\ComponentValidator'
deprecated:
package: 'drupal/core'
version: '10.3.0'
message: The "%alias_id%" service is deprecated since drupal/core 10.3.0 and will be removed in 11.0.

View File

@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sdc\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the correct rendering of components.
*
* @group sdc
* @group legacy
*
* @internal
*/
final class LibrariesBCLayerTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['system', 'sdc', 'sdc_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'sdc_theme_test';
/**
* Tests libraryOverrides.
*/
public function testLibraryBCLayer(): void {
$this->expectDeprecation('The module \'sdc\' is deprecated. See https://www.drupal.org/docs/core-modules-and-themes/deprecated-and-obsolete#s-understanding-deprecated-extensions');
$this->expectDeprecation('The sdc/sdc_theme_test--my-card asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. Use the core/components.[component-id] library instead. See https://www.drupal.org/node/3410260');
$build = [
'#type' => 'inline_template',
'#template' => "<h2>Foo</h2>{{ attach_library('sdc/sdc_theme_test--my-card') }}",
];
\Drupal::state()->set('sdc_test_component', $build);
$output = $this->drupalGet('sdc-test-component');
// Ensure the CSS from the component is properly added to the page.
$this->assertStringContainsString('my-card.css', $output);
}
}

View File

@ -223,3 +223,12 @@ function system_post_update_set_cron_logging_setting_to_boolean(): void {
$config->set('logging', (bool) $logging)->save(); $config->set('logging', (bool) $logging)->save();
} }
} }
/**
* Uninstall the sdc module if installed.
*/
function system_post_update_sdc_uninstall() {
if (\Drupal::moduleHandler()->moduleExists('sdc')) {
\Drupal::service('module_installer')->uninstall(['sdc'], FALSE);
}
}