Score:0

Using radio FormElement in a drupal 8 ListBuilder

ke flag

I made a custom configuration entity, and I'm trying to set up radio buttons in the listBuilder. This is done in the core module language without any problems, but when I try to do the same trick with my custom entity I can't get any radio button. Instead the attributes are rendered in the html element.

    public function buildRow(EntityInterface $entity) {
      $row['label'] = $entity->label();
      $row['default'] = [
        '#type' => 'radio',
        '#parents' => ['site_default_language'],
        '#title' => t('Set @title as default', ['@title' => $entity->label()]),
        '#title_display' => 'invisible',
        '#return_value' => $entity->id(),
        '#id' => 'edit-site-default-language-' . $entity->id(),
      ];
      // Mark the right language as default in the form.
      if ($entity->id() == $this->languageManager->getDefaultLanguage()->getId()) {
        $row['default']['#default_value'] = $entity->id();
      }
      return $row + parent::buildRow($entity);
    }

Then I get this html element as a result without any errors in the logs:

<td #type="radio" #parents="active_scsp_server" 
#title="..." #title_display="invisible" 
#return_value="pre" #id="edit-active-scsp-server-pre" #default_value="pre">
</td>
hoanns avatar
fr flag
Are you extending DraggableListBuilder as well? This thing is actually a Form in disguise.
David Lemon avatar
ke flag
Yes, I am extending DraggableListBuilder, mimicking a big part of LanguageListBuilder. But, the problem is that I am not getting any form... I already tryed to reinstall the entity, clearing cache and so on...
leymannx avatar
ne flag
Maybe try `$row['default'][$entity->id()] = [...]`. And can't the `#default_value` just be `TRUE` or `FALSE` or `NULL`? Can it be an ID?
Score:2
ke flag

To make the DraggableListBuilder work, the entity need to have a weigth key defined. Otherwise it will fail silently.

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.