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.
By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In D6 and D7, CTools provided the #dependency system to allow certain form elements to be dependent on others.
However, beginning in D8, Drupal Core provides the #states system to do the same thing.
Dependency used the HTML ID attribute, whereas States uses the HTML name attribute.
D7
$form['token_help'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output,
'#id' => 'edit-options-token-help',
'#dependency' => array(
'edit-options-tokenize' => array(1),
),
);
D8
$form['token_help'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output,
'#id' => 'edit-options-token-help',
'#states' => array(
'visible' => array(
':input[name="options[tokenize]"]' => array('checked' => TRUE),
),
),
);
Impacts:
Module developers