first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

26
core/modules/sdc/README.txt Executable file
View File

@@ -0,0 +1,26 @@
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.

14
core/modules/sdc/sdc.info.yml Executable file
View File

@@ -0,0 +1,14 @@
name: Single-Directory Components
type: module
description: 'Allows discovery and rendering of self-contained UI components.'
# version: VERSION
package: Core (Experimental)
lifecycle: deprecated
lifecycle_link: 'https://www.drupal.org/docs/core-modules-and-themes/deprecated-and-obsolete#s-understanding-deprecated-extensions'
dependencies:
- drupal:serialization
# Information added by Drupal.org packaging script on 2024-07-04
version: '10.3.1'
project: 'drupal'
datestamp: 1720094222

64
core/modules/sdc/sdc.module Executable file
View File

@@ -0,0 +1,64 @@
<?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

@@ -0,0 +1,44 @@
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

@@ -0,0 +1,45 @@
<?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);
}
}