Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 3.x
  • 8.x-1.x
  • 8.x-2.x
  • 3.0.0-alpha1
  • 3.0.0-alpha2
  • 3.0.0-alpha3
  • 3.0.0-beta1
  • 3.0.0-beta2
  • 3.0.0-beta3
  • 3.1.0
  • 8.x-1.0
  • 8.x-1.1
  • 8.x-1.1-alpha1
  • 8.x-1.1-alpha2
  • 8.x-2.0
  • 8.x-2.0-beta1
  • 8.x-2.0-beta2
  • 8.x-2.0-beta3
  • 8.x-2.1
  • 8.x-2.2
  • 8.x-2.3
  • 8.x-2.4
22 results

Target

Select target project
  • project/components
  • issue/components-3178770
  • issue/components-3151880
  • issue/components-3190898
  • issue/components-3190990
  • issue/components-3191428
  • issue/components-3278923
  • issue/components-3191392
  • issue/components-3191790
  • issue/components-3191956
  • issue/components-3191968
  • issue/components-3192012
  • issue/components-3192697
  • issue/components-3192979
  • issue/components-3165589
  • issue/components-2909781
  • issue/components-3195720
  • issue/components-3195721
  • issue/components-3278984
  • issue/components-3209440
  • issue/components-3209575
  • issue/components-3209547
  • issue/components-3209487
  • issue/components-3210853
  • issue/components-3210928
  • issue/components-3107993
  • issue/components-3216184
  • issue/components-3299045
  • issue/components-3204256
  • issue/components-3362347
  • issue/components-3371808
  • issue/components-3390999
  • issue/components-2707849
  • issue/components-3278970
  • issue/components-3422650
  • issue/components-3428529
  • issue/components-3464819
  • issue/components-3469223
  • issue/components-3473188
  • issue/components-3348158
  • issue/components-3500811
  • issue/components-3519047
42 results
Select Git revision
  • 3.x
  • 3464819-add-gitlab-ci
  • 8.x-1.x
  • 8.x-2.x
  • 3.0.0-alpha1
  • 3.0.0-alpha2
  • 3.0.0-alpha3
  • 3.0.0-beta1
  • 3.0.0-beta2
  • 3.0.0-beta3
  • 8.x-1.0
  • 8.x-1.1
  • 8.x-1.1-alpha1
  • 8.x-1.1-alpha2
  • 8.x-2.0
  • 8.x-2.0-beta1
  • 8.x-2.0-beta2
  • 8.x-2.0-beta3
  • 8.x-2.1
  • 8.x-2.2
  • 8.x-2.3
  • 8.x-2.4
22 results
Show changes
Commits on Source (6)
Showing
with 309 additions and 230 deletions
.DS_Store
/.idea
composer.lock
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
variables:
_CSPELL_WORDS: 'Albin'
OPT_IN_TEST_NEXT_MAJOR: 1
phpcs:
allow_failure: false
phpstan:
allow_failure: false
phpstan (next major):
allow_failure: true
phpstan (next minor):
allow_failure: true
# Components!
The Components module makes it easier for a theme to organize its components.
It allows themes (and modules) to register Twig namespaces and provides some
additional Twig functions and filters for use in Drupal templates.
For a full description of the module, visit the
[project page](https://www.drupal.org/project/components).
Submit bug reports and feature suggestions, or track changes in the
[issue queue](https://www.drupal.org/project/issues/components?categories=All).
## Table of contents
- Features
- Installation
- Requirements
- Configuration
- Usage
- Maintainers
## Features
- Offers feature called Template namespaces.
## Installation
Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
## Requirements
This module requires no modules outside of Drupal core.
## Configuration
This modules doesn't have any configuration. It allows user to add the template
namespaces.
## Maintainers
- John Albin Wilkins - [JohnAlbin](https://www.drupal.org/u/johnalbin)
- Rob Loach - [RobLoach](https://www.drupal.org/u/robloach)
\ No newline at end of file
type: module
name: Components
description: 'Registers folders of components defined by your theme or module as Twig namespaces'
core_version_requirement: ^9 || ^10
core_version_requirement: ^10.2 || ^11
php: 8.1
components:
# Allow themes to reuse this module's default namespace, "components".
allow_default_namespace_reuse: true
services:
components.registry:
class: Drupal\components\Template\ComponentsRegistry
arguments: ['@extension.list.module', '@extension.list.theme', '@module_handler', '@theme.manager', '@cache.default', '@file_system']
arguments: ['@extension.list.module', '@extension.list.theme', '@module_handler', '@theme.manager', '@cache.bootstrap', '@file_system']
components.twig.loader:
class: Drupal\components\Template\Loader\ComponentsLoader
......
......@@ -11,6 +11,6 @@
}
],
"require": {
"drupal/core": "^9 || ^10"
"drupal/core": "^10.2 || ^11"
}
}
......@@ -92,7 +92,7 @@ class ComponentsRegistry {
ModuleHandlerInterface $moduleHandler,
ThemeManagerInterface $themeManager,
CacheBackendInterface $cache,
FileSystemInterface $fileSystem
FileSystemInterface $fileSystem,
) {
$this->moduleExtensionList = $moduleExtensionList;
$this->themeExtensionList = $themeExtensionList;
......@@ -147,7 +147,7 @@ class ComponentsRegistry {
// Get a listing of all Twig files in the namespace path.
$files = $this->fileSystem->scanDirectory($nameSpacePath, $regex);
}
catch (NotRegularDirectoryException $exception) {
catch (NotRegularDirectoryException) {
$this->logWarning(sprintf('The "@%s" namespace contains a path, "%s", that is not a directory.',
$nameSpace,
$nameSpacePath,
......
......@@ -6,6 +6,8 @@ use Drupal\components\Template\ComponentsRegistry;
use Twig\Error\LoaderError;
use Twig\Loader\FilesystemLoader;
// cspell:ignore mycomponents mythemeComponents
/**
* Loads namespaced templates from the filesystem.
*
......
......@@ -7,6 +7,8 @@ use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
// cspell:ignore domo ponycorn
/**
* A class providing components' Twig extensions.
*/
......@@ -17,7 +19,7 @@ class TwigExtension extends AbstractExtension {
*/
public function getFunctions(): array {
return [
new TwigFunction('template', [$this, 'template'], ['is_variadic' => TRUE]),
new TwigFunction('template', $this->template(...), ['is_variadic' => TRUE]),
];
}
......@@ -124,7 +126,7 @@ class TwigExtension extends AbstractExtension {
* When $element is not an array or "Traversable".
*/
public static function recursiveMergeFilter($element, $array): array {
if (!twig_test_iterable($element)) {
if (!is_iterable($element)) {
throw new RuntimeError(sprintf('The recursive_merge filter only works on arrays or "Traversable" objects, got "%s".', gettype($element)));
}
......@@ -160,7 +162,7 @@ class TwigExtension extends AbstractExtension {
* When $element is not an array or "Traversable".
*/
public static function setFilter($element, string $at, $value) {
if (!twig_test_iterable($element)) {
if (!is_iterable($element)) {
throw new RuntimeError(sprintf('The "set" filter only works on arrays or "Traversable" objects, got "%s".', gettype($element)));
}
......@@ -202,7 +204,7 @@ class TwigExtension extends AbstractExtension {
* When $element is not an array or "Traversable".
*/
public static function addFilter($element, string $at, $value = NULL, $values = NULL) {
if (!twig_test_iterable($element)) {
if (!is_iterable($element)) {
throw new RuntimeError(sprintf('The "add" filter only works on arrays or "Traversable" objects, got "%s".', gettype($element)));
}
......
<?php
/**
* @file
* Components test module.
*/
declare(strict_types=1);
/**
* @file
* Test module.
......
<?php
/**
* @file
* Components Twig extension test module.
*/
declare(strict_types=1);
/**
* @file
* Test module.
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\components\Functional;
use Drupal\Tests\BrowserTestBase;
......@@ -39,24 +41,19 @@ class ComponentsTest extends BrowserTestBase {
* The rendered string output (typically HTML).
*/
protected function render(array &$elements): string {
return $this->container->get('renderer')->renderRoot($elements);
return (string) $this->container->get('renderer')->renderRoot($elements);
}
/**
* Ensures component templates can be loaded inside a Drupal instance.
*/
public function testLoadTemplate() {
try {
$element = [
// The templates/components-test.html.twig file determines which
// templates are loaded.
'#theme' => 'components_test',
];
$result = $this->render($element);
}
catch (\Exception $e) {
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$element = [
// The templates/components-test.html.twig file determines which
// templates are loaded.
'#theme' => 'components_test',
];
$result = $this->render($element);
// The following templates are in paths defined in .info namespace
// definitions.
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\components\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
......@@ -36,7 +38,7 @@ abstract class ComponentsKernelTestBase extends KernelTestBase {
throw new \Exception(__METHOD__ . ' requires system module to be installed.');
}
return $this->container->get('renderer')->renderRoot($elements);
return (string) $this->container->get('renderer')->renderRoot($elements);
}
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\components\Kernel;
/**
......@@ -38,6 +40,8 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
$result = $this->render($element);
}
catch (\Exception $e) {
// @todo Fix in https://www.drupal.org/project/components/issues/3473207
// @phpstan-ignore method.notFound
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertStringContainsString('<ul><li>first item</li><li>second item</li></ul>', $result);
......@@ -70,6 +74,8 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
$result = $this->render($element);
}
catch (\Exception $e) {
// @todo Fix in https://www.drupal.org/project/components/issues/3473207
// @phpstan-ignore method.notFound
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertStringContainsString($expected, $result);
......@@ -80,7 +86,7 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
*
* @see testRecursiveMergeFilter()
*/
public function providerTestRecursiveMergeFilter(): array {
public static function providerTestRecursiveMergeFilter(): array {
return [
'Uses positional arguments' => [
'theme_hook' => 'components_twig_extension_test_recursive_merge_filter',
......@@ -120,6 +126,8 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
$result = $this->render($element);
}
catch (\Exception $e) {
// @todo Fix in https://www.drupal.org/project/components/issues/3473207
// @phpstan-ignore method.notFound
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertStringContainsString($expected, $result);
......@@ -130,7 +138,7 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
*
* @see testSetFilter()
*/
public function providerTestSetFilter(): array {
public static function providerTestSetFilter(): array {
return [
'Uses positional arguments' => [
'theme_hook' => 'components_twig_extension_test_set_filter',
......@@ -169,6 +177,8 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
$result = $this->render($element);
}
catch (\Exception $e) {
// @todo Fix in https://www.drupal.org/project/components/issues/3473207
// @phpstan-ignore method.notFound
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertStringContainsString($expected, $result);
......@@ -179,7 +189,7 @@ class TwigExtensionTest extends ComponentsKernelTestBase {
*
* @see testAddFilter()
*/
public function providerTestAddFilter(): array {
public static function providerTestAddFilter(): array {
return [
'Uses positional arguments' => [
'theme_hook' => 'components_twig_extension_test_add_filter',
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\components\Unit;
use Drupal\components\Template\Loader\ComponentsLoader;
......@@ -68,21 +70,21 @@ class ComponentsLoaderTest extends UnitTestCase {
$result = $this->invokeProtectedMethod($this->systemUnderTest, 'findTemplate', $name, $throw);
if (!$exception) {
$this->assertEquals($expected, $result, $this->getName());
$this->assertEquals($expected, $result);
}
}
catch (\Exception $e) {
if ($exception) {
$this->assertEquals($exception, $e->getMessage(), $this->getName());
$this->assertEquals($exception, $e->getMessage());
$exception = '';
}
else {
$this->fail('No exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
$this->fail('No exception expected; "' . $e->getMessage() . '"');
}
}
if ($exception) {
$this->fail('No exception thrown, but "' . $exception . '" was expected during: ' . $this->getName());
$this->fail('No exception thrown, but "' . $exception . '"');
}
}
......@@ -91,7 +93,7 @@ class ComponentsLoaderTest extends UnitTestCase {
*
* @see testFindTemplate()
*/
public function providerTestFindTemplate(): array {
public static function providerTestFindTemplate(): array {
return [
'error when template name has no @' => [
'name' => 'n/template.twig',
......@@ -176,7 +178,7 @@ class ComponentsLoaderTest extends UnitTestCase {
$this->systemUnderTest = new ComponentsLoader($componentsRegistry);
$result = $this->systemUnderTest->exists($template);
$this->assertEquals($expected, $result, $this->getName());
$this->assertEquals($expected, $result);
}
/**
......@@ -184,7 +186,7 @@ class ComponentsLoaderTest extends UnitTestCase {
*
* @see testExists()
*/
public function providerTestExists(): array {
public static function providerTestExists(): array {
return [
'confirms a template does exist' => [
'template' => '@ns/example-exists.twig',
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\components\Unit;
use Drupal\components\Template\TwigExtension;
......@@ -81,15 +83,9 @@ class TwigExtensionFiltersTest extends UnitTestCase {
* @dataProvider providerTestRecursiveMergeFilter
*/
public function testRecursiveMergeFilter(array $element, array $value, array $expected) {
$result = NULL;
try {
$result = TwigExtension::recursiveMergeFilter($element, $value);
}
catch (\Exception $e) {
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertEquals($expected, $result, $this->getName());
$this->assertEquals(array_replace_recursive($element, $value), $result, $this->getName());
$result = TwigExtension::recursiveMergeFilter($element, $value);
$this->assertEquals($expected, $result);
$this->assertEquals(array_replace_recursive($element, $value), $result);
}
/**
......@@ -97,7 +93,7 @@ class TwigExtensionFiltersTest extends UnitTestCase {
*
* @see testRecursiveMergeFilter()
*/
public function providerTestRecursiveMergeFilter(): array {
public static function providerTestRecursiveMergeFilter(): array {
return [
'Recursively sets values' => [
'element' => [
......@@ -171,14 +167,8 @@ class TwigExtensionFiltersTest extends UnitTestCase {
* @dataProvider providerTestSetFilter
*/
public function testSetFilter(array $element, string $at, $value, array $expected) {
$result = NULL;
try {
$result = TwigExtension::setFilter($element, $at, $value);
}
catch (\Exception $e) {
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertEquals($expected, $result, $this->getName());
$result = TwigExtension::setFilter($element, $at, $value);
$this->assertEquals($expected, $result);
}
/**
......@@ -186,7 +176,7 @@ class TwigExtensionFiltersTest extends UnitTestCase {
*
* @see testSetFilter()
*/
public function providerTestSetFilter(): array {
public static function providerTestSetFilter(): array {
return [
'Sets a new value' => [
'element' => [
......@@ -286,6 +276,8 @@ class TwigExtensionFiltersTest extends UnitTestCase {
$result = TwigExtension::addFilter($element, $at, $value);
}
catch (\Exception $e) {
// @todo Fix in https://www.drupal.org/project/components/issues/3473207
// @phpstan-ignore method.notFound
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertEquals($expected, $result, 'Failed to replace a value.');
......@@ -296,7 +288,7 @@ class TwigExtensionFiltersTest extends UnitTestCase {
*
* @see testAddFilter()
*/
public function providerTestAddFilter(): array {
public static function providerTestAddFilter(): array {
return [
'replacing a value' => [
'at' => 'element.#attributes.id',
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\components\Unit;
use Drupal\components\Template\TwigExtension;
......@@ -103,7 +105,7 @@ class TwigExtensionFunctionsTest extends UnitTestCase {
string $template,
array $variables,
array $expected,
string $rendered_output
string $rendered_output,
) {
$this->renderer
->expects($this->exactly(1))
......@@ -111,14 +113,8 @@ class TwigExtensionFunctionsTest extends UnitTestCase {
->with($expected)
->willReturn($rendered_output);
$result = NULL;
try {
$result = $this->twigEnvironment->render($template, $variables);
}
catch (\Exception $e) {
$this->fail('No Exception expected; "' . $e->getMessage() . '" thrown during: ' . $this->getName());
}
$this->assertEquals($rendered_output, $result, $this->getName());
$result = $this->twigEnvironment->render($template, $variables);
$this->assertEquals($rendered_output, $result);
}
/**
......@@ -126,7 +122,7 @@ class TwigExtensionFunctionsTest extends UnitTestCase {
*
* @see testTemplate()
*/
public function providerTestTemplate(): array {
public static function providerTestTemplate(): array {
$link = [
'#type' => 'link',
'#title' => 'example link',
......
name: Components test base theme
type: theme
base theme: stable9
core_version_requirement: ^9 || ^10
core_version_requirement: ^9 || ^10 || ^11
description: Theme for testing Components functionality.
components:
namespaces:
......
name: Components test theme
type: theme
base theme: components_test_base_theme
core_version_requirement: ^9 || ^10
core_version_requirement: ^9 || ^10 || ^11
description: Theme for testing Components functionality.
components:
namespaces:
......