Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The section "Use #type='link' for adding a single link to a render array, particularly for tables that include operation links like 'edit', 'delete', etc." is not clear for tables because the only provided example applies only to forms.
It should be made more clear that in order to pass a render array as a cell in a table, the array must be in an array in the 'data' index. An example like the following would be very helpful:
Drupal 6:
$row[] = l(t('link title'), 'path/to/location');
Drupal 7:
$row[] = array('data' => array('#type' => 'link', '#title' => t('link title'), '#href' => 'path/to/location'));
If you don't put that render array in the 'data' index of an array, it treats the render array as attributes for the cell.
Comments
Comment #1
arianek CreditAttribution: arianek commentedit's borderline which queue this should be in, but moving it to core docs so jhodgdon can review
Comment #2
joachim CreditAttribution: joachim commentedI'm not entirely I follow this...
Is what you are saying:
The example as it stands it not very clear anyway, as it's not clear that what's being assembled by taxonomy_overview_vocabularies() will then go to theme_table().
For an unthemed form, this works fine:
Comment #3
jhodgdonThis is the right queue for the Updating Modules pages. I don't have time to review this right at the moment...
Comment #4
jhodgdonAdding tag that we use for Updating page revisions
Comment #5
jhodgdonNew tagging scheme
Comment #6
jhodgdonSorry for the delay on this one.
The original post in my opinion is someone who just didn't understand how to build a table row using complex cells rather than just putting values into cells.
That said, the example in that section was unduly complex. So what I did is simplify the example down to two lines for d6/7 - one line as a form element and one line as a table cell. That should make everyone happy.
Comment #9
dianacastillo CreditAttribution: dianacastillo commentedDrupal 8 :
Comment #10
gmangones CreditAttribution: gmangones as a volunteer commentedIn 8 work fine.
Comment #11
ilechcod CreditAttribution: ilechcod commentedI just spent days trying to debug this in 2021. It's still not documented anywhere that the render array has to be put in the 'data' array for things to work. Was about to give up when I stumbled on this thread. This is unnecessary expense of energy. What does it take to document this officially inside the table element page?
Comment #12
jhodgdonIf you want to change the documentation for
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...
what you need to do is:
a) Create a new issue describing what needs to be added to the documentation.
b) In the Issue summary and relationships section, mark it as Related to this issue and to #2486967: [meta] Move/Create Form Element Documentation.
c) Add a new comment to both of the issues in (b) with a link to your new issue, so that people following either issue will know about your new issue.
d) If possible, make a patch for your new issue, or if not, be ready to review a patch that someone else creates. See
https://www.drupal.org/community/contributor-guide/task/create-a-patch-f...
for info on making patches.