This is a Meta issue.

You could call it a plan, like on the Etiquette page

So, no patches here please! Instead

  • Place patches in their respective child issue (see sidebar for child issues)
  • If there is no child issue yet, create one and mark this post as its parent. And then place patches there.
  • Test and review patches in the child issues.

Thank you!

Original post:
Use of theme functions is discouraged in D8 and removed in D9 in favor of using Twig templates.
All theme function in includes/fivestar.theme.inc should be replaced by templates in templates/ and hook_theme() should be modified to use these templates.

Issue fork fivestar-3133125

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

TR created an issue. See original summary.

tr’s picture

tr’s picture

Status: Active » Needs review
StatusFileSize
new4.86 KB

Here's a start. This patch removes two Field Formatter theme functions and replaces them with preprocess hooks and twig templates.

The removed functions are:
theme_fivestar_formatter_rating()
theme_fivestar_formatter_percentage()

They are replaced with:
template_preprocess_fivestar_formatter_rating()
template_preprocess_fivestar_formatter_percentage()

With templates:
templates/fivestar-formatter-rating.html.twig
templates/fivestar-formatter-percentage.html.twig

This could probably be simplified a lot further by moving the preprocess logic into the Field Formatters, but for now this closely sticks with what we are currently doing so it reduces the potential to be disruptive. Likewise, I hope this will serve as an example of how to convert the other theme functions to templates.

  • TR committed da04f69 on 8.x-1.x
    Issue #3133125 by TR: Replace theme functions with Twig templates -...
init90’s picture

Thank @TR for the nice examples. Here migration of static output function.

init90’s picture

StatusFileSize
new6.1 KB
new629 bytes

Here relevant issues with which I encountered when worked on it: #3142319: Move static theme output into twig templete and #3142322: Attach necessary library for static rating output

Added link to related issue into the patch.

init90’s picture

Title: Replace theme functions with Twig templates » [Meta] Replace theme functions with Twig templates
Related issues: +#3142319: Move static theme output into twig templete

Added related function.

v.hilkov’s picture

StatusFileSize
new9.4 KB

My humble attempt to replace theme functions. Updated fivestar_static_element, fivestar_summary and fivestar_preview_widget functions. I couldn't find where functions fivestar, fivestar_select, fivestar_preview, fivestar_preview_wrapper and fivestar_formatter_default are used. Are they needed at all? Looks like everything is working right now even without them. Maybe someone can point me in the right direction, so when I have free time I can try to update them as well if needed.

o'briat’s picture

Ok fivestar_static theme function is still on '8.x-1.0-alpha2' but not on dev.

tr’s picture

Hi @V.Hilkov

Thanks for your help. Can you make a new issue for each theme function you are replacing, like @init90 did with #3142319: Move static theme output into twig templete? One issue for each theme function. Then add those issues here as Related issues. That will make it easier to review and discuss your changes, and will allow me to give you credit for the commit.

Also, don't comment out code in your patch - just delete the lines that you no longer need.

o'briat’s picture

It's ok , I missed the fact that the other theme fixes are already on the dev branch and not on the last alpha.
So far dev + patch seems ok.

v.hilkov’s picture

Hi @TR

I did as requested and made different issue for every theme function, which I was able to replace. Also my previous question still stands: I couldn't find where functions fivestar, fivestar_select, fivestar_preview, fivestar_preview_wrapper and fivestar_formatter_default are used. Are they needed at all? Looks like everything is working right now even without them. Maybe someone can point me in the right direction, so when I have free time I can try to update them as well if needed.

tr’s picture

Are they needed at all?

I don't know. They have to be looked at one-by-one to see. Some may be used by other theme functions. Some may be for features that have not yet been ported to D8. Some may be for features that are no longer needed in D8. You will have to look at the D7 code to see how they were used, then see how that code got ported to D8 to figure out why the code is still there. We may be able to delete a lot of that, but not before we make sure that everything got properly moved from D7. A lot of things were not ported, or were incompletely ported.

Yuriy Mykhalyna made their first commit to this issue’s fork.

tr’s picture

@Yuriy Mykhalyna
This is a meta issue - patches aren't being evaluated here. Instead, see the related issues in the right sidebar for the issues where the patches are being reviewed. There is one related issue for each theme function.

rohan_katkar’s picture

I have tried below patch links through composer but its not working for me..

Patch link: https://www.drupal.org/files/issues/2020-11-21/replace-theme-functions-3...

  • The PHP version i am using - 7.4
  • Drupal version - 9.2

I am getting below error:
The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-11-21/replace-theme-functions-3...

When I ran "composer update" the inside fivestar module, folder called "b" is there, which includes below twigs:

  • fivestar-preview-widget.html.twig
  • fivestar-static-element.html.twig
  • fivestar-summary.html.twig
tr’s picture

@rohan_katkar Please read what I said in #16.

The patch in #8 will not be considered or supported. The patches that are being considered are in the child issues. Please use those patches and comment in those issues.

j.lucky’s picture

StatusFileSize
new7.8 KB

Just Update the Patch and remove the commented line.

rivimey’s picture

Meta issues don't have patches so I've hidden them.

pbbhoge’s picture

Re-rolled the patch

rivimey’s picture

pbbhoge’s picture

rivimey’s picture

@pbbhoge, Did you not see @TR 's post in #16?

This is a meta issue - patches aren't being evaluated here. Instead, see the related issues in the right sidebar for the issues where the patches are being reviewed. There is one related issue for each theme function.

Please do not upload patches or comment on those already uploaded.

kiseleva.t’s picture

Exported the changes from MR to a static patch file to be able to use it on the project without the risk that it will be changed or removed.

tr’s picture

No. Everyone please stop posting patches here. This is not helping. If you want to help, participate in the child issues.

tr’s picture

o'briat’s picture

I'm currently reviewing child issue #3186841, but I am missing something or there should be 4 more child ones: theme_fivestar, theme_fivestar_select, theme_fivestar_preview & theme_fivestar_formatter_default ?

rivimey’s picture

Some theme conversions are already done and some were subsumed:

  • theme_fivestar -- I think this is used/needed and the earlier patches in this thread include the needed code;
  • theme_fivestar_preview is in #3186841, as you know,
  • theme_fivestar_formatter_default -- I think there was some discussion about it, but I can't find it now.
  • theme_fivestar_select -- I think this is used/needed and the earlier patches in this thread include the needed code;

So I think maybe yes, we are missing one or more child issues.

o'briat’s picture

fivestar_preview has not been removed in #3186841, this issue only deals with fivestar_preview_widget & fivestar_preview_wrapper.

So I will create 4 child issues and try dispatch this issue patches into them.

Ok ?

rivimey’s picture

@O'briat if you are sure the theme functions are not covered in another issue, and are also still required by the module, please do add new issues for them.

Once done, please add the new issues referenced as child issues (that is, in the new issue, reference this one as parent.)

Thanks for your efforts.

johan den hollander’s picture

Hi,

I looked at the child issues and could not find a solution for: theme_fivestar_select.
I'm using the dev version with the #22 patch from https://www.drupal.org/project/fivestar/issues/3186841.

johan den hollander’s picture

In fact I still have deprecation messages for all of the following:

  • theme_fivestar()
  • theme_fivestar_select()
  • theme_fivestar_preview()
  • theme_fivestar_formatter_default()
init90’s picture

ravimane23’s picture

Added patch after removed all the remaining theme function.

I applied a patch manually reason the patch #25 unable to apply automatically.

In addition to patch, I also faced an issue that I am using layout_builder & star format for rating but if the rating is empty then no field is getting displayed on node view page eventhough field is present in layout. I took a reference of "Fivestar widget not displayed when using Layout Builder" I have added the code and it resolves my issue.

Status: Needs review » Needs work

The last submitted patch, 35: remove_remaining_theme_functions_3133125-35.patch, failed testing. View results

tr’s picture

Status: Needs work » Active

@ravimane23: You need to read everything on this page.

tr’s picture

init90’s picture

init90’s picture

init90’s picture

nicolas bouteille’s picture

+1 for deprecation message for theme_fivestar_preview after module install via UI or cache clear.

User deprecated function: Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of theme_fivestar_preview()

init90’s picture

saurabh-2k17’s picture

@Nicolas Bouteille any solutions for the issue you faced? I am seeing the same thing on my site after cache-clear.

firfin’s picture

Issue summary: View changes