- Merge request !1949Issue #3268547: Document that views_get_current_view() can return NULL β (Closed) created by prudloff
- πΊπΈUnited States smustgrave
I added the code from the IS into ClaroPreRender.php and ran drupal-check on the folder.
Confirmed the issue is therebut the fix in the MR did not make it go away
- Status changed to Needs review
2 months ago 10:38pm 27 February 2025 - π«π·France prudloff Lille
@smustgrave I tried reproducing with your method.
I am adding this change:diff --git a/core/themes/claro/src/ClaroPreRender.php b/core/themes/claro/src/ClaroPreRender.php index 82f73ac9fa3..3b566998894 100644 --- a/core/themes/claro/src/ClaroPreRender.php +++ b/core/themes/claro/src/ClaroPreRender.php @@ -16,6 +16,10 @@ class ClaroPreRender implements TrustedCallbackInterface { * Prerender callback for managed_file. */ public static function managedFile($element) { + if ($view = views_get_current_view()) { + + } + if (!empty($element['remove_button']) && is_array($element['remove_button'])) { $element['remove_button']['#attributes']['class'][] = 'button--extrasmall'; $element['remove_button']['#attributes']['class'][] = 'remove-button';
Then I am calling
./vendor/bin/phpstan analyze core/themes/claro/src/ClaroPreRender.php --level 5
.Without the patch:
------ -------------------------------------------------------------------------------------------------------------------------------------------- Line ClaroPreRender.php ------ -------------------------------------------------------------------------------------------------------------------------------------------- 19 If condition is always true. πͺͺ if.alwaysTrue π‘ Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon. ------ --------------------------------------------------------------------------------------------------------------------------------------------
With the patch:
[OK] No errors
- πΊπΈUnited States smustgrave
Thanks for checking.
If false can be returned can the description be updated as well when false could be returned. 100% agree on the NULL and it's already there.
Will keep an eye out for this one to come back.
If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
- π«π·France prudloff Lille
ViewExecutable::postExecute() does this:
views_set_current_view($old_view ?? FALSE);
Now that I think about it, wouldn't it be cleaner to change it like this:
views_set_current_view($old_view);
And only document
ViewExecutable|null
as allowed values?I feel like null has a clearer meaning that false here.
- π«π·France prudloff Lille
OK I see why ViewExecutable::postExecute() calls views_set_current_view() with FALSE: calling it with null does not change the cached value, so calling it with false is a way to explicitly remove the cached value.
So I will just document the current behavior. - πΊπΈUnited States smustgrave
Can you drop the return types, think adding those requires more work for BC. Fine to self RTBC after that
If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
Automatically closed - issue fixed for 2 weeks with no activity.