Chris@0: $value) { Chris@0: $this->set($property, $value); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets any arbitrary property. Chris@0: * Chris@0: * @param string $property Chris@0: * The property to retrieve. Chris@0: * Chris@0: * @return mixed Chris@0: * The value for that property, or NULL if the property does not exist. Chris@0: */ Chris@0: public function get($property) { Chris@0: if (property_exists($this, $property)) { Chris@0: $value = isset($this->{$property}) ? $this->{$property} : NULL; Chris@0: } Chris@0: else { Chris@0: $value = isset($this->additional[$property]) ? $this->additional[$property] : NULL; Chris@0: } Chris@0: return $value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets a value to an arbitrary property. Chris@0: * Chris@0: * @param string $property Chris@0: * The property to use for the value. Chris@0: * @param mixed $value Chris@0: * The value to set. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function set($property, $value) { Chris@0: if (property_exists($this, $property)) { Chris@0: $this->{$property} = $value; Chris@0: } Chris@0: else { Chris@0: $this->additional[$property] = $value; Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the human-readable name of the layout definition. Chris@0: * Chris@0: * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup Chris@0: * The human-readable name of the layout definition. Chris@0: */ Chris@0: public function getLabel() { Chris@0: return $this->label; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the human-readable name of the layout definition. Chris@0: * Chris@0: * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $label Chris@0: * The human-readable name of the layout definition. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setLabel($label) { Chris@0: $this->label = $label; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the description of the layout definition. Chris@0: * Chris@0: * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup Chris@0: * The description of the layout definition. Chris@0: */ Chris@0: public function getDescription() { Chris@0: return $this->description; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the description of the layout definition. Chris@0: * Chris@0: * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $description Chris@0: * The description of the layout definition. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setDescription($description) { Chris@0: $this->description = $description; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the human-readable category of the layout definition. Chris@0: * Chris@0: * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup Chris@0: * The human-readable category of the layout definition. Chris@0: */ Chris@0: public function getCategory() { Chris@0: return $this->category; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the human-readable category of the layout definition. Chris@0: * Chris@0: * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $category Chris@0: * The human-readable category of the layout definition. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setCategory($category) { Chris@0: $this->category = $category; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the template name. Chris@0: * Chris@0: * @return string|null Chris@0: * The template name, if it exists. Chris@0: */ Chris@0: public function getTemplate() { Chris@0: return $this->template; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the template name. Chris@0: * Chris@0: * @param string|null $template Chris@0: * The template name. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setTemplate($template) { Chris@0: $this->template = $template; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the template path. Chris@0: * Chris@0: * @return string Chris@0: * The template path. Chris@0: */ Chris@0: public function getTemplatePath() { Chris@0: return $this->templatePath; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the template path. Chris@0: * Chris@0: * @param string $template_path Chris@0: * The template path. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setTemplatePath($template_path) { Chris@0: $this->templatePath = $template_path; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the theme hook. Chris@0: * Chris@0: * @return string|null Chris@0: * The theme hook, if it exists. Chris@0: */ Chris@0: public function getThemeHook() { Chris@0: return $this->theme_hook; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the theme hook. Chris@0: * Chris@0: * @param string $theme_hook Chris@0: * The theme hook. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setThemeHook($theme_hook) { Chris@0: $this->theme_hook = $theme_hook; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the base path for this layout definition. Chris@0: * Chris@0: * @return string Chris@0: * The base path. Chris@0: */ Chris@0: public function getPath() { Chris@0: return $this->path; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the base path for this layout definition. Chris@0: * Chris@0: * @param string $path Chris@0: * The base path. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setPath($path) { Chris@0: $this->path = $path; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the asset library for this layout definition. Chris@0: * Chris@0: * @return string|null Chris@0: * The asset library, if it exists. Chris@0: */ Chris@0: public function getLibrary() { Chris@0: return $this->library; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the asset library for this layout definition. Chris@0: * Chris@0: * @param string|null $library Chris@0: * The asset library. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setLibrary($library) { Chris@0: $this->library = $library; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the icon path for this layout definition. Chris@0: * Chris@0: * @return string|null Chris@0: * The icon path, if it exists. Chris@0: */ Chris@0: public function getIconPath() { Chris@0: return $this->icon; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the icon path for this layout definition. Chris@0: * Chris@0: * @param string|null $icon Chris@0: * The icon path. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setIconPath($icon) { Chris@0: $this->icon = $icon; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Gets the icon map for this layout definition. Chris@14: * Chris@14: * This should not be used if an icon path is specified. See ::getIcon(). Chris@14: * Chris@14: * @return string[][]|null Chris@14: * The icon map, if it exists. Chris@14: */ Chris@14: public function getIconMap() { Chris@14: return $this->icon_map; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Sets the icon map for this layout definition. Chris@14: * Chris@14: * @param string[][]|null $icon_map Chris@14: * The icon map. Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function setIconMap($icon_map) { Chris@14: $this->icon_map = $icon_map; Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Builds a render array for an icon representing the layout. Chris@14: * Chris@14: * @param int $width Chris@14: * (optional) The width of the icon. Defaults to 125. Chris@14: * @param int $height Chris@14: * (optional) The height of the icon. Defaults to 150. Chris@14: * @param int $stroke_width Chris@14: * (optional) If an icon map is used, the width of region borders. Chris@14: * @param int $padding Chris@14: * (optional) If an icon map is used, the padding between regions. Any Chris@14: * value above 0 is valid. Chris@14: * Chris@14: * @return array Chris@14: * A render array for the icon. Chris@14: */ Chris@14: public function getIcon($width = 125, $height = 150, $stroke_width = NULL, $padding = NULL) { Chris@14: $icon = []; Chris@14: if ($icon_path = $this->getIconPath()) { Chris@14: $icon = [ Chris@14: '#theme' => 'image', Chris@14: '#uri' => $icon_path, Chris@14: '#width' => $width, Chris@14: '#height' => $height, Chris@14: '#alt' => $this->getLabel(), Chris@14: ]; Chris@14: } Chris@14: elseif ($icon_map = $this->getIconMap()) { Chris@14: $icon_builder = $this->getIconBuilder() Chris@14: ->setId($this->id()) Chris@14: ->setLabel($this->getLabel()) Chris@14: ->setWidth($width) Chris@14: ->setHeight($height); Chris@14: if ($padding) { Chris@14: $icon_builder->setPadding($padding); Chris@14: } Chris@14: if ($stroke_width) { Chris@14: $icon_builder->setStrokeWidth($stroke_width); Chris@14: } Chris@14: $icon = $icon_builder->build($icon_map); Chris@14: } Chris@14: return $icon; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Wraps the icon builder. Chris@14: * Chris@14: * @return \Drupal\Core\Layout\Icon\IconBuilderInterface Chris@14: * The icon builder. Chris@14: */ Chris@14: protected function getIconBuilder() { Chris@14: return \Drupal::service('layout.icon_builder'); Chris@14: } Chris@14: Chris@14: /** Chris@0: * Gets the regions for this layout definition. Chris@0: * Chris@0: * @return array[] Chris@0: * The layout regions. The keys of the array are the machine names of the Chris@0: * regions, and the values are an associative array with the following keys: Chris@0: * - label: (string) The human-readable name of the region. Chris@0: * Any remaining keys may have special meaning for the given layout plugin, Chris@0: * but are undefined here. Chris@0: */ Chris@0: public function getRegions() { Chris@0: return $this->regions; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the regions for this layout definition. Chris@0: * Chris@0: * @param array[] $regions Chris@0: * An array of regions, see ::getRegions() for the format. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setRegions(array $regions) { Chris@0: $this->regions = $regions; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the machine-readable region names. Chris@0: * Chris@0: * @return string[] Chris@0: * An array of machine-readable region names. Chris@0: */ Chris@0: public function getRegionNames() { Chris@0: return array_keys($this->getRegions()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the human-readable region labels. Chris@0: * Chris@0: * @return string[] Chris@0: * An array of human-readable region labels. Chris@0: */ Chris@0: public function getRegionLabels() { Chris@0: $regions = $this->getRegions(); Chris@0: return array_combine(array_keys($regions), array_column($regions, 'label')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the default region. Chris@0: * Chris@0: * @return string Chris@0: * The machine-readable name of the default region. Chris@0: */ Chris@0: public function getDefaultRegion() { Chris@0: return $this->default_region; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the default region. Chris@0: * Chris@0: * @param string $default_region Chris@0: * The machine-readable name of the default region. Chris@0: * Chris@0: * @return $this Chris@0: */ Chris@0: public function setDefaultRegion($default_region) { Chris@0: $this->default_region = $default_region; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDeriver() { Chris@0: return $this->deriver; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setDeriver($deriver) { Chris@0: $this->deriver = $deriver; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: }