- Issue created by @Martygraphie
- Merge request !81Issue #3448313 by Martygraphie: The menu_footer pattern hook causes a 500 error → (Open) created by Martygraphie
- Status changed to Needs review
6 months ago 3:44pm 20 May 2024 - Status changed to Needs work
6 months ago 5:05pm 21 May 2024 - 🇫🇷France pdureau Paris
I would not be against removing the hook like you did, because it will not be compatible with SDC / UI patterns 2 anyway.
But the feature needs to be kept for now because we need to consider people using it.
Can we add a condition in the hook to prevent the issue instead?Associate this menu with the footer_menu pattern
How? By site building? Where? From presenter template?
I will try to reproduce the issue.
- 🇫🇷France mh_nichts
Hello,
I've seen the same error, but caused by the button pattern preprocess (visible on pages : /patterns or /patterns/button ou /patterns/button_group) :
TypeError: strtolower(): Argument #1 ($string) must be of type string, Drupal\Core\Render\Markup given in strtolower() (line 440 of themes/contrib/ui_suite_dsfr/ui_suite_dsfr.theme). ui_suite_dsfr_preprocess_pattern_button(Array, 'pattern_button', Array) ...
It seems the same kind of condition causes the same error.
The strange thing is :
- if we comment those lines in ui_suite_dsfr but implement the same preprocess in our child theme, there is no error, everything works as expected
- I see the link pattern preprocess has the same kind of condition but it doesn't trigger any error...
I confirm that this preprocess is not obsolete, as it handles the "external" setting automatically based on the URL, so the best would be to find the cause of the error and fix it, if possible, instead of removing.
- 🇫🇷France pdureau Paris
OK, this is 1.0.0-RC2 material :) Let's try to understand and fix this ASAP!
Do we need this kind of checks?
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; +use Drupal\Component\Render\MarkupInterface; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Menu\MenuTreeParameters; @@ -421,6 +401,9 @@ function ui_suite_dsfr_preprocess_pattern_link(array &$variables) { if (empty($variables['url'])) { return; } + if (is_object($variables['url']) && ($variables['url'] instanceof MarkupInterface)) { + $variables['url'] = (string) $variables['url']; + } // It seems UrlHelper::setAllowedProtocols() doesn't support mailto. if (!str_starts_with(strtolower($variables['url']), 'mailto:') && UrlHelper::isExternal($variables['url']) @@ -436,6 +419,9 @@ function ui_suite_dsfr_preprocess_pattern_button(array &$variables) { if (empty($variables['url'])) { return; } + if (is_object($variables['url']) && ($variables['url'] instanceof MarkupInterface)) { + $variables['url'] = (string) $variables['url']; + } // It seems UrlHelper::setAllowedProtocols() doesn't support mailto. if (!str_starts_with(strtolower($variables['url']), 'mailto:') && UrlHelper::isExternal($variables['url']) @@ -466,6 +452,9 @@ function ui_suite_dsfr_preprocess_pattern_footer_menu(array &$variables) { if (empty($item['url'])) { return; } + if (is_object($item['url']) && ($item['url'] instanceof MarkupInterface)) { + $item['url'] = (string) $item['url']; + } // It seems UrlHelper::setAllowedProtocols() doesn't support mailto. if (!str_starts_with(strtolower($item['url']), 'mailto:') && UrlHelper::isExternal($item['url'])
- 🇫🇷France NicociN
There are cases in `ui_suite_dsfr_preprocess_pattern_footer_menu()` where `$item['url']` is an `Url`object, so we also need to check this "instanceof". I create a MR.
NB : no need to use `is_object()` as `instanceof` deals with it.
- Merge request !83Issue #3448313 by NicociN: External link check creates a 500 error → (Merged) created by NicociN
- Assigned to pdureau
- Status changed to Needs review
6 months ago 4:09pm 23 May 2024 - 🇫🇷France pdureau Paris
Great, i will merge tomorrow and release the RC2.
For your information, with the upcoming UI Patterns 2.x, such task will not needed because the prop type will automatically take care of the normalisation: https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/PropType...
- Issue was unassigned.
- Status changed to Fixed
6 months ago 6:55am 24 May 2024 - Status changed to Needs work
6 months ago 3:38pm 24 May 2024 - 🇷🇪Réunion Martygraphie Saint-Denis (Réunion)
Hello,
I'm still having problems with this approach:- Tokens ( and returns an empty url with the approach $item[‘url’]->toString(); , which is annoying because you can no longer distinguish between elements.
- Attributes defined for links in the administration space are not retrieved (e.g. class).
@pdureau, should I create a new isssue?
- Status changed to Fixed
6 months ago 5:30pm 24 May 2024 - 🇷🇪Réunion Martygraphie Saint-Denis (Réunion)
I've created a new issue #3449679 , I'm closing this one again
Automatically closed - issue fixed for 2 weeks with no activity.