0

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>
3
  • 1
    Are you extending DraggableListBuilder as well? This thing is actually a Form in disguise.
    – hoanns
    Aug 16 at 11:36
  • 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... Aug 16 at 12:10
  • Maybe try $row['default'][$entity->id()] = [...]. And can't the #default_value just be TRUE or FALSE or NULL? Can it be an ID?
    – leymannx
    Aug 16 at 12:35
2

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

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.