Problem/Motivation
In Drupal 8 we've been working to remove 'magic array keys'. But we still have render arrays, which everytime you use them cause you to need to look-up the allowed keys.
This is bad for DX.
Proposed resolution
Provide builder classes for each element type to make defining render arrays discoverable from IDEs
before
<?php
$variables['table'] = array(
'#type'=> 'table',
'#header'=> $headers,
'#rows'=> $rows,
'#attributes'=> array(
'id'=> $table_id,
),
'#tabledrag'=> array(
array(
'action'=> 'order',
'relationship'=> 'sibling',
'group'=> $weight_class,
),
),
);
?>
after
<?php
$variables['table'] = TableElement::create()
->setHeader($headers)
->setRows($rows)
->setAttributes(array(
'id'=> $table_id,
))
->setTableDrag(array(
array(
'action'=> 'order',
'relationship'=> 'sibling',
'group'=> $weight_class,
),
))->toRenderArray();
?>
Borrows heavily from both Url helper and FieldDefinition stuff.
Remaining tasks
Review
User interface changes
None
API changes
Only additions.