Problem/Motivation

This is now the second time I hit against an issue where having more context passed to the initial values event would be helpful.

When we call:

  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $item = $items[$delta];
    $value = $item->getEntity()->isNew() ? $this->getInitialValues() : $item->toArray();

we don't pass the FieldItem along.

This is a problem, because I've called createDuplicate(), which nulls out the entity id and now my pre-seeded values get deleted. Either don't check isNew, or pass the item along so I can return to the defaults dynamically provided to the address widget.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 2951637.patch3.69 KBheddn

Comments

heddn created an issue. See original summary.

heddn’s picture

Status: Active » Needs review
StatusFileSize
new3.69 KB

Let's see if this passes tests.

bojanz’s picture

Status: Needs review » Closed (duplicate)

The real fix for the described problem is #2838457: Re-enable the default value functionality for Address fields. Correct me if I'm wrong.

heddn’s picture

Status: Closed (duplicate) » Needs review

No, that doesn't fix it for me. I had values already in the address field. I just want to clone them. But when I clone them, that means it goes back to the default values provided by the field config, not the previously entered data.

Example pre-clone:
John Smith
123 Main St.
Anywhere, NY, 55555-5555
USA

Becomes:
USA

Because I don't have the original values prior to clone passed along as content when looking at the InitialValuesEvent.

bojanz’s picture

Status: Needs review » Closed (won't fix)

#2838457: Re-enable the default value functionality for Address fields is now almost ready and results in the entire InitialValues event no longer being fired, so we can't proceed with this issue.