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
|
* @param array $variables
|
||||||
* An associative array containing:
|
* An associative array containing:
|
||||||
* - element: An associative array containing the properties of the element.
|
* - element: An associative array containing the properties of the element.
|
||||||
* Properties used: #attributes, #children, #open,
|
* Properties used: #attributes, #children, #description, #required,
|
||||||
* #description, #id, #title, #value, #optional.
|
* #summary_attributes, #title, #value.
|
||||||
*/
|
*/
|
||||||
function template_preprocess_details(&$variables) {
|
function template_preprocess_details(&$variables) {
|
||||||
$element = $variables['element'];
|
$element = $variables['element'];
|
||||||
$variables['attributes'] = $element['#attributes'];
|
$variables['attributes'] = $element['#attributes'];
|
||||||
$variables['summary_attributes'] = new Attribute();
|
$variables['summary_attributes'] = new Attribute($element['#summary_attributes']);
|
||||||
if (!empty($element['#title'])) {
|
if (!empty($element['#title'])) {
|
||||||
$variables['summary_attributes']['role'] = 'button';
|
$variables['summary_attributes']['role'] = 'button';
|
||||||
if (!empty($element['#attributes']['id'])) {
|
if (!empty($element['#attributes']['id'])) {
|
||||||
|
|
|
@ -15,6 +15,8 @@ use Drupal\Core\Render\Element;
|
||||||
* - #title: The title of the details container. Defaults to "Details".
|
* - #title: The title of the details container. Defaults to "Details".
|
||||||
* - #open: Indicates whether the container should be open by default.
|
* - #open: Indicates whether the container should be open by default.
|
||||||
* Defaults to FALSE.
|
* Defaults to FALSE.
|
||||||
|
* - #summary_attributes: An array of attributes to apply to the <summary>
|
||||||
|
* element.
|
||||||
*
|
*
|
||||||
* Usage example:
|
* Usage example:
|
||||||
* @code
|
* @code
|
||||||
|
@ -43,6 +45,7 @@ class Details extends RenderElement {
|
||||||
$class = get_class($this);
|
$class = get_class($this);
|
||||||
return [
|
return [
|
||||||
'#open' => FALSE,
|
'#open' => FALSE,
|
||||||
|
'#summary_attributes' => [],
|
||||||
'#value' => NULL,
|
'#value' => NULL,
|
||||||
'#process' => [
|
'#process' => [
|
||||||
[$class, 'processGroup'],
|
[$class, 'processGroup'],
|
||||||
|
|
|
@ -260,12 +260,8 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
||||||
$missing_module_list = [
|
$missing_module_list = [
|
||||||
'#type' => 'details',
|
'#type' => 'details',
|
||||||
'#open' => TRUE,
|
'#open' => TRUE,
|
||||||
'#title' => [
|
'#title' => $this->t('Modules that will not be upgraded'),
|
||||||
'#type' => 'html_tag',
|
'#summary_attributes' => ['id' => ['error']],
|
||||||
'#tag' => 'span',
|
|
||||||
'#value' => $this->t('Modules that will not be upgraded'),
|
|
||||||
'#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']),
|
'#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,
|
'#weight' => 2,
|
||||||
];
|
];
|
||||||
|
@ -301,12 +297,8 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
||||||
// Available migrations.
|
// Available migrations.
|
||||||
$available_module_list = [
|
$available_module_list = [
|
||||||
'#type' => 'details',
|
'#type' => 'details',
|
||||||
'#title' => [
|
'#title' => $this->t('Modules that will be upgraded'),
|
||||||
'#type' => 'html_tag',
|
'#summary_attributes' => ['id' => ['checked']],
|
||||||
'#tag' => 'span',
|
|
||||||
'#value' => $this->t('Modules that will be upgraded'),
|
|
||||||
'#attributes' => ['id' => ['checked']],
|
|
||||||
],
|
|
||||||
'#weight' => 3,
|
'#weight' => 3,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,13 @@ class FormTestGroupDetailsForm extends FormBase {
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => 'Nest in details element',
|
'#title' => 'Nest in details element',
|
||||||
];
|
];
|
||||||
|
$form['summary_attributes'] = [
|
||||||
|
'#type' => 'details',
|
||||||
|
'#title' => 'Details element with summary attributes',
|
||||||
|
'#summary_attributes' => [
|
||||||
|
'data-summary-attribute' => 'test',
|
||||||
|
],
|
||||||
|
];
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,4 +223,12 @@ class ElementTest extends BrowserTestBase {
|
||||||
$this->assertText('I am an error on the details element.');
|
$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