Updated: Comment #5

Problem/Motivation

When guessing an existing format, D8 returns the error message:
"This format already exists. Enter a unique format string. "

Similary, when guessing and existing machine name, D8 returns the error message:
"The machine-readable name is already in use. It must be unique."

This is confusing because some formats are not included in the list on:
http://example.com/admin/config/regional/date-time

Steps to recreate:

First case: Guessing an existing format

Steps to reproduce:
1. Install Drupal8 Head
2. Go to admin/config/regional/date-time/formats/add
3. Add new date format:
Name: TestFormat
Machine name: testformat
Format String: Y
Languages: English
=> Add format

Second case:
1. Install Drupal8 Head
2. Go to admin/config/regional/date-time/formats/add
3. Add new date format:
Name: HTML Date
Machine Name: html_date
Format String: YYYY
Languages: English
=> Add format

Error message: ""The machine-readable name is already in use. It must be unique."

Here are all currently defined date formats (in core/modules/system/config):

Not in UI list:

Fallback date format fallback intl: 'ccc, MM/dd/yyyy - kk:mm'
HTML Date html_date intl: yyyy-MM-dd
HTML Datetime html_datetime intl: 'yyyy-MM-dd''T''kk:mm:ssZZ'
HTML Month html_month intl: Y-MM
HTML Time html_time intl: 'H:mm:ss'
HTML Week html_week intl: 'Y-''W''WW'
HTML Year html_year intl: MM-d

Currently in UI list:

Default long date long intl: 'EEEE, LLLL d, yyyy - kk:mm'
Default medium date medium intl: 'ccc, MM/dd/yyyy - kk:mm'
Default short date short intl: 'MM/dd/yyyy - kk:mm'

Proposed resolution

Display the unmutable machine names and formats in the Date and Time format list - but don't allow them to be changed.

Remaining tasks

User interface changes

Yes.

before

from comment #19

after

from comment #19

API changes

Probably not.

#2100351: Date format name 'custom' is reserved but not checked for
#2119997: Change UI to remove display machine name for date formats

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ursula’s picture

Issue summary: View changes

Updated issue summary - add more details

ursula’s picture

Issue summary: View changes

issue summary update - formatting

ursula’s picture

Issue summary: View changes

issue summary edit - more information.

YesCT’s picture

Title: Adding date format returns error for format not in the date-time list » Adding a date format that is *not* in the list of existing formats returns error "already in use". huh?!

clarifying title

YesCT’s picture

Issue summary: View changes

Issue summary update - formatting

evilehk’s picture

Assigned: Unassigned » evilehk

I believe I can help here and am working on this.

evilehk’s picture

Status: Active » Needs review
FileSize
44.3 KB
1.09 KB

The attached patch implements the proposed solution of displaying the locked date format fields in the date format entity list page. Similar to how the field ui displays locked fields by adding " (Locked)" in the label, the date format list does the same thing.

The below highlights the new rows. The path in the screenshot is admin/config/regional/date-time

Date and time formats - Drop8.png

YesCT’s picture

Issue tags: +Needs usability review

cool. that is a great start.

@evilehk did we open an issue also to *allow* creating a new format even if it duplicates another patter? (not duplicate machine name, but pattern) I dont think we did, so

next steps:
* ui review
* open another issue to allow duplicate formats (and link it in the summaries of these related issues)

I think we need a usability review.
We can help that by looking around in core for other UIs that show locked things like this.

HM. the language detection and selection hides a type. it is invisible.
and we hide the not applicable, etc system language, often.
hm.
roles is kind of similar, in that it shows system things (but different in that we can change stuff about the roles, like their human names I think)

this might be a wont fix.

new idea:
put the system ones is a collapsed set
maybe with a label like "System date formats"

and, (optional) since there is no edit on the system ones, we might want to include the info we see on edit of the regular ones, like the php pattern.

In summary, we really need that other issue that allows creating duplicate formats.
Maybe with a little helper step that says: "hi, you already have these other formats with that same pattern. Do you really want another one?" ... well that might not be a great pattern. but we can discuss that in the other issue.

YesCT’s picture

Issue summary: View changes

added related issue

tim.plunkett’s picture

Filter formats make the locked filter undelete-able. But it is still editable.

tim.plunkett’s picture

Issue summary: View changes

updated remaining tasks

evilehk’s picture

evilehk’s picture

Assigned: evilehk » Unassigned

Unassigning for no particular reason other than I didn't realize this patch was still assigned to me and do not want to discourage others from reviewing

wylbur’s picture

Installed this patch on a clean install of D8-dev today. The patch applied cleanly and, the UI shows all the locked system date formats. The US is not very friendly at this point, new formats are added under all the locked system formats. (see screen shot)

Screenshot of UI

There is another issue about removing the machine names from the UI list, Change UI to remove display machine name for date formats, and replacing it as a hover. If we do show all these system elements, does it really make sense to show them if we don't show the machine name except as a hover?

Bojhan’s picture

Why cant one edit these?

tim.plunkett’s picture

vijaycs85’s picture

Priority: Normal » Critical
Issue tags: +D8UX usability
Related issues: +#2091397: Create hook_help for Datetime module

#2091397: Create hook_help for Datetime module blocked by this issue. raising this as critical as well.

tim.plunkett’s picture

Priority: Critical » Normal

No, #2091397: Create hook_help for Datetime module is not actually blocked by this. The hook_help() should describe what is happening.
If we choose to change things in this issue, this issue will update the hook_help() accordingly.

jhodgdon’s picture

Title: Adding a date format that is *not* in the list of existing formats returns error "already in use". huh?! » Adding a date format that is locked (and currently *not* shown in the list of existing formats) returns error "already in use". huh?!
Issue tags: +Usability
vijaycs85’s picture

This patch has:

1. Reroll of patch in #3
2. Addressing the sort issue reported by @wylbur at #8
3. Manual test (before vs after) for sorting fix.

YesCT’s picture

Issue summary: View changes
Issue tags: +Needs screenshots, +Novice

The before and after screenshots show a different number of things...

We still need a before screenshot before any patch is applied.

Is the sort based on locked first (to put them at the bottom) and then Name (or machine name)?

YesCT’s picture

Issue summary: View changes

fixing html

vijaycs85’s picture

Thanks for the review @YesCT.

We still need a before screenshot before any patch is applied.

- added new set.

Is the sort based on locked first (to put them at the bottom) and then Name (or machine name)?

- It wasn't order by name in #14, but it does sort by name, if the lock status are same.

jhodgdon’s picture

Issue tags: +Needs screenshots, +Novice

I don't think that "before" screenshot in #17 is really "before any patch is applied", unless the title and issue summary are way out of date. It doesn't seem to be illustrating the bug.

vijaycs85’s picture

Really very sorry for making this more complicated :(

@jhodgdon is correct. The before is "before I fix the order problem" instead of "before *this* issue patch as a whole". Here is proper before/after.

vijaycs85’s picture

Issue summary: View changes
jhodgdon’s picture

Thanks!!

tim.plunkett’s picture

Title: Adding a date format that is locked (and currently *not* shown in the list of existing formats) returns error "already in use". huh?! » Show locked date formats in the UI
Component: datetime.module » system.module
Status: Needs review » Needs work
  1. +++ b/core/modules/system/lib/Drupal/system/DateFormatListBuilder.php
    @@ -59,9 +60,9 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
       public function load() {
    -    return array_filter(parent::load(), function ($entity) {
    -      return !$entity->isLocked();
    -    });
    +    $entities = parent::load();
    +    uasort($entities, 'static::sort');
    +    return $entities;
       }
    

    You can remove this method override completely. ConfigEntityListBuilder::load() already calls the sort method on the entity class.

  2. +++ b/core/modules/system/lib/Drupal/system/DateFormatListBuilder.php
    @@ -78,10 +79,28 @@ public function buildHeader() {
    +      $row['id'] =  t('@entity_id (Locked)', array('@entity_id' => $entity->id()));
    

    Use $this->t() please.

  3. +++ b/core/modules/system/lib/Drupal/system/DateFormatListBuilder.php
    @@ -78,10 +79,28 @@ public function buildHeader() {
    +  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
    +      if ($a->isLocked() == $b->isLocked()) {
    +        $a_label = $a->label();
    +        $b_label = $b->label();
    +        return strnatcasecmp($a_label, $b_label);
    +      }
    +      return $a->isLocked() ? 1 : -1;
    +  }
    

    This should be moved to the DateFormat class directly. Also, the indentation is wrong.

I updated the title to reflect the solution, and date formats are owned by system module, unrelated to the optional datetime.module.

vijaycs85’s picture

Thanks for the review @tim.plunkett

#22.1 - Fixed
#22.2 - Fixed
#22.3 - Fixed

Still the result is same.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Looks great, thanks!

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Unless mine eyes deceive me, we're lacking explicit test coverage for this, so needs work for that.

Also needs work because the only other place I've seen this "(locked)" pattern is on the Roles page, and there it's "anonymous user (locked)," (lowercase L, emphasized) so we should do the same here.

Don't want to scope creep this too much, but off-hand, it feels weird to have more locked things in an admin than unlocked things that you can actually do something with, and having those two things co-mingling in the same list. Would it be easy/desirable to simply split the table in two (Custom / Locked), similar to Enabled / Disabled in the Views UI listing)?

If that's a huge ball of wax, feel free to just fix the first two points, though, unless someone from the UX team feels strongly.

YesCT’s picture

Issue summary: View changes
Issue tags: +Novice

updated issue summary remaining tasks, added contributor task document links, and tagged.

mparker17’s picture

Assigned: Unassigned » mparker17

I want to learn how to write automated tests: assigning to myself.

mparker17’s picture

Re-rolled patch because it didn't apply. Haven't made any changes yet, so no interdiff.

mparker17’s picture

FileSize
2.42 KB
639 bytes

Changed "(Locked)" to "(locked)".

As an aside, I didn't notice any "locked" text on the Roles page currently, but this could be because of a recent patch.

Still have to write tests.

mparker17’s picture

FileSize
3.61 KB
1.11 KB

Added tests.

Feedback welcome.

Special thanks to @lauriii for mentoring me!

mparker17’s picture

Assigned: mparker17 » Unassigned
Status: Needs work » Needs review
vijaycs85’s picture

Issue tags: +date

Thanks @mparker17 for the patch. Let's add an unique tag for date issues (as this is system.module component), so that we can track them.

reg #25:

Thanks @webchick for the valuable comments & QA.

we're lacking explicit test coverage for this, so needs work for that.

- @mparker17 addressed this in current patch

Also needs work because the only other place I've seen this "(locked)" pattern is on the Roles page, and there it's "anonymous user (locked)," (lowercase L, emphasized) so we should do the same here.

- @mparker17 addressed this current patch

Don't want to scope creep this too much, but off-hand, it feels weird to have more locked things in an admin than unlocked things that you can actually do something with, and having those two things co-mingling in the same list. Would it be easy/desirable to simply split the table in two (Custom / Locked), similar to Enabled / Disabled in the Views UI listing)?

If that's a huge ball of wax, feel free to just fix the first two points, though, unless someone from the UX team feels strongly.

Totally agreed on unifying UI part, but may be not this issue :). Let's fix both pages (and if there any other pages with this case) at #2280055: Unify the UI of locked+unlocked components list

vijaycs85’s picture

Issue tags: -Needs tests
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Yes, I agree that all the points from webchick's "needs work" in #25 seem to be addressed. Back to RTBC. Thanks mparker17!

xjm’s picture

#2091397: Create hook_help for Datetime module is also (presumably briefly) postponed on this issue.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

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