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

Comments

catch created an issue. See original summary.

catch’s picture

Status: Active » Needs review
StatusFileSize
new1.69 KB
catch’s picture

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.

kim.pepper’s picture

StatusFileSize
new10.85 KB
new9.81 KB
  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.
catch’s picture

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.

kim.pepper’s picture

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?

catch’s picture

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.

longwave’s picture

Status: Needs review » Needs work
+++ 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, it is a nice separation of concerns as it is.

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new12.49 KB
new2.42 KB

Fixes deprecation message.

Status: Needs review » Needs work

The last submitted patch, 9: 3343755-9.patch, failed testing. View results

kim.pepper’s picture

Status: Needs work » Needs review
smustgrave’s picture

Will a change record be needed for getGroupedOptionsList()?

Shouldn't grouped be deprecated also?

longwave’s picture

Status: Needs review » Reviewed & tested by the community

@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.

longwave’s picture

Tagging for change record update.

catch’s picture

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.

smustgrave’s picture

That’s correct sorry for not specifying I meant parameter

catch’s picture

Issue summary: View changes

Updated the issue summary a bit.

catch’s picture

Title: Small simplification to TimeZoneFormHelper » Simplify TimeZoneFormHelper

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

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new84 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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.

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new12.48 KB

Re-roll of #9

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 3343755-20.patch, failed testing. View results

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Random test fail

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 3343755-20.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Another random failure.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 3343755-20.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Surprise! Random failure.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

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.

kim.pepper’s picture

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

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new12.5 KB
new9.62 KB

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

catch’s picture

Status: Needs review » Reviewed & tested by the community

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

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

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...
liquidcms’s picture

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?

liquidcms’s picture

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.

quietone’s picture

Status: Fixed » Needs work

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.

feyp’s picture

Status: Needs work » Needs review

Updated the CR.

catch’s picture

Status: Needs review » Fixed

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

quietone’s picture

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

quietone’s picture

I forgot to remove the tag.

feyp’s picture

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?

quietone’s picture

@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.

feyp’s picture

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

Status: Fixed » Closed (fixed)

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