Problem/Motivation

Adding a DateItem to your entity currently does not work at all.

Steps to reproduce

  1. Add the following to Node::baseFieldDefinitions():
    $fields['broken_date'] = FieldDefinition::create('date');
    
  2. Clear caches
  3. Go to node/add/article

Expected result:
You are able to edit a node.

Actual result:

InvalidArgumentException: Invalid data type date has been given. in Drupal\Core\TypedData\TypedDataManager->createInstance() (line 91 of core/lib/Drupal/Core/TypedData/TypedDataManager.php)

Details

The exception message is right: There is no @DataType plugin with the id date.

Proposed resolution

Remaining tasks

User interface changes

None.

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Note, because I just realized this might be confusing:

There is a @FieldType plugin with ID date, so the example code is valid. See DateItem. DateItem itself uses the typed data plugin with ID date for its value property. That is the one that doesn't exist which is why this is broken.

tstoeckler’s picture

Priority: Normal » Major

Raising to major. This is really, really bad. It can't be triggered from the UI so not critical, but certainly major.

mr.baileys’s picture

Status: Active » Needs review
FileSize
685 bytes

Could the fix be as simple as changing DateItem to use the DateTimeIso8601 typed data definition?

Berdir’s picture

Issue tags: +Needs tests

Yeah, looks like this was never updated when we renamed that.

Another question is if this should be dropped/merged with the datetime module field type.

Berdir’s picture

As suggested in #2150511: [meta] Deduplicate the set of available field types, I think we should simply drop this in favor of DateTimeItem from datetime.module.

Berdir’s picture

Title: DateItem is completely broken » DateItem is completely broken, remove it
Category: Bug report » Task
Issue tags: -Needs tests
FileSize
1.4 KB
swentel’s picture

Status: Needs review » Reviewed & tested by the community
yched’s picture

Yep, +1.

AFAICT through git log tracking, DateItem was introduced in the very original "Entity Property API" patch in #1696640: Implement API to unify entity properties and fields as one of the available "EntityNG field types", but was never actually used for anything...

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 769d611 and pushed to 8.x. Thanks!

  • alexpott committed 769d611 on 8.0.x
    Issue #2239241 by Berdir, mr.baileys | tstoeckler: DateItem is...

Status: Fixed » Closed (fixed)

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