Problem/Motivation

Themes can now be OOP, let's convert what we can.

Then let's move remaining procedural functions. ⁷

Steps to reproduce

Open theme files.

Proposed resolution

Add procedural test coverage: #3579629: Add procedural hooks to test theme to test collection and invoking legacy hooks

Core themes
Convert the missed hooks and move the remaining functions to the correct hook class

Test themes #3579903: Eliminate Olivero and three test .theme files

  • access_test.theme
    • Keep this file
  • test_installer_theme.theme
    • test_installer_theme_form_install_select_language_form_alter
    • Test converting this
  • test_missing_base_theme.theme
    • Delete this file
  • views_test_checkboxes_theme.theme
    • views_test_checkboxes_theme_form_views_exposed_form_alter
    • Convert this hook

Identify if there are any functions that cannot be in classes.

Remaining tasks

N/A

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3554670

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:

Comments

nicxvan created an issue. See original summary.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes

berdir’s picture

I'd really prefer to do the big themes properly grouped and not just one big hooks class. And those in a dedicated issue.

We know better now how to group them and otherwise it will result in another chain of follow ups

nicxvan’s picture

At first I agreed with you, I was really just testing how this worked with themes for rector.

However, I think we should do this automatically for a few reasons.

1. Test rector on themes
2. We've seen how long even just simple organization can take in the queue, let's at least remove the .theme files I think followups will be simpler for themes
3. I think with the comment issue this is pretty much done and will be ready for testing

nicxvan changed the visibility of the branch 11.x to hidden.

nicxvan changed the visibility of the branch 3554670-meta-convert-themes to hidden.

nicxvan changed the visibility of the branch 3554670-conversionv2 to hidden.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
berdir’s picture

The fail in InstallerTranslationTest happens on /admin/config/regional/language and the exception backtrace is this:

InvalidArgumentException: Class "Drupal\test_theme\Hook\TestThemeHooks" does not exist. in /var/www/html/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php:32
Stack trace:
#0 /var/www/html/core/lib/Drupal/Core/Utility/CallableResolver.php(100): Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition()
#1 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(592): Drupal\Core\Utility\CallableResolver->getCallableFromDefinition()
#2 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(552): Drupal\Core\Theme\ThemeManager->getImplementationsForTheme()
#3 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(620): Drupal\Core\Theme\ThemeManager->alterForTheme()
#4 /var/www/html/core/lib/Drupal/Core/Render/ElementInfoManager.php(135): Drupal\Core\Theme\ThemeManager->alter()
#5 /var/www/html/core/lib/Drupal/Core/Render/ElementInfoManager.php(71): Drupal\Core\Render\ElementInfoManager->buildInfo()
#6 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(865): Drupal\Core\Render\ElementInfoManager->getInfo()
#7 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(305): Drupal\Core\Form\FormBuilder->prepareForm()
#8 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(244): Drupal\Core\Form\FormBuilder->buildForm()
#9 /var/www/html/core/lib/Drupal/Core/Entity/DraggableListBuilderTrait.php(121): Drupal\Core\Form\FormBuilder->getForm()
#10 /var/www/html/core/lib/Drupal/Core/Entity/Controller/EntityListController.php(23): Drupal\Core\Config\Entity\DraggableListBuilder->render()
#11 [internal function]: Drupal\Core\Entity\Controller\EntityListController->listing()
#12 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#13 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(634): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#14 [internal function]: Drupal\Core\Render\Renderer::Drupal\Core\Render\{closure}()
#15 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(635): Fiber->start()
#16 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#17 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(183): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#20 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#21 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#22 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#23 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(118): Drupal\Core\StackMiddleware\ContentLength->handle()
#24 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(92): Drupal\page_cache\StackMiddleware\PageCache->pass()
#25 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#26 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#27 /var/www/html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(53): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#28 /var/www/html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(54): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#29 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(745): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#30 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#31 {main}

The test has protected $defaultTheme = 'test_theme'; but on that page, \Drupal::getContainer()->getParameter('container.themes') only has stark. Changing the test to use stark gets the test passed that line but fails later due to theme specific checks.

I'm guessing installer tests don't set up the theme properly, they set it as the active one without properly installing it.

nicxvan’s picture

Thank you!

// Ensure the default theme is installed.
$container->get('theme_installer')->install([$this->defaultTheme], TRUE);

Is in the installerTestBase and adding the install during the test doesn't fix it either. I'll have to investigate further.

Edit, just to see where this was going wrong I added:
$themes = \Drupal::getContainer()->getParameter('container.themes');
Right before where the test dies and I see:

  • stark
  • stable9
  • starterkit_theme
  • test_theme

I'll try reviewing from the other direction.

nicxvan’s picture

Ok I dug in more to the Theme settings failure, and it's a weird one, it's because test_theme_theme isn't the admin theme so the hook adding the field doesn't run.

Setting it to the admin theme works manually testing, I tried:

    $edit['admin_theme'] = $theme;
    $this->drupalGet('admin/appearance');
    $this->submitForm($edit, 'Save configuration');

and

    \Drupal::configFactory()
      ->getEditable('system.theme')
      ->set('admin', $theme)
      ->save();

Neither work in the test.

Reverting the hook does work though.

nicxvan’s picture

I found the theme settings failure, we call it directly:

 // Call theme-specific settings.
        $function = $theme . '_form_system_theme_settings_alter';
        if (function_exists($function)) {
          $function($form, $form_state);
        }

I'll revert that one conversion for now and create a follow up.

nicxvan’s picture

#3560833: Create better way to manage theme setting alters I'm going to revert that conversion here.

nicxvan’s picture

Title: [meta] Convert themes to OOP » Convert themes to OOP

I also reverted test theme for #3560851: Convert test_theme to OOP

nicxvan’s picture

Issue summary: View changes
phenaproxima’s picture

Status: Active » Needs review

I am not entirely qualified to sign off on this, but I do like how the actual change is like 10 lines long, and the rest of this is just removing .theme files in favor of classes. That's really nice to see.

Maybe a comment in the theme registry, to clarify what it's doing, would be nice? It's hard to grok without a lot of background context loaded into one's brain.

nicxvan’s picture

Status: Needs review » Active

Thank you, I addressed all of your feedback.

I think it's actually better to keep the change in #3556794: preprocess_HOOK__candidates in themes can be assigned to module invoke maps since several of the conversions here test that better than the test in that dedicated issue.

This should be ready for review again.

catch’s picture

Status: Active » Needs review

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

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

nicxvan’s picture

Title: Convert themes to OOP » [meta] Eliminate core .theme files
Issue summary: View changes
nicxvan’s picture

Issue summary: View changes

nicxvan changed the visibility of the branch 3554670-conversionv3 to hidden.

nicxvan’s picture

Converted this to a meta, I created three issues for the remaining core themes.

I'll create follow ups for the .theme files once those are all committed.

nicxvan’s picture

Just a couple more!

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
berdir’s picture

The claro_system functions I think shouldn't be in claro at all I think, they are currently called by system module, but all of that and the related helpers should be moved to toolbar, which is moving to contrib, it's overlapping with the system.module function removal issue. I think it makes sense to do them together.

nicxvan’s picture

Yeah I'll remove that here, then update the system.module issue once this and the translation config one lands.

Created #3579899: Remove remaining claro.theme functions

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture