0

I need to add an Icon to a layout added by a contrib module. But I see it is adding the layout via plugin PHP file instead of layouts.yml. The annotation looks like following

/**
 * A very advanced custom layout.
 *
 * @Layout(
 *   id = "lb_tabs_tabs",
 *   label = @Translation("Tabs"),
 *   category = @Translation("Effects"),
 *   path = "layouts/tabs",
 *   template = "lb-tabs-tabs",
 *   icon_map = ""
 * )
 */

I don't know how to represent the multidimensional array into this annotation form. When I tried simple [['region', 'region']] form it errored [Syntax Error] Expected PlainValue, got '[' .

tried @Array(@Array('region', 'region')) as well but got

Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got '(' .

What is the correct way to add an icon_map there?

Also tried adding layouts.yml and moving these values to yml and the layout option just disappeared as a whole`.

0

You can do this via the layout alter hook ( hook_layout_alter(&$definitions) ). The definitions variable is an array of all the defined layouts keyed by the layout machine name.

The value here is a Drupal\Core\Layout\LayoutDefinition object. This has a setIconMap method. You can pass this an array of arrays that define the icon.

E.g. if the yml format is:

- [top]
- [first, second]
- [bottom]

the value is something like:

$map = [
  ['top'],
  ['first', 'second'],
  ['bottom']
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.