Problem/Motivation
It should be caused by carelessness.
\Drupal\Core\Theme\Registry::postProcessExtension
the line 721:
if (isset($cache[$hook]['preprocess functions']) && !in_array($hook, $cache[$hook]['preprocess functions'])) {
It should be:
if (isset($cache[$hook]['preprocess functions']) && !in_array($preprocessor, $cache[$hook]['preprocess functions']))
The in_array will always fail and the preprocess hook is added to the cache, creating duplicates. Ultimately, this is not a problem because later in the method array_unique is used to remove duplicates.
// Ensure uniqueness.
if (isset($cache[$hook]['preprocess functions'])) {
$cache[$hook]['preprocess functions'] = array_unique($cache[$hook]['preprocess functions']);
}
Steps to reproduce
Read the code
Proposed resolution
Fix the needle in the in_array to $preprocess
if (isset($cache[$hook]['preprocess functions']) && !in_array($preprocessor, $cache[$hook]['preprocess functions']))
Remaining tasks
Patch
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 2967627-8.patch | 840 bytes | quietone |
Comments
Comment #2
cilefen commented@yunke If possible, would you please post patches? The issues will be fixed faster that way.
Comment #8
quietone commentedWriting an automated test to prove there are no duplicates in the array isn't possible because an array_unique is run on the array later in the method. To have a test the method would have to be split into two which, to me, seems unnecessary for this fix.
To see what happens, I removed the array_unique and then \Drupal\KernelTests\Core\Theme\RegistryTest::testThemeTemplatesRegisteredByModules failed.
Comment #9
smustgrave commentedLooks good to me. Clean and easy to read
Comment #10
pappisI use module_preprocess_node__some_page to add a js library to that specific page with
$variables['#attached']['library'][] = 'module/js_library';and sometimes the js code from the library gets loaded twice.
Maybe this is the reason ?
Comment #12
catchCommitted/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!