Follow-up to #2429443: Date format form is unusable

Problem/Motivation

Problem 1: dateFormat() method in \Drupal\Core\Datetime\DateFormatter class does below:
1. Set the requested language as override language.
2. Load the date_format config entity.
3. Save them in $this->dateFormats property for further request.
4. Set the language back to original language.

So the success case (e.g. format 'medium') would have below data in $this->dateFormats property:

Array
(
    [medium] => Array
        (
            [en] => Drupal\Core\Datetime\Entity\DateFormat Object
                (
                    [id] => medium
                    ...
                    ...  

                )

        )

)

However, this is not going to help for 'custom' format - a predefined format for user-defined formats.

Problem 2: The argument $format of formatDate() is very confusing as it is $type in format() method.

Proposed resolution

for
Problem 1: Don't bother doing any of those steps for 'custom'.
Problem 2: Update variable name to use what we have in format()

Remaining tasks

1. Patch
2. Test

User interface changes

N/A

API changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because too unneeded processing happens for custom date formats.
Issue priority Normal.
Unfrozen changes None
Prioritized changes Yes, because follow-up on a recent major.
Disruption None
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vijaycs85’s picture

rteijeiro’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
    // If we have a non-custom date format use the provided date format pattern.
    if ($date_format = $this->dateFormat($type, $langcode)) {

Let's add to this condition instead.

alexpott’s picture

    // If we have a non-custom date format use the provided date format pattern.
    if ($date_format = $this->dateFormat($type, $langcode)) {

Let's add to this condition instead.

alexpott’s picture

Issue tags: -Needs tests

Not sure that a test is worth it.

vijaycs85’s picture

Status: Needs work » Needs review
FileSize
747 bytes

Here we go.

Status: Needs review » Needs work

The last submitted patch, 6: 2457345-exclude-custom-format-load-6.patch, failed testing.

Status: Needs work » Needs review
Anonymous’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Re #5: not sure how this could be automatically tested. Feedback from #4 was addressed. Back to RTBC.

Added beta eval to summary.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 744514b and pushed to 8.0.x. Thanks!

  • alexpott committed 744514b on 8.0.x
    Issue #2457345 by vijaycs85: Remove unnecessary format lookup in \Drupal...
vijaycs85’s picture

Thank you!

tstoeckler’s picture

Status: Fixed » Needs work

It might be that I'm once again missing something but I don't think this is correct. The check is for $format !== 'custom' but in fact it should be $type !== 'custom' because $format will be the actual PHP date format, e.g. Y-m-d.

  • alexpott committed 112e955 on 8.0.x
    Revert "Issue #2457345 by vijaycs85: Remove unnecessary format lookup in...
alexpott’s picture

@tstoeckler++ nice catch. Reverted this.

vijaycs85’s picture

Status: Needs work » Needs review
FileSize
2.49 KB

/me feels very bad to make a mistake in a one line fix.

Really sorry about that... It was a blind copy-paste when regenerated the patch at #6.

However, I believe this is just showed how important to name a variable correctly. The type ('medium', 'custom') is getting passed as $type to \Drupal\Core\Datetime\DateFormatter::format and same value is used as $format in \Drupal\Core\Datetime\DateFormatter::dateFormat. Why dateFormat need to accept a '$format' as an argument?

vijaycs85’s picture

Title: Remove unnecessary format lookup in \Drupal\Core\Datetime\DateFormatter::dateFormat for 'custom' format » Remove unnecessary formatDate call for 'custom' format & document cleanup.
Issue summary: View changes
vijaycs85’s picture

Title: Remove unnecessary formatDate call for 'custom' format & document cleanup. » Remove unnecessary formatDate call for 'custom' format & code cleanup.

Status: Needs review » Needs work

The last submitted patch, 16: 2457345-exclude-custom-format-load-16.patch, failed testing.

  • alexpott committed 112e955 on 8.1.x
    Revert "Issue #2457345 by vijaycs85: Remove unnecessary format lookup in...
  • alexpott committed 744514b on 8.1.x
    Issue #2457345 by vijaycs85: Remove unnecessary format lookup in \Drupal...

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • alexpott committed 112e955 on 8.3.x
    Revert "Issue #2457345 by vijaycs85: Remove unnecessary format lookup in...
  • alexpott committed 744514b on 8.3.x
    Issue #2457345 by vijaycs85: Remove unnecessary format lookup in \Drupal...

  • alexpott committed 112e955 on 8.3.x
    Revert "Issue #2457345 by vijaycs85: Remove unnecessary format lookup in...
  • alexpott committed 744514b on 8.3.x
    Issue #2457345 by vijaycs85: Remove unnecessary format lookup in \Drupal...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • alexpott committed 112e955 on 8.4.x
    Revert "Issue #2457345 by vijaycs85: Remove unnecessary format lookup in...
  • alexpott committed 744514b on 8.4.x
    Issue #2457345 by vijaycs85: Remove unnecessary format lookup in \Drupal...

  • alexpott committed 112e955 on 8.4.x
    Revert "Issue #2457345 by vijaycs85: Remove unnecessary format lookup in...
  • alexpott committed 744514b on 8.4.x
    Issue #2457345 by vijaycs85: Remove unnecessary format lookup in \Drupal...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (outdated)
Issue tags: -d8date +Bug Smash Initiative
Related issues: +#3295658: Improve documentation and parameter naming for DateFormatter::dateFormat()

This appears to have been fixed in #2846643: DateFormatter should not attempt to load a format from storage if the format is "custom" expect for the documentation changes and variable name change to \Drupal\Core\Datetime\DateFormatter::dateFormat.

I am going to close this as outdated and open a new issue for the other changes. Moving credit other there.

quietone’s picture