class SvgIconBuilder implements IconBuilderInterface (View source)

Builds SVG layout icons.

Properties

protected string $id

The machine name of the layout.

protected string $label

The label of the layout.

protected int $width

The width of the SVG.

protected int $height

The height of the SVG.

protected int $padding

The padding between regions.

protected int|null $strokeWidth

The width of region borders.

Methods

array
build(array $icon_map)

Builds a render array representation of an SVG based on an icon map.

array
buildRenderArray(array $regions, int $width, int $height, int|null $stroke_width)

Builds a render array representation of an SVG.

array[]
calculateSvgValues(array $rows, int $width, int $height, int $stroke_width, int $padding)

Calculates the dimensions and offsets of all regions.

int
getOffset(int $delta, int $length, int $stroke_width, int $padding)

Gets the offset for this region.

float|int
getLength(int $number_of_regions, int $length, int $stroke_width, int $padding)

Gets the height or width of a region.

$this
setId(string $id)

Sets the ID.

$this
setLabel(string $label)

Sets the label.

$this
setWidth(int $width)

Sets the width.

$this
setHeight(int $height)

Sets the height.

$this
setPadding(int $padding)

Sets the padding.

$this
setStrokeWidth(int|null $stroke_width)

Sets the stroke width.

Details

array build(array $icon_map)

Builds a render array representation of an SVG based on an icon map.

Parameters

array $icon_map
A two-dimensional array representing the visual output of the layout. For the following shape: ------------------------------
100%
------- -------------- -------
50% 25%
25% -------------- -------
75%
------------------------------

The corresponding array would be:

  • ['top']
  • ['first', 'second', 'second', 'third']
  • ['first', 'bottom', 'bottom', 'bottom'].

Return Value

array

A render array representing a SVG icon.

protected array buildRenderArray(array $regions, int $width, int $height, int|null $stroke_width)

Builds a render array representation of an SVG.

Parameters

array $regions

An array keyed by region name, with each element containing the 'height', 'width', and 'x' and 'y' offsets of each region.

int $width

The width of the SVG.

int $height

The height of the SVG.

int|null $stroke_width

The width of region borders.

Return Value

array

A render array representing a SVG icon.

protected array[] calculateSvgValues(array $rows, int $width, int $height, int $stroke_width, int $padding)

Calculates the dimensions and offsets of all regions.

Parameters

array $rows

A two-dimensional array representing the visual output of the layout. See the documentation for the $icon_map parameter of \Drupal\Core\Layout\Icon\IconBuilderInterface::build().

int $width

The width of the SVG.

int $height

The height of the SVG.

int $stroke_width

The width of region borders.

int $padding

The padding between regions.

Return Value

array[]

An array keyed by region name, with each element containing the 'height', 'width', and 'x' and 'y' offsets of each region.

protected int getOffset(int $delta, int $length, int $stroke_width, int $padding)

Gets the offset for this region.

Parameters

int $delta

The zero-based delta of the region.

int $length

The height or width of the region.

int $stroke_width

The width of the region borders.

int $padding

The padding between regions.

Return Value

int

The offset for this region.

protected float|int getLength(int $number_of_regions, int $length, int $stroke_width, int $padding)

Gets the height or width of a region.

Parameters

int $number_of_regions

The total number of regions.

int $length

The total height or width of the icon.

int $stroke_width

The width of the region borders.

int $padding

The padding between regions.

Return Value

float|int

The height or width of a region.

$this setId(string $id)

Sets the ID.

Parameters

string $id

The machine name of the layout.

Return Value

$this

$this setLabel(string $label)

Sets the label.

Parameters

string $label

The label of the layout.

Return Value

$this

$this setWidth(int $width)

Sets the width.

Parameters

int $width

The width of the SVG.

Return Value

$this

$this setHeight(int $height)

Sets the height.

Parameters

int $height

The height of the SVG.

Return Value

$this

$this setPadding(int $padding)

Sets the padding.

Parameters

int $padding

The padding between regions.

Return Value

$this

$this setStrokeWidth(int|null $stroke_width)

Sets the stroke width.

Parameters

int|null $stroke_width

The width of region borders.

Return Value

$this