- Issue created by @Grimreaper
- @grimreaper opened merge request.
- Issue was unassigned.
- Status changed to Needs review
over 1 year ago 1:40pm 15 September 2023 - 🇫🇷France Grimreaper France 🇫🇷
With the MR, if in an element there is:
[ '#title' => 'my title', '#description' => 'my description', '#description_toggle' => TRUE, ];
The element will have the toggle.
I am currently poking something in conjunction with Gin Layout Builder for select list. Maybe other form elements will require update.
- 🇮🇳India shubham_jain
Hi @Grimreaper,
&& $variables['element']['#description_toggle']
can you explain why you have added this because isset is already checking that the value is set or not. So, I don't think we need this code. - 🇫🇷France Grimreaper France 🇫🇷
Hi @shubham_jain,
The isset tests that the key exists, it does not check if it is TRUE or FALSE.
- Status changed to RTBC
4 months ago 12:05pm 14 August 2024 - 🇺🇸United States jrockowitz Brooklyn, NY
I think this is a great idea.
The code is correct in using...
(isset($variables['element']['#description_toggle']) && $variables['element']['#description_toggle'])
...because the
$variables['element']['#description_toggle']
can be defined but set toFALSE
.I will mark this RTBC unless the maintainer needs test coverage or wants someone to take a different approach.
BTW, if someone wants to enable the description toggle for all admin forms via the Gin admin, they would need to use the patch and the custom code below.
/** * Implements template_preprocess_HOOK() for form_element. */ function MY_MODULE_preprocess_form_element(&$variables) { _MY_MODULE_preprocess_description_toggle($variables); } /** * Implements template_preprocess_HOOK() for datetime_wrapper. */ function MY_MODULE_preprocess_datetime_wrapper(&$variables) { _MY_MODULE_preprocess_description_toggle($variables); } /** * Implements hook_preprocess_details(). */ function MY_MODULE_preprocess_details(array &$variables): void { _MY_MODULE_preprocess_description_toggle($variables); } /** * Implements template_preprocess_HOOK() for fieldset. * * @see MY_MODULE_preprocess_fieldset */ function MY_MODULE_preprocess_fieldset(&$variables) { _MY_MODULE_preprocess_description_toggle($variables); } /** * Implements template_preprocess_HOOK() for form_element. * * @see \Drupal\gin\GinDescriptionToggle * @see gin_preprocess_form_element() * @see gin_preprocess_datetime_wrapper() * @see gin_preprocess_details() * @see gin_preprocess_fieldset() */ function _MY_MODULE_preprocess_description_toggle(&$variables) { /** @var \Drupal\Core\Theme\ThemeManagerInterface $theme_manager */ $theme_manager = \Drupal::service('theme.manager'); if ($theme_manager->getActiveTheme()->getName() === 'gin') { $variables['element']['#description_toggle'] = TRUE; } }