All this functions are deprecated in #2109287: Replace list_themes() with a service.
So let's clean-up their usage

CommentFileSizeAuthor
#88 interdiff.txt510 bytesJeroenT
#88 clean_up_usage_of-2151469-88.patch25.95 KBJeroenT
#85 2151469-85.patch25.96 KBrpayanm
#85 2151469-interdiff.txt1.91 KBrpayanm
#83 2151469-83.patch24.84 KBrpayanm
#83 2151469-interdiff.txt1.79 KBrpayanm
#81 2151469-interdiff-71-80.txt2.7 KBrpayanm
#80 2151469-80.patch24.7 KBrpayanm
#80 2151469-interdiff.txt920 bytesrpayanm
#78 2151469-78.patch24.31 KBrpayanm
#78 2151469-interdiff.txt1012 bytesrpayanm
#76 2151469-76.patch23.32 KBrpayanm
#76 2151469-interdiff.txt821 bytesrpayanm
#74 2151469-74.patch23.32 KBrpayanm
#74 2151469-interdiff.txt534 bytesrpayanm
#72 2151469-72.patch22.8 KBrpayanm
#72 2151469-interdiff.txt1.99 KBrpayanm
#66 2151469-66.patch21.37 KBrpayanm
#64 clean_up_usage_of-2151469-64.patch21.37 KBianthomas_uk
#61 interdiff.txt3.34 KBJeroenT
#61 clean_up_usage_of-2151469-61.patch21.48 KBJeroenT
#59 interdiff.txt7.22 KBJeroenT
#59 clean_up_usage_of-2151469-59.patch18.99 KBJeroenT
#56 interdiff.txt543 bytesJeroenT
#56 clean_up_usage_of-2151469-56.patch17.35 KBJeroenT
#55 interdiff.txt9.73 KBJeroenT
#55 clean_up_usage_of-2151469-55.patch17.34 KBJeroenT
#54 clean_up_usage_of-2151469-54.patch10.95 KBJeroenT
#52 clean_up_usage_of-2151469-52.patch11.33 KBalansaviolobo
#49 interdiff.txt46.73 KBalansaviolobo
#49 clean_up_usage_of-2151469-49.patch27.53 KBalansaviolobo
#42 2151469-42.patch38.6 KBlokapujya
#40 2151469-40.patch41 KBlokapujya
#38 2151469-deprecated-block.patch8.41 KBlokapujya
#36 deprecated-some-modules-redo.patch0 byteslokapujya
#35 2152469-color.patch588 byteslokapujya
#33 2151469-some-modules.patch8.38 KBlokapujya
#30 2151469-block.patch9.99 KBlokapujya
#28 2151469-28.patch42.47 KBlokapujya
#26 interdiff.txt654 byteslokapujya
#26 2151469-26.patch43.17 KBlokapujya
#24 2151469-24.patch43.81 KBlokapujya
#17 deprecated-2151469-17.patch49.08 KBpflame
#15 deprecated-2151469-15.patch52.31 KBpflame
#10 deprecated-2151469-10.patch51.27 KBRichard Damon
#3 deprecated-2151469-3.patch46.38 KBRichard Damon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Richard Damon’s picture

Assigned: Unassigned » Richard Damon

Working on this

eporama’s picture

Just to make sure, we're on the right track, we're talking about a *lot* of this type of change:

 $ git diff
diff --git a/core/includes/config.inc b/core/includes/config.inc
index 8e9ce5e..3742ec1 100644
--- a/core/includes/config.inc
+++ b/core/includes/config.inc
@@ -53,7 +53,7 @@ function ($value) use ($name) {
       }
     );
     $enabled_extensions = array_keys(\Drupal::moduleHandler()->getModuleList());
-    $enabled_extensions += array_keys(array_filter(list_themes(), function ($theme) {return $theme->status;}));
+    $enabled_extensions += array_keys(array_filter(\Drupal::service('theme_handler')->listInfo(), function ($theme) {return $theme->status;}));

     $other_module_config = array_filter($other_module_config, function ($config_name) use ($enabled_extensions) {
       $provider = Unicode::substr($config_name, 0, strpos($config_name, '.'));

Should we have one massive patch for this? Or handle modules individually? And as Gábor mentions, individual modules may have a lot more things that need to be changed like config_translation which has code just to get around this.

Richard Damon’s picture

FileSize
46.38 KB

Here is a patch replacing all the depreciated procedural calls with calls to the service. Someone with a bit more understanding of things can look at what can be simplified because of this.

Richard Damon’s picture

Status: Active » Needs review
tstoeckler’s picture

Status: Needs review » Needs work

Wow, quite a massive patch, nice work!
There's a detailed review below, which basically boils down to a few things:

  • The changes in the test files are fine.
  • In almost all of the other classes the theme handler should be injected. I've given specific instructions in all cases, but they're not very elaborate so don't hesitate to ask if you're having problems with this!!!
  • When referencing the functions in documentation ThemeHandlerInterface should be referenced instead of \Drupal::service('theme_handler'). In @see (and other PhpDoc statements) the full namespace should be specified as well, i.e. \Drupal\Core\Extension\ThemeHandlerInterface
  • At some places we can save a tiny bit of performance by saving $theme_handler into a local variable instead of calling \Drupal::service('theme_handler') multiple times

If this is overwhelming (which I could definitely understand!!!) you could also avoid all the injection stuff for now and limit this issue to the changes in the test files and then let the rest be handled in a separate issue. That's your call. :-)

Follow-up issues that should be created:

  • Inject all the things in DisplayPluginBase (something like this might already exist)
  • Make ThemeHandlerInterface::enable()/disable()/reset() chainable.
  1. +++ b/core/lib/Drupal/Core/Theme/Registry.php
    @@ -385,7 +385,7 @@ protected function build() {
    -   *   The loaded $theme object as returned from list_themes().
    +   *   The loaded $theme object as returned from \Drupal::service('theme_handler')->listInfo().
    

    This does not wrap at 80 characters, but more importantly this should say "ThemeHandlerInterface::listInfo()" instead of \Drupal::service...

  2. +++ b/core/lib/Drupal/Core/Theme/Registry.php
    @@ -576,12 +576,12 @@ protected function getPath($module) {
       /**
    -   * Wraps list_themes().
    +   * Wraps \Drupal::service('theme_handler')->listInfo().
        *
        * @return array
        */
       protected function listThemes() {
    -    return list_themes();
    +    return \Drupal::service('theme_handler')->listInfo();
       }
    

    Instead of this change, the theme handler should be injected (see __construct() in this class and the core.services.yml file)
    and any usage of listThemes() in this class should be replaced by $this->themeHandler->listInfo() directly.

  3. +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php
    @@ -102,7 +102,7 @@ public function addForm(CustomBlockTypeInterface $custom_block_type, Request $re
    -    if (($theme = $request->query->get('theme')) && in_array($theme, array_keys(list_themes()))) {
    +    if (($theme = $request->query->get('theme')) && in_array($theme, array_keys(\Drupal::service('theme_handler')->listInfo()))) {
    

    The theme handler should be injected instead (see the __construct() and create() methods in this class).

  4. +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php
    @@ -236,7 +236,7 @@ public function form(array $form, array &$form_state) {
    -      foreach (list_themes() as $theme_name => $theme_info) {
    +      foreach (\Drupal::service('theme_handler')->listInfo() as $theme_name => $theme_info) {
    

    The theme handler should be injected here. (__contstruct() and create()).

  5. +++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php
    @@ -26,7 +26,7 @@ class BlockController extends ControllerBase {
    -    $themes = list_themes();
    +    $themes = \Drupal::service('theme_handler')->listInfo();
    

    BlockController doesn't use ContainerInjectionInterface yet, so I think it's fine to leave this as is.

    For extra credit, though, you could inject this as well. (Look at how CustomBlockController does it for guidance.)

  6. +++ b/core/modules/block/lib/Drupal/block/Plugin/Derivative/ThemeLocalTask.php
    @@ -47,7 +47,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
    -    foreach (list_themes() as $theme_name => $theme) {
    +    foreach (\Drupal::service('theme_handler')->listInfo() as $theme_name => $theme) {
    

    This should be injected (__construct() and create()).

  7. +++ b/core/modules/config_translation/lib/Drupal/config_translation/ConfigMapperManager.php
    @@ -89,13 +89,20 @@ public function __construct(CacheBackendInterface $cache_backend, LanguageManage
        * @return array
        *   An associative array of the currently available themes. The keys are the
    -   *   themes' machine names and the values are objects. See list_themes() for
    +   *   themes' machine names and the values are objects. See ThemeHandler::listInfo() for
        *   documentation on those objects.
        *
        * @todo Remove this once https://drupal.org/node/2109287 is fixed in core.
        */
       protected function getThemeList($refresh = FALSE) {
    -    return list_themes($refresh);
    +    $theme_handler = \Drupal::service('theme_handler');
    +
    +    if ($refresh) {
    +      $theme_handler->reset();
    +      system_list_reset();
    +    }
    +
    +    return $theme_handler->listInfo();
       }
    

    Per the todo, this function should be removed, and instead a) the theme handler should be injected (see the config_translation.services.yml) and all usages of getThemeList() should be replaced with direct calls to the theme handler. Note: ConfigMapperManagerTest will have to be updated for the constructor change.

  8. +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationBlockListController.php
    @@ -29,7 +29,8 @@ class ConfigTranslationBlockListController extends ConfigTranslationEntityListCo
    -    $this->themes = list_themes();
    +    $this->themes = \Drupal::service('theme_handler')->listInfo
    +    ();
    

    Weird wrapping here.

    More importantly, this should be injected as well. Here you have to actually use createInstance() (instead of the usual create()). You can look at how EntityListController does this.

  9. +++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php
    @@ -63,7 +63,7 @@ public function disable(Request $request) {
    -      $themes = list_themes();
    +      $themes = \Drupal::service('theme_handler')->listInfo();
    
    @@ -72,7 +72,7 @@ public function disable(Request $request) {
    -          theme_disable(array($theme));
    +          \Drupal::service('theme_handler')->disable(array($theme));
    
    @@ -104,11 +104,16 @@ public function enable(Request $request) {
    -      $themes = list_themes(TRUE);
    +      $theme_handler = \Drupal::service('theme_handler');
    +
    +      $theme_handler->reset();
    +      system_list_reset();
    +
    +      $themes = $theme_handler->listInfo();
    ...
    -        theme_enable(array($theme));
    +        \Drupal::service('theme_handler')->enable(array($theme));
    

    Here the theme handler should be injected (__construct() / create()).

    Also, the system_list_reset() should not be necessary, $this->themeHandler->reset() already takes care of that.

  10. +++ b/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php
    @@ -71,7 +71,7 @@ public function getFormId() {
    -    $themes = list_themes();
    +    $themes = \Drupal::service('theme_handler')->listInfo();
    
    @@ -82,7 +82,7 @@ public function buildForm(array $form, array &$form_state, $theme = '') {
    -      $themes = list_themes();
    +      $themes = \Drupal::service('theme_handler')->listInfo();
    

    This should be injected with the usual __construct() / create().

  11. +++ b/core/modules/system/lib/Drupal/system/Plugin/Derivative/ThemeLocalTask.php
    @@ -18,7 +18,7 @@ class ThemeLocalTask extends DerivativeBase {
    -    foreach (list_themes() as $theme_name => $theme) {
    +    foreach (\Drupal::service('theme_handler')->listInfo() as $theme_name => $theme) {
    

    Since this is a plugin (derivative) I don't think we can get by without injecting the theme handler. Look at other local task derivatives on how they do that, e.g. FieldUiLocalTask.

  12. +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php
    @@ -81,8 +81,8 @@ function setUp() {
    -    $this->themes = array_keys(list_themes());
    -    theme_enable($this->themes);
    +    $this->themes = array_keys(\Drupal::service('theme_handler')->listInfo());
    +    \Drupal::service('theme_handler')->enable($this->themes);
    

    We could avoid getting the service twice by doing $theme_handler = \Drupal::service('theme_handler') once and then using the local variable.

  13. +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
    @@ -188,13 +188,13 @@ function testFunctionOverride() {
    -    // Check if drupal_theme_access() retrieves enabled themes properly from list_themes().
    ...
    +    // Check if drupal_theme_access() retrieves enabled themes properly from listInfo().
    

    This does not wrap properly. Also, instead of just saying listInfo(), we should probably be specific and say ThemeHandlerInterface::listInfo().

  14. +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
    @@ -188,13 +188,13 @@ function testFunctionOverride() {
    -    // Check if list_themes() returns disabled themes.
    +    // Check if \Drupal::service('theme_handler')->listInfo() returns disabled themes.
    

    Again, this doesn't wrap at 80 characters and should say ThemeHandlerInterface::listInfo() instead of \Drupal::....

  15. +++ b/core/modules/system/system.admin.inc
    @@ -192,13 +192,13 @@ function system_theme_default() {
    -    $themes = list_themes();
    +    $themes = \Drupal::service('theme_handler')->listInfo();
    ...
    -       theme_enable(array($theme));
    +       \Drupal::service('theme_handler')->enable(array($theme));
    

    We could store $theme_handler in a local variable here to avoid calling \Drupal::service() twice.

  16. +++ b/core/modules/system/system.admin.inc
    @@ -206,9 +206,9 @@ function system_theme_default() {
    -      // theme_enable(). However, modules must know the current default theme in
    +      // \Drupal::service('theme_handler')->enable(). However, modules must know the current default theme in
    ...
    -      // implementations, and doing the variable_set() before the theme_enable()
    +      // implementations, and doing the variable_set() before the \Drupal::service('theme_handler')->enable()
    

    Again, this should say ThemeHandlerInterface::enable() and wrap at 80 characters.

  17. +++ b/core/modules/system/system.install
    @@ -546,7 +546,7 @@ function system_requirements($phase) {
    -  // Enable and set the default theme. Can't use theme_enable() this early in
    +  // Enable and set the default theme. Can't use \Drupal::service('theme_handler')->enable() this early in
    

    This should say ThemeHandlerInterface::enable() and wrap at 80 characters.

  18. +++ b/core/modules/system/theme.api.php
    @@ -224,7 +224,7 @@ function hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables
    - * @see theme_enable()
    + * @see \Drupal::service('theme_handler')->enable()
    

    Same as above, but here we need the full namespace: \Drupal\Core\Extension\ThemeHandlerInterface::enable()

  19. +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
    @@ -1765,7 +1765,7 @@ public function buildOptionsForm(&$form, &$form_state) {
    -          $themes = list_themes();
    +          $themes = \Drupal::service('theme_handler')->listInfo();
    
    @@ -1826,7 +1826,7 @@ public function buildOptionsForm(&$form, &$form_state) {
    -        foreach (list_themes() as $key => $theme) {
    +        foreach (\Drupal::service('theme_handler')->listInfo() as $key => $theme) {
    

    This should *not* be injected as there's currently a lot of uninjected stuff in DisplayPluginBase and that should be a separate issue. In theory we could store $theme_handler in a local variable here, but that will make it slightly harder when actually injecting stuff. So, I don't really care, but I would leave it as is.

  20. +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php
    @@ -29,7 +29,7 @@ public function buildForm(array $form, array &$form_state) {
    -    foreach (list_themes() as $name => $theme) {
    +    foreach (\Drupal::service('theme_handler')->listInfo() as $name => $theme) {
    

    Here I personally find injection less important, but for extra credit you could use ContainerInjectionInterface as explained above.

  21. +++ b/core/profiles/standard/standard.install
    @@ -18,8 +18,8 @@ function standard_install() {
    -  theme_enable(array($default_theme));
    -  theme_disable(array('stark'));
    +  \Drupal::service('theme_handler')->enable(array($default_theme));
    +  \Drupal::service('theme_handler')->disable(array('stark'));
    
    @@ -79,7 +79,7 @@ function standard_install() {
    -  theme_enable(array('seven'));
    +  \Drupal::service('theme_handler')->enable(array('seven'));
    

    Here we can store the theme handler in a local variable to save some cycles.

    In theory we should really make enable() and disable() chainable but that's a different issue.

tstoeckler’s picture

Also Re #2: Let's open a follow-up issue to create a listEnabledInfo() (or similar) method on the theme handler that would encapsulate that code.

The last submitted patch, 3: deprecated-2151469-3.patch, failed testing.

Richard Damon’s picture

I will look at the comments and update the patch. This was my project at today's code sprint in Boston. I will need a bit of study/instruction on the "injection" comments.

Richard Damon’s picture

One question, would it be better to split the patch into a patch per core module being updated, so perhaps some can be updated quicker, or should I keep it all as one big patch for the full issue?

Richard Damon’s picture

Status: Needs work » Needs review
FileSize
51.27 KB

Here is a patch with much of the fixes done. I haven't actually implemented full dependency injection into the classes, but have added the class member to hold the handler, and am initilizing it in the constructor. This sets things up for making the changes to implement the injection.

There is also one test that failed last time, apparently due to the change breaking an ad-hoc mocking of list_themes, which will need to be changed into a real mock.

I am tempted to break this into two patches, one for what is basically completed now, and that which still needs work, so that the issue has a big bite taken out of it for now.

Status: Needs review » Needs work

The last submitted patch, 10: deprecated-2151469-10.patch, failed testing.

lokapujya’s picture

The last patch passed Simple test for me locally, but now this needs a re-roll.

Richard Damon’s picture

I'll look into re-rolling the patch this week.

pflame’s picture

Assigned: Richard Damon » pflame

I will try to reroll the patch since it's been there for few weeks. I am working on this through core mentoring hours.

pflame’s picture

Status: Needs work » Needs review
FileSize
52.31 KB

I reroll the patch and uploaded the latest patch.

Status: Needs review » Needs work

The last submitted patch, 15: deprecated-2151469-15.patch, failed testing.

pflame’s picture

Status: Needs work » Needs review
FileSize
49.08 KB

I reroll the patch again, the patch in #15 has some test functions which are removed from the latest code. Please review the latest patch attached to this comment.

Status: Needs review » Needs work

The last submitted patch, 17: deprecated-2151469-17.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review

17: deprecated-2151469-17.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 17: deprecated-2151469-17.patch, failed testing.

pflame’s picture

Status: Needs work » Needs review

17: deprecated-2151469-17.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 17: deprecated-2151469-17.patch, failed testing.

sun’s picture

Issue tags: -Novice +@deprecated
lokapujya’s picture

Assigned: pflame » lokapujya
Status: Needs work » Needs review
FileSize
43.81 KB

WIP.

Status: Needs review » Needs work

The last submitted patch, 24: 2151469-24.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
43.17 KB
654 bytes

Am hoping for at least a test run.

Status: Needs review » Needs work

The last submitted patch, 26: 2151469-26.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
42.47 KB

another quick try.

Status: Needs review » Needs work

The last submitted patch, 28: 2151469-28.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
9.99 KB

I don't know why the test run failed. None of the actual tests failed. We just had a random error. I'm trying just the changes on the block module.

Status: Needs review » Needs work

The last submitted patch, 30: 2151469-block.patch, failed testing.

lokapujya’s picture

Does anyone knows why all tests pass, but I still get this error in Simpletest: PHP Fatal error: Call to a member function get() on a non-object in /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal.php on line 138.

Next, Ill try a patch for a different module, not block.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
8.38 KB

This includes the changes for only some of the modules, just to see if it passes simpletest.

Status: Needs review » Needs work

The last submitted patch, 33: 2151469-some-modules.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
588 bytes

just the color module changes?

lokapujya’s picture

Redo of #33. That patch had unintended changes in it. If this passes, the problem is most likely in the block module code changes.

ianthomas_uk’s picture

This doesn't currently have a patch to review.

I think the basics of this could be handled by #2208607: Write script to automate replacement of deprecated functions where possible, and then a followup patch here for documentation and dependency injection.

lokapujya’s picture

Assigned: lokapujya » Unassigned
FileSize
8.41 KB

Summary of the last few patches: I couldn't figure out which change is causing the test to break. A patch with the changes that contains just the block modules changes failed Simpletest. Another patch with the changes for 6 other modules passed.

So, I still don't know why the changes in block module are not passing. Here is another test to see if it has anything to do with the protected themehandler variable.

lokapujya’s picture

Status: Needs work » Needs review
lokapujya’s picture

FileSize
41 KB

protected themehandler was misued. Removal of that code passeed in #38.

Here the complete reroll: patch from #28 + removal of the protected $themehandler local variable (as passed in patch from #38).

Status: Needs review » Needs work

The last submitted patch, 40: 2151469-40.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
38.6 KB

So this is a patch with all of the $themehandler local variables removed.

ianthomas_uk’s picture

We've got a better patch, so removing the link to the automated script issue.

lokapujya’s picture

Recommend implementing dependency injection in a followup: #2221801: Use Dependency Injection for theme handler. as suggested by tstoeckler in #5.

lokapujya’s picture

Maybe someone that understand the task from comment #6 can create an issue for that too.

sun’s picture

Adding two related issues that are significantly changing the affected code.

Some of the suggested conversions in this issue/patch are probably trivial, but it would probably be a good idea to carefully review all of them to see whether it makes sense to convert them here.

sun’s picture

42: 2151469-42.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 42: 2151469-42.patch, failed testing.

alansaviolobo’s picture

Status: Needs work » Needs review
FileSize
27.53 KB
46.73 KB

Status: Needs review » Needs work

The last submitted patch, 49: clean_up_usage_of-2151469-49.patch, failed testing.

alansaviolobo’s picture

Status: Needs work » Needs review
FileSize
11.33 KB
rpayanm’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block/src/BlockForm.php
    @@ -90,7 +90,7 @@ public function form(array $form, FormStateInterface $form_state) {
           $theme_options = array();
    -      foreach (list_themes() as $theme_name => $theme_info) {
    +      foreach (\Drupal::service('theme_handler')->listInfo() as $theme_name => $theme_info) {
             if (!empty($theme_info->status)) {
    

    Inject service on the class instead.

  2. +++ b/core/modules/block_content/src/Controller/BlockContentController.php
    @@ -90,7 +90,7 @@ public function addForm(BlockContentTypeInterface $block_content_type, Request $
    -    if (($theme = $request->query->get('theme')) && in_array($theme, array_keys(list_themes()))) {
    +    if (($theme = $request->query->get('theme')) && in_array($theme, array_keys(\Drupal::service('theme_handler')->listInfo()))) {
    

    Inject service...

  3. +++ b/core/modules/system/src/Form/ThemeSettingsForm.php
    @@ -69,7 +69,7 @@ public function getFormId() {
    +    $themes = \Drupal::service('theme_handler')->listInfo();
    

    Inject service...

  4. +++ b/core/modules/system/src/Form/ThemeSettingsForm.php
    @@ -80,7 +80,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme =
    -      $themes = list_themes();
    +      $themes = \Drupal::service('theme_handler')->listInfo();
           $features = $themes[$theme]->info['features'];
    

    Inject service...

  5. +++ b/core/modules/views_ui/src/Form/BasicSettingsForm.php
    @@ -30,7 +30,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +    foreach (\Drupal::service('theme_handler')->listInfo() as $name => $theme) {
    

    Inject service...

  6. +++ b/core/modules/system/src/Tests/Theme/ThemeTest.php
    @@ -195,17 +195,22 @@ function testFunctionOverride() {
    +    // Check if ThemeHandlerIntface::listInfo() returns disabled themes.
    

    Typo

JeroenT’s picture

Status: Needs work » Needs review
FileSize
10.95 KB

Created straight reroll.

JeroenT’s picture

FileSize
17.34 KB
9.73 KB

Addressed all changes as suggested by rpayanm. Patch attached!

JeroenT’s picture

Note to self: Review patches before submitting them...

Status: Needs review » Needs work

The last submitted patch, 56: clean_up_usage_of-2151469-56.patch, failed testing.

The last submitted patch, 55: clean_up_usage_of-2151469-55.patch, failed testing.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
18.99 KB
7.22 KB

Updated BlockFormTest + replaced ThemeHandler with ThemeHandlerInterface in __construct.

andypost’s picture

Status: Needs review » Needs work

Patch looks great but incomplete, there's few references in comments

$ git grep list_themes
core/includes/module.inc:23: * @see list_themes()
core/includes/theme.inc:147:function list_themes($refresh = FALSE) {
core/includes/theme.maintenance.inc:86:  // list_themes() triggers a \Drupal\Core\Extension\ModuleHandler::alter() in
core/includes/theme.maintenance.inc:89:  // list_themes() builds its cache.
core/lib/Drupal/Core/Theme/Registry.php:414:   * @see list_themes()
core/modules/system/src/Tests/Theme/ThemeTest.php:214:    // list_themes().
JeroenT’s picture

Status: Needs work » Needs review
FileSize
21.48 KB
3.34 KB

Removed the remaining list_themes() references + also found and removed a reference to _system_rebuild_theme_data().

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/includes/theme.inc
@@ -351,8 +351,10 @@ function theme_get_setting($setting_name, $theme = NULL) {
+    if ($theme && isset($themes[$theme])) {

When would !$theme occur, this looks like a logic change, not just a cleanup.

Otherwise looks good.

ianthomas_uk’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
21.37 KB

Good spot. That must have been a reroll mistake - the line was changed the other way round a few weeks ago. They are effectively identical anyway.

This patch is #61 without that line changed.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 64: clean_up_usage_of-2151469-64.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
21.37 KB

rerolled...

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

good reroll, back to rtbc

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 66: 2151469-66.patch, failed testing.

Status: Needs work » Needs review

rpayanm queued 66: 2151469-66.patch for re-testing.

JeroenT’s picture

Status: Needs review » Reviewed & tested by the community

Tests pass again, so RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Theme/Registry.php
@@ -180,7 +180,7 @@ protected function init($theme_name = NULL) {
-      $themes = $this->listThemes();
+      $themes = \Drupal::service('theme_handler')->listInfo();

+++ b/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php
@@ -39,7 +39,7 @@ public function access($theme) {
-    $themes = list_themes();
+    $themes = \Drupal::service('theme_handler')->listInfo();

can't we inject the service here?

rpayanm’s picture

Status: Needs work » Needs review
FileSize
1.99 KB
22.8 KB

Status: Needs review » Needs work

The last submitted patch, 72: 2151469-72.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
534 bytes
23.32 KB

oppss sorry :)

Status: Needs review » Needs work

The last submitted patch, 74: 2151469-74.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
821 bytes
23.32 KB

ummmm.

Status: Needs review » Needs work

The last submitted patch, 76: 2151469-76.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
1012 bytes
24.31 KB

Test...

Status: Needs review » Needs work

The last submitted patch, 78: 2151469-78.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
920 bytes
24.7 KB

fighting against the Tests...

rpayanm’s picture

FileSize
2.7 KB

Yeah :D
Interdiff #71 - #80

star-szr’s picture

Status: Needs review » Needs work

@rpayanm, nice work. Thank you! What about the one in ThemeAccessCheck? Here are a couple minor coding standards/docs things that can be fixed up:

  1. +++ b/core/lib/Drupal/Core/Theme/Registry.php
    @@ -149,13 +157,16 @@ class Registry implements DestructableInterface {
    +   * @param $theme_handler
    +   *   The theme handler.
    

    I think this @param should have the data type.

  2. +++ b/core/modules/block_content/src/Controller/BlockContentController.php
    @@ -48,10 +57,13 @@ public static function create(ContainerInterface $container) {
        * @param \Drupal\Core\Entity\EntityStorageInterface $block_content_type_storage
        *   The custom block type storage.
    +   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
    +   * The theme handler.
    

    The description for this param needs to be indented by 2 spaces.

rpayanm’s picture

FileSize
1.79 KB
24.84 KB

Next, ThemeAccessCheck...

rpayanm’s picture

Status: Needs work » Needs review
rpayanm’s picture

FileSize
1.91 KB
25.96 KB

Trying with ThemeAccessCheck...

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

#85 is #66 plus the injection that alexpott asked for, so RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Theme/ThemeAccessCheck.php
@@ -16,6 +17,22 @@
   /**
+   * The theme handler.
+   *
+   * @var \Drupal\Core\Extension\ThemeHandlerInterface
+   */
+  protected $themeHandler;
+
+  /**
+   * Constructs a \Drupal\Core\Theme\Registry object.
+   *
+   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
+   *   The theme handler.
+   */
+  public function __construct(ThemeHandlerInterface $theme_handler) {
+    $this->themeHandler = $theme_handler;
+  }

@@ -39,7 +56,7 @@ public function access($theme) {
   public function checkAccess($theme) {
-    $themes = list_themes();
+    $themes = \Drupal::service('theme_handler')->listInfo();
     return !empty($themes[$theme]->status);

Now we've injected it we need to actually use it :) $this->themeHandler instead of \Drupal::service(...

JeroenT’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
25.95 KB
510 bytes

Addressed feedback of alexpott in 87.

JeroenT’s picture

Status: Reviewed & tested by the community » Needs review

Go testbot!

JeroenT’s picture

Status: Reviewed & tested by the community » Needs review

Go testbot!

JeroenT’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Title: Clean-up usage of deprecated list_themes(), drupal_find_base_themes(), theme_enable(), theme_disable(), _system_rebuild_theme_data() in favor of theme_handler service » Clean-up usage of deprecated list_themes() and _system_rebuild_theme_data() in favor of theme_handler service
Status: Reviewed & tested by the community » Fixed

This issue is a prioritized change (removing deprecated function use) as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed 88a6bbc and pushed to 8.0.x. Thanks!

  • alexpott committed e298180 on 8.0.x
    Issue #2151469 by rpayanm, lokapujya, JeroenT, alansaviolobo, Richard...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

a_thakur’s picture

drupal_theme_access() is still is used.

bash-3.2$ grep drupal_theme_access -nr *
core/includes/theme.inc:88:function drupal_theme_access($theme) {
core/modules/system/src/Tests/Theme/ThemeTest.php:211:    // Check if drupal_theme_access() retrieves enabled themes properly from
core/modules/system/src/Tests/Theme/ThemeTest.php:213:    $this->assertTrue(drupal_theme_access('test_theme'), 'Installed theme detected');
core/modules/system/src/Tests/Theme/ThemeTest.php:215:    $this->assertTrue(drupal_theme_access('test_theme'), 'Enabled theme detected');
core/modules/system/system.module:321:  return \Drupal::currentUser()->hasPermission('administer themes') && drupal_theme_access($theme);
bash-3.2$ 

Created https://www.drupal.org/node/2151469 to get rid of this.

star-szr’s picture