Problem/Motivation
$form['checkbox'] = [
'#type' => 'checkbox',
'#title' => t('Show link'),
];
$form['link'] = [
'#type' => 'link',
'#title' => t('Link to front page'),
'#url' => Url::fromRoute('<front>'),
'#states' => [
'visible' => [
':input[data-drupal-selector=edit-checkbox]' => ['checked' => TRUE],
],
],
];
Expected output:<a href="/" data-drupal-selector="edit-link" data-drupal-states="{"visible":{":input[data-drupal-selector=edit-checkbox]":{"checked":true}}}" id="edit-link">Link to front page</a>
Actual output:<a href="/" data-drupal-selector="edit-link" id="edit-link">Link to front page</a>
This appears to be because \Drupal\Core\Render\Element\Link::preRenderLink
moves the attributes into #options['attributes']
, which would be fine... if drupal_process_states()
(which adds the states to the element's #attributes
) was invoked before pre_render callbacks were invoked in \Drupal\Core\Render\Renderer::doRender
.
Proposed resolution
Move the invocation of drupal_process_states()
before pre_render callbacks.
Remaining tasks
- Create patch
- Create test
User interface changes
None
API changes
None
Data model changes
None