Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Layout/LayoutDefinition.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Layout/LayoutDefinition.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/lib/Drupal/Core/Layout/LayoutDefinition.php Mon Apr 23 09:46:53 2018 +0100 @@ -86,6 +86,15 @@ 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 @@ } /** + * 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[]