Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291859

#states not applied to link elements

$
0
0

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="{&quot;visible&quot;:{&quot;:input[data-drupal-selector=edit-checkbox]&quot;:{&quot;checked&quot;: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


Viewing all articles
Browse latest Browse all 291859

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>