0

I'm interested in adding a link in a tableselect form row. Utilizing the #options key I can only add columns with strings. I am able to add form elements in the #options array similar to the #rows array.

$rows[$nid] = [
    'edit_link' => [
        'class' => 'edit_link',
        'data' => [
            '#type' => 'link',
            '#url' => Url::fromRoute('group_manager.edit'),
            '#title' => 'test',
        ],
    ],
]

//…

$form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
);

Implementing this example as is doesn't render this column in the table, so I assume it has failed somehow.

The 'edit_link' element works if the form is changed to a 'table' instead of 'tableselect'.

1
  • 1
    Your code is roughly correct, but there are things you didn't post so I can't say for sure why you're having a problem. Note that classes need to be passed as an array, so that should look like 'class' => ['edit_link']. Also, you only show one column - is that really all your table has? And if the 'group_manager.edit' route needs a parameter (e.g. the group id ?) that needs to be specified in your Url::fromRoute() call ... But as I said, your code is basically correct and should work for a tableselect - I use working code that's very similar to the above. Check your log for errors ...
    – anonymous
    May 16, 2021 at 2:47

1 Answer 1

0

I solved my issue.

The links column was not rendered for the tableselect form because I didn't update my $header array with the new element name edit_link.

It appears a table form does not map the element names to the header names, meaning I did not have to update the header array for my link columns to appear. As long as the element name was in the header array Tableselect would render the column. I believe this to be the basis of my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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