diff --git a/core/lib/Drupal/Core/Layout/Annotation/Layout.php b/core/lib/Drupal/Core/Layout/Annotation/Layout.php index 68ff9d81b9..eae930cf4e 100644 --- a/core/lib/Drupal/Core/Layout/Annotation/Layout.php +++ b/core/lib/Drupal/Core/Layout/Annotation/Layout.php @@ -116,7 +116,7 @@ class Layout extends Plugin { * * @var string[][] optional * - * @see \Drupal\Core\Layout\Icon\IconGeneratorInterface::generate() + * @see \Drupal\Core\Layout\Icon\IconBuilderInterface::build() */ public $icon_map; diff --git a/core/lib/Drupal/Core/Layout/Icon/IconGeneratorInterface.php b/core/lib/Drupal/Core/Layout/Icon/IconBuilderInterface.php similarity index 86% rename from core/lib/Drupal/Core/Layout/Icon/IconGeneratorInterface.php rename to core/lib/Drupal/Core/Layout/Icon/IconBuilderInterface.php index e513266df6..de2f82a441 100644 --- a/core/lib/Drupal/Core/Layout/Icon/IconGeneratorInterface.php +++ b/core/lib/Drupal/Core/Layout/Icon/IconBuilderInterface.php @@ -3,12 +3,12 @@ namespace Drupal\Core\Layout\Icon; /** - * Provides an interface for generating layout icons. + * Provides an interface for building layout icons. */ -interface IconGeneratorInterface { +interface IconBuilderInterface { /** - * Generates a render array representation of an SVG based on an icon map. + * Builds a render array representation of an SVG based on an icon map. * * @param string[][] $icon_map * A two-dimensional array representing the visual output of the layout. @@ -34,7 +34,7 @@ * @return array * A render array representing a SVG icon. */ - public function generate(array $icon_map); + public function build(array $icon_map); /** * Sets the ID. @@ -60,7 +60,7 @@ public function setLabel($label); * Sets the width. * * @param int $width - * The width of the generated SVG. + * The width of the SVG. * * @return $this */ @@ -70,7 +70,7 @@ public function setWidth($width); * Sets the height. * * @param int $height - * The height of the generated SVG. + * The height of the SVG. * * @return $this */ diff --git a/core/lib/Drupal/Core/Layout/Icon/IconFactoryInterface.php b/core/lib/Drupal/Core/Layout/Icon/IconFactoryInterface.php deleted file mode 100644 index 63c8782ca0..0000000000 --- a/core/lib/Drupal/Core/Layout/Icon/IconFactoryInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -calculateSvgValues($icon_map, $this->width, $this->height, $this->strokeWidth, $this->padding); return $this->buildRenderArray($regions, $this->width, $this->height, $this->strokeWidth); } /** - * Generates a render array representation of an SVG. + * Builds a render array representation of an SVG. * * @param mixed[] $regions * An array keyed by region name, with each element containing the 'height', * 'width', and 'x' and 'y' offsets of each region. * @param int $width - * The width of the generated SVG. + * The width of the SVG. * @param int $height - * The height of the generated SVG. + * The height of the SVG. * @param int|null $stroke_width * The width of region borders. * @@ -142,11 +142,11 @@ protected function buildRenderArray(array $regions, $width, $height, $stroke_wid * @param string[][] $rows * A two-dimensional array representing the visual output of the layout. See * the documentation for the $icon_map parameter of - * \Drupal\Core\Layout\IconGeneratorInterface::generate(). + * \Drupal\Core\Layout\IconBuilderInterface::build(). * @param int $width - * The width of the generated SVG. + * The width of the SVG. * @param int $height - * The height of the generated SVG. + * The height of the SVG. * @param int $stroke_width * The width of region borders. * @param int $padding diff --git a/core/lib/Drupal/Core/Layout/Icon/SvgIconFactory.php b/core/lib/Drupal/Core/Layout/Icon/SvgIconFactory.php deleted file mode 100644 index b966095df0..0000000000 --- a/core/lib/Drupal/Core/Layout/Icon/SvgIconFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -getIconMap()) { - $icon_generator = $this->getIconGenerator() + $icon_builder = $this->getIconBuilder() ->setId($this->id()) ->setLabel($this->getLabel()) ->setWidth($width) ->setHeight($height) ->setPadding($padding) ->setStrokeWidth($stroke_width); - $icon = $icon_generator->generate($icon_map); + $icon = $icon_builder->build($icon_map); } return $icon; } /** - * Wraps the icon generator. + * Wraps the icon builder. * - * @return \Drupal\Core\Layout\Icon\IconGeneratorInterface - * The icon generator. + * @return \Drupal\Core\Layout\Icon\IconBuilderInterface + * The icon builder. */ - protected function getIconGenerator() { - return \Drupal::service('layout.icon_generator')->get(); + protected function getIconBuilder() { + return \Drupal::service('layout.icon_builder'); } /** diff --git a/core/modules/layout_discovery/layout_discovery.services.yml b/core/modules/layout_discovery/layout_discovery.services.yml index 805b562b75..48d32292cc 100644 --- a/core/modules/layout_discovery/layout_discovery.services.yml +++ b/core/modules/layout_discovery/layout_discovery.services.yml @@ -2,5 +2,6 @@ services: plugin.manager.core.layout: class: Drupal\Core\Layout\LayoutPluginManager arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@theme_handler'] - layout.icon_generator: - class: Drupal\Core\Layout\Icon\SvgIconFactory + layout.icon_builder: + class: Drupal\Core\Layout\Icon\SvgIconBuilder + shared: false diff --git a/core/tests/Drupal/KernelTests/Core/Layout/IconGeneratorTest.php b/core/tests/Drupal/KernelTests/Core/Layout/IconBuilderTest.php similarity index 85% rename from core/tests/Drupal/KernelTests/Core/Layout/IconGeneratorTest.php rename to core/tests/Drupal/KernelTests/Core/Layout/IconBuilderTest.php index a28a083fa3..ac9d380808 100644 --- a/core/tests/Drupal/KernelTests/Core/Layout/IconGeneratorTest.php +++ b/core/tests/Drupal/KernelTests/Core/Layout/IconBuilderTest.php @@ -2,29 +2,29 @@ namespace Drupal\KernelTests\Core\Layout; -use Drupal\Core\Layout\Icon\SvgIcon; +use Drupal\Core\Layout\Icon\SvgIconBuilder; use Drupal\Core\Render\RenderContext; use Drupal\KernelTests\KernelTestBase; /** - * @coversDefaultClass \Drupal\Core\Layout\Icon\SvgIcon + * @coversDefaultClass \Drupal\Core\Layout\Icon\SvgIconBuilder * @group Layout */ -class IconGeneratorTest extends KernelTestBase { +class IconBuilderTest extends KernelTestBase { /** - * @covers ::generate + * @covers ::build * @covers ::buildRenderArray * @covers ::calculateSvgValues * @covers ::getLength * @covers ::getOffset * - * @dataProvider providerTestGenerate + * @dataProvider providerTestBuild */ - public function testGenerate(SvgIcon $icon_generator, $icon_map, $expected) { + public function testBuild(SvgIconBuilder $icon_builder, $icon_map, $expected) { $renderer = $this->container->get('renderer'); - $build = $icon_generator->generate($icon_map); + $build = $icon_builder->build($icon_map); $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($build, $renderer) { return $renderer->render($build); @@ -32,16 +32,16 @@ public function testGenerate(SvgIcon $icon_generator, $icon_map, $expected) { $this->assertSame($expected, $output); } - public function providerTestGenerate() { + public function providerTestBuild() { $data = []; - $data['empty'][] = (new SvgIcon()); + $data['empty'][] = (new SvgIconBuilder()); $data['empty'][] = []; $data['empty'][] = <<<'EOD' EOD; - $data['two_column'][] = (new SvgIcon()) + $data['two_column'][] = (new SvgIconBuilder()) ->setId('two_column') ->setLabel('Two Column'); $data['two_column'][] = [['left', 'right']]; @@ -57,7 +57,7 @@ public function providerTestGenerate() { EOD; - $data['two_column_no_stroke'][] = (new SvgIcon()) + $data['two_column_no_stroke'][] = (new SvgIconBuilder()) ->setStrokeWidth(NULL); $data['two_column_no_stroke'][] = [['left', 'right']]; $data['two_column_no_stroke'][] = <<<'EOD' @@ -71,7 +71,7 @@ public function providerTestGenerate() { EOD; - $data['two_column_border_collapse'][] = (new SvgIcon()) + $data['two_column_border_collapse'][] = (new SvgIconBuilder()) ->setPadding(-2); $data['two_column_border_collapse'][] = [['left', 'right']]; $data['two_column_border_collapse'][] = <<<'EOD' @@ -85,7 +85,7 @@ public function providerTestGenerate() { EOD; - $data['stacked'][] = (new SvgIcon()); + $data['stacked'][] = (new SvgIconBuilder()); $data['stacked'][] = [ ['sidebar', 'top', 'top'], ['sidebar', 'left', 'right'],