Issue #2930407 by tstoeckler, lauriii, alexpott: Allow specifying summary attributes for details elements
parent
2129484ee5
commit
d6caa27121
|
@ -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 @@ use Drupal\Core\Render\Element;
|
|||
* - #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 @@ class Details extends RenderElement {
|
|||
$class = get_class($this);
|
||||
return [
|
||||
'#open' => FALSE,
|
||||
'#summary_attributes' => [],
|
||||
'#value' => NULL,
|
||||
'#process' => [
|
||||
[$class, 'processGroup'],
|
||||
|
|
|
@ -260,12 +260,8 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
$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 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
// 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 @@ class FormTestGroupDetailsForm extends FormBase {
|
|||
'#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 @@ class ElementTest extends BrowserTestBase {
|
|||
$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"]'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue