comparison 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
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
84 * @var string 84 * @var string
85 */ 85 */
86 protected $icon; 86 protected $icon;
87 87
88 /** 88 /**
89 * An array defining the regions of a layout.
90 *
91 * @var string[][]|null
92 *
93 * @see \Drupal\Core\Layout\Icon\IconBuilderInterface::build()
94 */
95 protected $icon_map;
96
97 /**
89 * An associative array of regions in this layout. 98 * An associative array of regions in this layout.
90 * 99 *
91 * The key of the array is the machine name of the region, and the value is 100 * The key of the array is the machine name of the region, and the value is
92 * an associative array with the following keys: 101 * an associative array with the following keys:
93 * - label: (string) The human-readable name of the region. 102 * - label: (string) The human-readable name of the region.
367 * @return $this 376 * @return $this
368 */ 377 */
369 public function setIconPath($icon) { 378 public function setIconPath($icon) {
370 $this->icon = $icon; 379 $this->icon = $icon;
371 return $this; 380 return $this;
381 }
382
383 /**
384 * Gets the icon map for this layout definition.
385 *
386 * This should not be used if an icon path is specified. See ::getIcon().
387 *
388 * @return string[][]|null
389 * The icon map, if it exists.
390 */
391 public function getIconMap() {
392 return $this->icon_map;
393 }
394
395 /**
396 * Sets the icon map for this layout definition.
397 *
398 * @param string[][]|null $icon_map
399 * The icon map.
400 *
401 * @return $this
402 */
403 public function setIconMap($icon_map) {
404 $this->icon_map = $icon_map;
405 return $this;
406 }
407
408 /**
409 * Builds a render array for an icon representing the layout.
410 *
411 * @param int $width
412 * (optional) The width of the icon. Defaults to 125.
413 * @param int $height
414 * (optional) The height of the icon. Defaults to 150.
415 * @param int $stroke_width
416 * (optional) If an icon map is used, the width of region borders.
417 * @param int $padding
418 * (optional) If an icon map is used, the padding between regions. Any
419 * value above 0 is valid.
420 *
421 * @return array
422 * A render array for the icon.
423 */
424 public function getIcon($width = 125, $height = 150, $stroke_width = NULL, $padding = NULL) {
425 $icon = [];
426 if ($icon_path = $this->getIconPath()) {
427 $icon = [
428 '#theme' => 'image',
429 '#uri' => $icon_path,
430 '#width' => $width,
431 '#height' => $height,
432 '#alt' => $this->getLabel(),
433 ];
434 }
435 elseif ($icon_map = $this->getIconMap()) {
436 $icon_builder = $this->getIconBuilder()
437 ->setId($this->id())
438 ->setLabel($this->getLabel())
439 ->setWidth($width)
440 ->setHeight($height);
441 if ($padding) {
442 $icon_builder->setPadding($padding);
443 }
444 if ($stroke_width) {
445 $icon_builder->setStrokeWidth($stroke_width);
446 }
447 $icon = $icon_builder->build($icon_map);
448 }
449 return $icon;
450 }
451
452 /**
453 * Wraps the icon builder.
454 *
455 * @return \Drupal\Core\Layout\Icon\IconBuilderInterface
456 * The icon builder.
457 */
458 protected function getIconBuilder() {
459 return \Drupal::service('layout.icon_builder');
372 } 460 }
373 461
374 /** 462 /**
375 * Gets the regions for this layout definition. 463 * Gets the regions for this layout definition.
376 * 464 *