Introduction Delighted hook_schema is one of those methods where you are happy to have a usable documentation on the api website. It is pretty much self-explanatory and you don’t have to look for hours on third parties websites to get some usable information. 🙂 hook_schema on api.drupal.org and don’t forget to select your Drupal version! […]
Tag Archives: table
[Drupal] Table render array example structure
Result The code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
public function controllerCallbackExample() { return [ '#type' => 'table', '#caption' => 'This is a caption. Use a translated string here.', '#header' => [ 'Header 1', 'Header 2', 'Header 3', 'Header 4' ], '#rows' => [ [ 'Row 1 Cell 1', 'Row 1 Cell 2', 'Row 1 Cell 3', ['data' => 'Row 1 Cell 4'] ], [ 'class' => ['second-row-class', 'may contain spaces but dont use them'], 'data' => [ 'Row 2 Cell 1', [ 'data' => 'Row 2 Cell 2' ], [ 'colspan' => 2, 'data' => 'Row 3 Cell 3 & 4', 'style' => 'background-color: pink; text-align: center' ] ], 'style' => 'font-weight: bold' ], [ 'data' => [ 'Row 3 Cell 1', 'Row 3 Cell 2', 'Row 3 Cell 3', 'Row 3 Cell 4' ], 'no_striping' => FALSE // Not working in 8.2.x, may be fixed later ] ], '#footer' => [ [ 'data' => [ 'Footer 1', [ 'colspan' => 2, 'data' => 'Footer 2 with colspan = 2', 'style' => 'text-align: inherit' ], [ 'data' => 'Footer 4', 'style' => 'text-align: inherit' ] ], 'style' => 'text-align: center' ], [ [ 'colspan' => 4, 'class' => 'second-footer-row', 'data' => 'Another Footer Line', 'style' => ['background-color: purple;', 'text-align: center;', 'color: white;'] ] ] ] ]; } |
Additional Information Tested to work on Drupal 8.2.x. For some reason, no_striping doesn’t work as expected in 8.2.x (it is ignored). The script which handles the render array conversion to twig ready variables is located here: core\includes\theme.inc. The twig template which renders the table on the default theme is here: core\themes\classy\templates\dataset\table.html.twig.