Simplify TimeZoneFormHelper

Created on 22 February 2023, over 1 year ago
Updated 19 April 2023, about 1 year ago

Problem/Motivation

Instead of the $group parameter, we can have two methods, one that returns grouped and one doesn't.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

The $grouped parameter is removed, and a new method is added - however this class was only added to 10.1.x last week, so amending the CR from the previous issue should be sufficient, no need for a bc layer for something that's never been in a tagged release.

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated 8 minutes ago

Created by

πŸ‡¬πŸ‡§United Kingdom catch

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

Comments & Activities

Not all content is available!

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

  • Issue created by @catch
  • Status changed to Needs review over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch
  • πŸ‡¬πŸ‡§United Kingdom catch

    Couple more thoughts:

    1. in the grouped case, would it be worth trying to use array_multisort() on the resulting array and skipping the initial asort(), didn't try this yet, might not be easier to read.

    2. Should we split the method into getOptionsList() and getGroupedOptionsList() or something? But then we'd probably want a protected method for the shared logic, which means three methods instead of one, maybe that's fine though.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia
    1. I played around with array_multisort() but it's a mystery how it works
    2. Agree! I think this is a much better API. Added a patch that does this.
  • πŸ‡¬πŸ‡§United Kingdom catch

    Looking at #4, we now don't have a single call to ::getOptionsList(), so do we even need both versions? But grepping contrib it looks like it's used a lot with the default arguments, so maybe better to provide the 1-1 for now.

    I think if we get this in before 10.1.x is released, we won't need a deprecation either way, can just update the CR from the other issue.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    so maybe better to provide the 1-1 for now.

    By this I assume you mean having both methods as in the last patch?

    I think if we get this in before 10.1.x is released, we won't need a deprecation either way, can just update the CR from the other issue.

    Yep agreed.

    So just need more reviews now?

  • πŸ‡¬πŸ‡§United Kingdom catch

    By this I assume you mean having both methods as in the last patch?

    I'm on the fence, but I think that means we could try to get this in and then open yet another follow-up to look at deprecating one if we want to.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK
    +++ b/core/modules/system/system.module
    @@ -1113,7 +1113,7 @@ function system_mail($key, &$message, $params) {
       @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. This function is no longer used in Drupal core. Use \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList() or \DateTimeZone::listIdentifiers() instead. See https://www.drupal.org/node/3023528', E_USER_DEPRECATED);
    

    We should update this deprecation notice to add a reference to getGroupedOptionsList().

    Not sure it is worth deprecating getOptionsList() given that getGroupedOptionsList() needs to call it and contrib appears to use it.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Fixes deprecation message.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Will a change record be needed for getGroupedOptionsList()?

    Shouldn't grouped be deprecated also?

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @smustgrave as this was only added recently in 10.1.x which is not yet released, it makes sense to add this extra method to the existing change record at https://www.drupal.org/node/3023528 β†’

    Not sure what you mean by deprecating grouped, it is used in many places in core. The ungrouped version is not, but it is a nice separation of concerns.

    The deprecation message is updated and there is nothing else to do here, so this is RTBC.

  • Status changed to RTBC over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Tagging for change record update.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I think @smustgrave is maybe referring to the @grouped parameter, but since the method was only added to 10.1 a week or so ago, we don't need to deprecate as long as this gets committed before 10.1.x beta1 since the change will only be from 10.0.x and earlier which doesn't have the method.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    That’s correct sorry for not specifying I meant parameter

  • πŸ‡¬πŸ‡§United Kingdom catch

    Updated the issue summary a bit.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Still small but slightly less small than when I opened the issue.

  • Status changed to Needs work over 1 year ago
  • Status changed to RTBC over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Random test fail

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Another random failure.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Surprise! Random failure.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    This looks like a really nice idea.

    +++ b/core/lib/Drupal/Core/Datetime/TimeZoneFormHelper.php
    @@ -34,29 +32,44 @@ public static function getOptionsList(bool $blank = FALSE, bool $grouped = FALSE
    +  public static function getGroupedOptionsList(bool $blank = FALSE): array {
    

    I think we can name this method a bit better. How about getOptionsListByRegion() or getOptionsListGroupedByRegion(). This would lead to more informative code. Discussed with @catch. We have a preference for the first option because it is more concise but maybe you'd expect that method to have a region argument. Maybe people have a better suggestion.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Ha ha. I think the current getGroupedOptionsList() is easier to understand, but not a hill worth dying on.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Here's a patch that renames to getOptionsListByRegion().

  • Status changed to RTBC over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    #30 looks good. I don't think there's that much in it, but I do prefer it slightly over the other options.

  • Status changed to Fixed about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed c312cc1 and pushed to 10.1.x. Thanks!

    • alexpott β†’ committed c312cc11 on 10.1.x
      Issue #3343755 by kim.pepper, catch, smustgrave, longwave: Simplify...
  • πŸ‡¨πŸ‡¦Canada liquidcms

    Sorry if not the right place for this question but I am trying to modify the TZ list in D9.4. From the looks of things this is only possible by hacking core (like an alter function in the system_time_zones() function?). Is the work here going to make this any easier to accomplish in D10?

  • πŸ‡¨πŸ‡¦Canada liquidcms

    Hmm, thought i would be smart and hack the system.module to add an alter to allow modifying the $zones. All i do in my alter is remove all the non-America optgroups. It works perfectly but form submit complains it is not a valid option. This isn't standard Drupal form processing is it. I should be able to remove items from a select list without issue.

  • Status changed to Needs work about 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    This is tagged for change record updates which still need to be done.

    This issue should be added to the list of issues in the existing CR β†’ . And I see that the deprecation messages lists two alternate methods to use but only one is mentioned in the CR. The CR should have both and explain when to use one or the other. And examples are always useful.

    Setting back to NW for the change record work.

  • Status changed to Needs review about 1 year ago
  • πŸ‡©πŸ‡ͺGermany FeyP

    Updated the CR.

  • Status changed to Fixed about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    I also went to update the CR but cross-posed with FeyP - changes look better than mine so marking fixed.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    @FeyP, Thanks! That is much more informative and easy to read.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    I forgot to remove the tag.

  • πŸ‡©πŸ‡ͺGermany FeyP

    Since I didn't have luck asking in Slack...

    Shouldn't the CR be published? The documentation on writing CRs β†’ says

    (change records are published when the change is committed)

    so I would have expected this to happen on commit or in this case after the review. However maybe I'm missing something and we usually wait until release?

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    @FeyP, yes it usually happens on commit but sometimes a committer forgets or gets called away. You are welcome to publish a Draft CR if the issue is fixed and there are not outstanding items. As always, add a comment to the issue when doing so. Which I will do now. :-)

    I have published the CR.

  • πŸ‡©πŸ‡ͺGermany FeyP

    @quietone Thanks! I thought that it was just an oversight, but wasn't entirely sure. Will do in the future, if needed :)

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

Production build 0.69.0 2024