Unverified Commit d6caa271 authored by alexpott's avatar alexpott

Issue #2930407 by tstoeckler, lauriii, alexpott: Allow specifying summary...

Issue #2930407 by tstoeckler, lauriii, alexpott: Allow specifying summary attributes for details elements
parent 2129484e
......@@ -235,13 +235,13 @@ function template_preprocess_fieldset(&$variables) {
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #attributes, #children, #open,
* #description, #id, #title, #value, #optional.
* Properties used: #attributes, #children, #description, #required,
* #summary_attributes, #title, #value.
*/
function template_preprocess_details(&$variables) {
$element = $variables['element'];
$variables['attributes'] = $element['#attributes'];
$variables['summary_attributes'] = new Attribute();
$variables['summary_attributes'] = new Attribute($element['#summary_attributes']);
if (!empty($element['#title'])) {
$variables['summary_attributes']['role'] = 'button';
if (!empty($element['#attributes']['id'])) {
......
......@@ -15,6 +15,8 @@
* - #title: The title of the details container. Defaults to "Details".
* - #open: Indicates whether the container should be open by default.
* Defaults to FALSE.
* - #summary_attributes: An array of attributes to apply to the <summary>
* element.
*
* Usage example:
* @code
......@@ -43,6 +45,7 @@ public function getInfo() {
$class = get_class($this);
return [
'#open' => FALSE,
'#summary_attributes' => [],
'#value' => NULL,
'#process' => [
[$class, 'processGroup'],
......
......@@ -260,12 +260,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$missing_module_list = [
'#type' => 'details',
'#open' => TRUE,
'#title' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $this->t('Modules that will not be upgraded'),
'#attributes' => ['id' => ['error']],
],
'#title' => $this->t('Modules that will not be upgraded'),
'#summary_attributes' => ['id' => ['error']],
'#description' => $this->t('There are no modules installed on your new site to replace these modules. If you proceed with the upgrade now, configuration and/or content needed by these modules will not be available on your new site. For more information, see <a href=":review">Review the pre-upgrade analysis</a> in the <a href=":migrate">Upgrading to Drupal 8</a> handbook.', [':review' => 'https://www.drupal.org/docs/8/upgrade/upgrade-using-web-browser#pre-upgrade-analysis', ':migrate' => 'https://www.drupal.org/docs/8/upgrade']),
'#weight' => 2,
];
......@@ -301,12 +297,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Available migrations.
$available_module_list = [
'#type' => 'details',
'#title' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $this->t('Modules that will be upgraded'),
'#attributes' => ['id' => ['checked']],
],
'#title' => $this->t('Modules that will be upgraded'),
'#summary_attributes' => ['id' => ['checked']],
'#weight' => 3,
];
......
......@@ -39,6 +39,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $required
'#type' => 'textfield',
'#title' => 'Nest in details element',
];
$form['summary_attributes'] = [
'#type' => 'details',
'#title' => 'Details element with summary attributes',
'#summary_attributes' => [
'data-summary-attribute' => 'test',
],
];
return $form;
}
......
......@@ -223,4 +223,12 @@ public function testFormElementErrors() {
$this->assertText('I am an error on the details element.');
}
/**
* Tests summary attributes of details.
*/
public function testDetailsSummaryAttributes() {
$this->drupalGet('form-test/group-details');
$this->assertTrue($this->cssSelect('summary[data-summary-attribute="test"]'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment