summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/Layout/LayoutDefinition.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib/Drupal/Core/Layout/LayoutDefinition.php')
-rw-r--r--core/lib/Drupal/Core/Layout/LayoutDefinition.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/Layout/LayoutDefinition.php b/core/lib/Drupal/Core/Layout/LayoutDefinition.php
index c804776..c87b618 100644
--- a/core/lib/Drupal/Core/Layout/LayoutDefinition.php
+++ b/core/lib/Drupal/Core/Layout/LayoutDefinition.php
@@ -86,6 +86,15 @@ class LayoutDefinition extends PluginDefinition implements PluginDefinitionInter
protected $icon;
/**
+ * An array defining the regions of a layout.
+ *
+ * @var string[][]|null
+ *
+ * @see \Drupal\Core\Layout\Icon\IconBuilderInterface::build()
+ */
+ protected $icon_map;
+
+ /**
* An associative array of regions in this layout.
*
* The key of the array is the machine name of the region, and the value is
@@ -372,6 +381,85 @@ class LayoutDefinition extends PluginDefinition implements PluginDefinitionInter
}
/**
+ * Gets the icon map for this layout definition.
+ *
+ * This should not be used if an icon path is specified. See ::getIcon().
+ *
+ * @return string[][]|null
+ * The icon map, if it exists.
+ */
+ public function getIconMap() {
+ return $this->icon_map;
+ }
+
+ /**
+ * Sets the icon map for this layout definition.
+ *
+ * @param string[][]|null $icon_map
+ * The icon map.
+ *
+ * @return $this
+ */
+ public function setIconMap($icon_map) {
+ $this->icon_map = $icon_map;
+ return $this;
+ }
+
+ /**
+ * Builds a render array for an icon representing the layout.
+ *
+ * @param int $width
+ * (optional) The width of the icon. Defaults to 125.
+ * @param int $height
+ * (optional) The height of the icon. Defaults to 150.
+ * @param int $stroke_width
+ * (optional) If an icon map is used, the width of region borders.
+ * @param int $padding
+ * (optional) If an icon map is used, the padding between regions. Any
+ * value above 0 is valid.
+ *
+ * @return array
+ * A render array for the icon.
+ */
+ public function getIcon($width = 125, $height = 150, $stroke_width = NULL, $padding = NULL) {
+ $icon = [];
+ if ($icon_path = $this->getIconPath()) {
+ $icon = [
+ '#theme' => 'image',
+ '#uri' => $icon_path,
+ '#width' => $width,
+ '#height' => $height,
+ '#alt' => $this->getLabel(),
+ ];
+ }
+ elseif ($icon_map = $this->getIconMap()) {
+ $icon_builder = $this->getIconBuilder()
+ ->setId($this->id())
+ ->setLabel($this->getLabel())
+ ->setWidth($width)
+ ->setHeight($height);
+ if ($padding) {
+ $icon_builder->setPadding($padding);
+ }
+ if ($stroke_width) {
+ $icon_builder->setStrokeWidth($stroke_width);
+ }
+ $icon = $icon_builder->build($icon_map);
+ }
+ return $icon;
+ }
+
+ /**
+ * Wraps the icon builder.
+ *
+ * @return \Drupal\Core\Layout\Icon\IconBuilderInterface
+ * The icon builder.
+ */
+ protected function getIconBuilder() {
+ return \Drupal::service('layout.icon_builder');
+ }
+
+ /**
* Gets the regions for this layout definition.
*
* @return array[]