function LayoutDefinition::getIcon

Same name in other branches
  1. 9 core/lib/Drupal/Core/Layout/LayoutDefinition.php \Drupal\Core\Layout\LayoutDefinition::getIcon()
  2. 8.9.x core/lib/Drupal/Core/Layout/LayoutDefinition.php \Drupal\Core\Layout\LayoutDefinition::getIcon()
  3. 11.x 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 440

Class

LayoutDefinition
Provides an implementation of a layout definition and its metadata.

Namespace

Drupal\Core\Layout

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.