Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Theme preprocessor callbacks are still stuck with using global functions:
$function = $form['whatever callback'];
$result = $function($form, $form_state);
This inhibits the usage of proper callbacks and makes mixing OOP with D7 a complete mess.
Proposed resolution
Change the way these callbacks are invoked.
Remaining tasks
Review
User interface changes
None
API changes
None.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#2 | 2652834-fix-theme-callbacks.patch | 777 bytes | david_garcia |
Comments
Comment #2
david_garcia CreditAttribution: david_garcia commentedThat should do it.
Comment #3
izaaksom CreditAttribution: izaaksom commentedA step further into OOP, Thanks. :D! Fix worked perfectly.
Comment #4
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedNice work, pending commit!
Comment #5
stefan.r CreditAttribution: stefan.r commentedComment #6
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedSee comment at #2652814-8: Allow the use of callbacks for element value callbacks and batch API redirect callbacks which applies here too.
Comment #7
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThe is_callable() part we definitely can do, the $function => call_user_func_array() we should remove for now.
Comment #8
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAdding Novice tag as it should be simple to just leave is_callable().
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedCommitted and pushed to 7.x! Thanks!
I fixed the removal of the call_user_func_array() on commit and also made it possible to use any callable for theme functions.
Comment #12
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThis is still present in D8 and needs to be fixed there first.
Comment #13
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #14
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedD8 issue: #2760659: Allow the use of callbacks instead of global functions in preprocess function callbacks
Comment #15
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #16
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI think this is small enough to be a task.
Comment #17
Ayesh CreditAttribution: Ayesh commentedAdding the issue that we collectively add tests for these changes (correct me if I'm wrong please).
Comment #18
Ayesh CreditAttribution: Ayesh commentedComment #19
MustangGB CreditAttribution: MustangGB commentedMoving to 7.70 for now as waiting for D8 commit.