Problem/Motivation

Conceptually, the discovery of templates is part of the Theme Registry. At the moment, the discovery (drupal_find_theme_templates()) is 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

Issue fork drupal-2612800

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stevector created an issue. See original summary.

stevector’s picture

Assigned: stevector » Unassigned
Status: Active » Needs review
FileSize
14.73 KB

Here's a first pass.

Status: Needs review » Needs work

The last submitted patch, 2: theme-discovery-2612800-2.patch, failed testing.

stevector’s picture

I had an errant debug message in that last patch.

stevector’s picture

Status: Needs work » Needs review

The last submitted patch, 2: theme-discovery-2612800-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: theme-discovery-2612800-4.patch, failed testing.

stevector’s picture

Status: Needs work » Needs review
FileSize
14.08 KB

Odd,

$theme = $this->theme->getName();

fails in one test but this does not:

$theme = $this->themeManager->getActiveTheme()->getName();

Trying again.

joelpittet’s picture

Status: Needs review » Needs work

Thanks for this clean-up. These is my favourite clean-ups:)

+++ b/core/includes/theme.inc
@@ -117,51 +117,8 @@ function drupal_theme_rebuild() {
  *   The functions found, suitable for returning from hook_theme;
  */
 function drupal_find_theme_functions($cache, $prefixes) {

Likely will need those deprecated notices in the docblocks.

re #8 that is strange.

+++ b/core/lib/Drupal/Core/Theme/Registry.php
@@ -766,4 +766,168 @@ public function getPrefixGroupedUserFunctions() {
+  public function find_theme_templates($cache, $extension, $path) {

Since this is a OOP thing now it should be findThemeTemplates() or just findTemplates() to save a bit of redundency but most important is the camel casing for methods.

stevector’s picture

Thanks for the review! This patch adds the deprecated notice, camel casing and fixes an unnecessary line break.

joelpittet’s picture

Thanks for the cleanup @stevector. This is the related type of move #2591515: Move twig_without() to the TwigExtension where all the other filters are and deprecate and this patch is trying to touch the same bit of code #2339447: Improve theme registry build performance by 85% which may cause a re-roll.

Not sure if this will will make it into a patch release or 8.1.x, so I'll just leave it until 8.0.0 is released.

The last submitted patch, 2: theme-discovery-2612800-2.patch, failed testing.

The last submitted patch, 4: theme-discovery-2612800-4.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markhalliwell’s picture

I like the idea of this issue, getting rid of procedural functions, but I think we can do one better and make this one of the goals of #2869859: [PP-1] Refactor theme hooks/registry into plugin managers.

This way, themes (base themes) would finally have the power to properly hook into this process.

markhalliwell’s picture

markhalliwell’s picture

Version: 8.5.x-dev » 8.6.x-dev
Related issues: +#2957440: Refactor ThemeRegistry and Theme\Registry

The above issue #2869859: [PP-1] Refactor theme hooks/registry into plugin managers really makes this issue a moot point.

This issue really pertains to #2957440: Refactor ThemeRegistry and Theme\Registry for BC purposes.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
148 bytes

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.

andypost’s picture

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

Bhanu951 made their first commit to this issue’s fork.

Bhanu951’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
smustgrave’s picture

Status: Needs review » Needs work

MR had just a few failures.

Bhanu951’s picture

VladimirAus made their first commit to this issue’s fork.

Bhanu951’s picture

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.

andypost’s picture

Title: Move drupal_find_theme_templates and drupal_find_theme_functions to Theme Registry service » Deprecate drupal_find_theme_templates to Theme Registry service
Issue summary: View changes

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

elber made their first commit to this issue’s fork.

elber’s picture

Hi I just rebased

andypost’s picture

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

bharath-kondeti made their first commit to this issue’s fork.

bharath-kondeti’s picture

Status: Needs work » Needs review
VladimirAus’s picture

Status: Needs review » Needs work

From @andypost review:

  • findThemeFunctions is not removed
  • core/lib/Drupal/Core/Theme/Registry.php is not refactored

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.