public function LayoutDefinition::getIcon in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Layout/LayoutDefinition.php \Drupal\Core\Layout\LayoutDefinition::getIcon()
Builds a render array for an icon representing the layout.
Parameters
int $width: (optional) The width of the icon. Defaults to 125.
int $height: (optional) The height of the icon. Defaults to 150.
int $stroke_width: (optional) If an icon map is used, the width of region borders.
int $padding: (optional) If an icon map is used, the padding between regions. Any value above 0 is valid.
Return value
array A render array for the icon.
File
- core/
lib/ Drupal/ Core/ Layout/ LayoutDefinition.php, line 437
Class
- LayoutDefinition
- Provides an implementation of a layout definition and its metadata.
Namespace
Drupal\Core\LayoutCode
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;
}