Move drupal_find_theme_templates and drupal_find_theme_functions to Theme Registry service

Created on 10 November 2015, about 9 years ago
Updated 30 January 2023, almost 2 years ago

Problem/Motivation

Conceptually, the discovery of theme functions and templates is part of the Theme Registry. In actuality, the two discover functions (drupal_find_theme_templates() and drupal_find_theme_functions()) are still in theme.inc and portions of them call the Theme Registry service.

The practical implication is that extending/modifying template discovery is much harder with these procedural functions.

Proposed resolution

  • Create methods on the theme registry service for finding theme templates and theme functions.
  • Have the procedural functions to nothing more than wrap the service.

Remaining tasks

Mark functions as deprecated?
Update interface?

User interface changes

None

API changes

Mark the procedural functions as deprecated?

Data model changes

none

📌 Task
Status

Needs work

Version

10.1

Component
Theme 

Last updated about 3 hours ago

Created by

🇺🇸United States stevector Minneapolis, MN

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇫🇷France andypost

    needs re-roll for 10.1 and fix deprecation to that version

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    MR had just a few failures.

  • First commit to issue fork.
  • 🇮🇳India bhanu951
    Warning: foreach() argument must be of type array|object, string given in Drupal\Core\Theme\Registry->findThemeFunctions() (line 932 of /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/Registry.php)
    #0 /var/www/html/repos/drupal/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'foreach() argum...', '/var/www/html/r...', 932)
    #1 /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/Registry.php(932): _drupal_error_handler(2, 'foreach() argum...', '/var/www/html/r...', 932)
    #2 /var/www/html/repos/drupal/core/themes/engines/twig/twig.engine(17): Drupal\Core\Theme\Registry->findThemeFunctions(Array, '.html.twig', 'core/themes/cla...')
    #3 /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/Registry.php(455): twig_theme(Array, 'theme_engine', 'claro', 'core/themes/cla...')
    #4 /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/Registry.php(370): Drupal\Core\Theme\Registry->processExtension(Array, 'twig', 'theme_engine', 'claro', 'core/themes/cla...')
    #5 /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/Registry.php(247): Drupal\Core\Theme\Registry->build()
    #6 /var/www/html/repos/drupal/core/lib/Drupal/Core/Utility/ThemeRegistry.php(88): Drupal\Core\Theme\Registry->get()
    #7 /var/www/html/repos/drupal/core/lib/Drupal/Core/Utility/ThemeRegistry.php(69): Drupal\Core\Utility\ThemeRegistry->initializeRegistry()
    #8 /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/Registry.php(267): Drupal\Core\Utility\ThemeRegistry->__construct('theme_registry:...', Object(Drupal\Core\Cache\ChainedFastBackend), Object(Drupal\Core\ProxyClass\Lock\DatabaseLockBackend), Array, true)
    #9 /var/www/html/repos/drupal/core/lib/Drupal/Core/Theme/ThemeManager.php(141): Drupal\Core\Theme\Registry->getRuntime()
    #10 /var/www/html/repos/drupal/core/lib/Drupal/Core/Render/Renderer.php(436): Drupal\Core\Theme\ThemeManager->render('file_upload_hel...', Array)
    #11 /var/www/html/repos/drupal/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, true)
    #12 /var/www/html/repos/drupal/core/lib/Drupal/Core/Render/Renderer.php(160): Drupal\Core\Render\Renderer->render(Array, true)
    #13 /var/www/html/repos/drupal/core/lib/Drupal/Core/Render/Renderer.php(583): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
    #14 /var/www/html/repos/drupal/core/lib/Drupal/Core/Render/Renderer.php(161): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #15 /var/www/html/repos/drupal/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php(269): Drupal\Core\Render\Renderer->renderPlain(Array)
    #16 /var/www/html/repos/drupal/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php(144): Drupal\file\Plugin\Field\FieldWidget\FileWidget->formElement(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
    #17 /var/www/html/repos/drupal/core/lib/Drupal/Core/Field/WidgetBase.php(349): Drupal\image\Plugin\Field\FieldWidget\ImageWidget->formElement(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
    #18 /var/www/html/repos/drupal/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php(167): Drupal\Core\Field\WidgetBase->formSingleElement(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
    #19 /var/www/html/repos/drupal/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php(117): Drupal\file\Plugin\Field\FieldWidget\FileWidget->formMultipleElements(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), Array, Object(Drupal\Core\Form\FormState))
    #20 /var/www/html/repos/drupal/core/lib/Drupal/Core/Field/WidgetBase.php(111): Drupal\image\Plugin\Field\FieldWidget\ImageWidget->formMultipleElements(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), Array, Object(Drupal\Core\Form\FormState))
    #21 /var/www/html/repos/drupal/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(183): Drupal\Core\Field\WidgetBase->form(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), Array, Object(Drupal\Core\Form\FormState))
    #22 /var/www/html/repos/drupal/core/lib/Drupal/Core/Entity/ContentEntityForm.php(121): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object(Drupal\user\Entity\User), Array, Object(Drupal\Core\Form\FormState))
    #23 /var/www/html/repos/drupal/core/modules/user/src/AccountForm.php(311): Drupal\Core\Entity\ContentEntityForm->form(Array, Object(Drupal\Core\Form\FormState))
    #24 /var/www/html/repos/drupal/core/lib/Drupal/Core/Entity/EntityForm.php(106): Drupal\user\AccountForm->form(Array, Object(Drupal\Core\Form\FormState))
    #25 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
    #26 /var/www/html/repos/drupal/core/lib/Drupal/Core/Form/FormBuilder.php(534): call_user_func_array(Array, Array)
    #27 /var/www/html/repos/drupal/core/lib/Drupal/Core/Form/FormBuilder.php(281): Drupal\Core\Form\FormBuilder->retrieveForm('user_form', Object(Drupal\Core\Form\FormState))
    #28 /var/www/html/repos/drupal/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\user\ProfileForm), Object(Drupal\Core\Form\FormState))
    #29 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #30 /var/www/html/repos/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #31 /var/www/html/repos/drupal/core/lib/Drupal/Core/Render/Renderer.php(583): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #32 /var/www/html/repos/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #33 /var/www/html/repos/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #34 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #35 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #36 /var/www/html/repos/drupal/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #37 /var/www/html/repos/drupal/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #38 /var/www/html/repos/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #39 /var/www/html/repos/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #40 /var/www/html/repos/drupal/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #41 /var/www/html/repos/drupal/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #42 /var/www/html/repos/drupal/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #43 /var/www/html/repos/drupal/core/lib/Drupal/Core/DrupalKernel.php(698): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #44 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #45 {main}
    .
    

    Getting this error , which is causing the test failures.

  • 🇫🇷France andypost

    Updated title as only one left

    +++ b/core/includes/theme.inc
    @@ -114,53 +114,14 @@ function drupal_theme_rebuild() {
     function drupal_find_theme_functions($cache, $prefixes) {
    

    is deprecated and removed

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Build Successful
  • 🇧🇷Brazil elber Brazil

    Hi I just rebased

  • 🇫🇷France andypost

    It needs work to remove all mentions of "theme function", left a set of review-comments

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,380 pass
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,381 pass
  • Status changed to Needs work over 1 year ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    From @andypost review:

    • findThemeFunctions is not removed
    • core/lib/Drupal/Core/Theme/Registry.php is not refactored
  • last update over 1 year ago
    29,500 pass
  • 🇮🇳India bhanu951

    Adding MR changes as patch for backup before rebase.

  • Pipeline finished with Failed
    27 days ago
    Total: 108s
    #352704
  • Pipeline finished with Failed
    27 days ago
    Total: 195s
    #352712
  • Pipeline finished with Failed
    27 days ago
    Total: 1037s
    #352742
  • Pipeline finished with Failed
    27 days ago
    Total: 644s
    #352757
  • Pipeline finished with Success
    27 days ago
    Total: 605s
    #352774
  • Pipeline finished with Failed
    27 days ago
    Total: 207s
    #352779
  • Pipeline finished with Failed
    27 days ago
    Total: 160s
    #352789
  • Pipeline finished with Failed
    27 days ago
    Total: 495s
    #352802
  • Pipeline finished with Failed
    27 days ago
    Total: 148s
    #352872
  • Pipeline finished with Failed
    27 days ago
    Total: 675s
    #352875
  • Pipeline finished with Failed
    27 days ago
    Total: 151s
    #352939
  • Pipeline finished with Success
    27 days ago
    Total: 1431s
    #352943
  • 🇮🇳India bhanu951

    Made changes to MR and address review comments.

    Now sure how to handle adding new constructor argument.

    Created new issue to add handle adding new constructor argument. 📌 Inject the file_system service in the theme registry service Active .

    Should we handle adding new constructor argument in this issue or in other issue ?

  • Pipeline finished with Success
    27 days ago
    Total: 979s
    #352994
  • 🇺🇸United States smustgrave

    Left some small comments on the MR

  • Pipeline finished with Failed
    25 days ago
    Total: 238s
    #354892
  • 🇮🇳India bhanu951

    @smustgrave

    Phpcs failing without those nit changes hence keeping them.

  • 🇺🇸United States nicxvan

    This looks pretty good. I have a couple of comments.

    1. There seems to be a lot of our of scope code style changes were those causing actual failures?
    2. You do not need to test pure bc wrapper functions, please remove that test.

    My question is did we consider adding a helper?
    Then we could inject that new helper into registry and the twig engine. It seems like a lot to use the whole registry just to get the templates in the engine.

  • 🇮🇳India bhanu951

    @nicxvan : Thanks for the review.

    > My question is did we consider adding a helper ?

    AFAIK, there wasn't any discussion in this regards.

    > It seems like a lot to use the whole registry just to get the templates in the engine.

    Agreed.

    > I really think this piece should be moved to a themetemplatefinder.

    Seems reasonable. Where do you suggest its location ?

    How does core/lib/Drupal/Core/Theme/Themetemplatefinder.php sound ?

    Ad do we need interface for this ?

  • 🇺🇸United States nicxvan

    I'd go with:

    core/lib/Drupal/Core/Theme/TemplateFinder.php

    I don't think it needs an interface, I may be wrong about the interface though.

Production build 0.71.5 2024