Score:0

How to show layout's label or description in a custom Layout Builder settings form

za flag

I have successfully made custom layouts and a custom settings form, something like this: https://www.codimth.com/blog/web/drupal/how-add-custom-settings-layouts-drupal-8-9

I want the custom settings form to include the layout's label and description as I have defined them in the layouts.yml file.

Like, at the top of the form before my settings, the name of the layout and then the description. I don't want to have to make a new Class for each layout just to show different label and description.

Score:1
za flag

My colleague figured it out :D

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $configuration = $this->getConfiguration();
  $definition = $this->getPluginDefinition();
  $form['feature_set_info'] = [
    '#type' => 'item',
    '#markup' => '<div class="form-item"><div class="isu-layout-form-title">' . $definition->getLabel() . '</div><p class="description isu-form-element-description">' . $definition->getDescription() . '</p></div></div>',
  ];
  // The rest of my form
  return $form;
}

In particular $definition = $this->getPluginDefinition(); and then use it as $definition->getLabel() and $definition->getDescription().

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.