Closed (fixed)
Project:
Drupal core
Version:
9.4.x-dev
Component:
theme system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
5 Jul 2016 at 09:20 UTC
Updated:
12 Apr 2022 at 10:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
David_Rothstein commentedDon't think there's a reason for this one to be postponed (currently the Drupal 7 issue is marked postponed on it).
Comment #4
vmachado commentedPatch attached.
Comment #5
fabianx commentedRTBC - Though committers very likely want tests for this, so setting to RTBC, so they can confirm that assumption.
Comment #6
alexpottAssumption confirmed :)
Comment #7
joelpittet@Fabianx, I was trying to write tests but ran to a question. Should these callables support suggestions some how?
Example in core tests that I was looking to add too is
test_theme_theme_test_function_suggestions__theme_overrideComment #8
fabianx commentedI think you would only add those manually to the theme registry via hook_theme_registry_alter() as we only support auto-detection for functions really.
Comment #9
lauriiiCreated some tests for this
Comment #10
lauriiiComment #12
joelpittetCool thanks @lauriii besides an extra linebreak that works to demonstrate the feature's functionality.
Comment #13
lauriiiRemoved the change for the theme functions since they are deprecated.
Comment #14
lauriiiComment #15
fabianx commentedRTBC + 1
Comment #17
manuel garcia commented+1
Comment #18
fabianx commentedBack to RTBC, the test fail was unrelated.
Comment #19
alexpottDo we care about the performance difference here?
I did some quick profiling with the script attached.
The good thing is this change will have little difference in PHP7 afaics. I guess the question is how many times do we call a preprocess function on a page? Definitely not the 3,000,000 calls of the script. On perhaps a more realistic check on PHP5.5 where $iterations is 100 the script results in:
So double not very much.
Comment #20
fabianx commentedThe important part is the is_callable(), which is also already a little bit slower.
We could also do:
The only advantage of c_u_f_a is that also 'Class::method' works consistently on PHP 5.5, too, but I am not sure we need / want to support that.
['Class', 'method'] works also for $function() and Drupal 7 will have only this callable variant and not use c_u_f_a at all (for BC reasons).
Comment #21
xjmTo me this doesn't look worth micro-optimization
, but the proposed code flow in #20 also looks finesee below. I pinged catch for a second opinion and he said if it's negligible on PHP7 he doesn't mind (but also added that he's looking forward to deprecating preprocess functions as well as theme functions).@cilefen pointed out that we support callables elsewhere as well, e.g. in Form API. I looked up how we do that. FormStateInterface::prepareCallback() accepts a callback specified as
::methodName(). The implementation:So that is a bit more hardcoded than what we want to support here.
@cilefen and I also agreed that it would be good to add a change record for this, especially if we are not adding it for deprecated theme functions.
Comment #22
xjm@catch also said:
Comment #26
markhalliwellRe: perf
Considering that PHP 5 support will be officially removed in March, perhaps this should wait for 8.7.x? That way we don't have to worry about it. I mean, we've already waited many years for this very annoying issue to get fixed, what's a few more months :D
I would also argue that that is actually now a "bug" of 8.x. Almost every callback in 8.x allows for various types of callables (including services) due to its heavy OO nature. This limitation/drupalism was simply inherited from the previous 7.x theme system and never properly fixed when migrated from procedural code to classes.
Comment #27
markhalliwellOh and #2869859: [PP-1] Refactor theme hooks/registry into plugin managers will likely completely remove the need for any arbitrary functions like this anyway, so this particular issue probably won't be much of one in the future anyway (except in BC cases).
Comment #28
markhalliwellComment #30
anya_m commentedRerolled
Comment #31
alexpottStill needs a change record - needs work for this. I'm +1 on the change - brings things into line.
I had a quick think about if this widens any security concerns because theme callbacks have been involved in recents security advisories but that's when they can be part of the render array and these cannot.
Comment #38
lemming commentedAdded change record for the issue - https://www.drupal.org/node/3266641
Comment #39
yogeshmpawarResolved CSpell errors & removed change record tag from this issue.
Comment #41
yogeshmpawarUpdated patch will fix test failures.
Comment #43
yogeshmpawarMissed one test failure in previous patch so resolved in this patch.
Comment #44
lemming commentedPatch #43 is working for me on Core 9.3.
+1
Comment #45
jhedstromAs noted in #31 this was only waiting on a CR, which was added in #38. Moving back to RTBC.
Comment #46
alexpottCommitted and pushed fb3dc749ac to 10.0.x and 9a265629be to 9.4.x. Thanks!
Comment #49
joachim commentedDoes this really allow all PHP callables? Even anonymous functions?