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
Comments
Comment #2
heddnLet's see if this passes tests.
Comment #3
bojanz commentedThe real fix for the described problem is #2838457: Re-enable the default value functionality for Address fields. Correct me if I'm wrong.
Comment #4
heddnNo, 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.
Comment #5
bojanz commented#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.