From e09e56af09ddb7bc35d1c8af27536bc4fa217d55 Mon Sep 17 00:00:00 2001 From: danchadwick Date: Wed, 16 Nov 2022 10:11:02 -0500 Subject: [PATCH] Patch 3315270-2 --- .../Field/FieldWidget/ProfileFormWidget.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Plugin/Field/FieldWidget/ProfileFormWidget.php b/src/Plugin/Field/FieldWidget/ProfileFormWidget.php index e49b9f3..691c8d3 100644 --- a/src/Plugin/Field/FieldWidget/ProfileFormWidget.php +++ b/src/Plugin/Field/FieldWidget/ProfileFormWidget.php @@ -153,11 +153,11 @@ class ProfileFormWidget extends WidgetBase implements ContainerFactoryPluginInte $profile_type_storage = $this->entityTypeManager->getStorage('profile_type'); /** @var \Drupal\profile\Entity\ProfileTypeInterface $profile_type */ $profile_type = $profile_type_storage->load($this->getFieldSetting('profile_type')); - $property = ['profiles', $profile_type->id()]; + $property = ['profiles', $profile_type->id(), $delta]; $profile = $form_state->get($property); if (!$profile) { - if (!$account->isAnonymous()) { - $profile = $profile_storage->loadByUser($account, $profile_type->id()); + if (!$account->isAnonymous() && ($profile_id = $items->get($delta)->target_id)) { + $profile = $profile_storage->load($profile_id); } if (!$profile) { $values = [ @@ -206,6 +206,7 @@ class ProfileFormWidget extends WidgetBase implements ContainerFactoryPluginInte $items->getName(), $delta, 'entity', ]), '#bundle' => $profile->bundle(), + '#delta' => $delta, '#element_validate' => [ [get_class($this), 'validateProfileForm'], ], @@ -266,11 +267,9 @@ class ProfileFormWidget extends WidgetBase implements ContainerFactoryPluginInte return; } $property = ['profiles', $this->getFieldSetting('profile_type')]; - $profile = $form_state->get($property); - if (!empty($profile)) { - $values = [ - ['entity' => $profile], - ]; + $profiles = $form_state->get($property); + if (!empty($profiles)) { + $values = array_map(function($profile) { return ['entity' => $profile]; }, $profiles); $items->setValue($values); $items->filterEmptyItems(); } @@ -285,8 +284,8 @@ class ProfileFormWidget extends WidgetBase implements ContainerFactoryPluginInte * The current state of the form. */ public static function validateProfileForm(array &$element, FormStateInterface $form_state) { + $property = ['profiles', $element['#bundle'], $element['#delta']]; /** @var \Drupal\profile\Entity\ProfileInterface $profile */ - $property = ['profiles', $element['#bundle']]; $profile = $form_state->get($property); if (!empty($profile)) { assert($profile instanceof ProfileInterface); @@ -311,11 +310,13 @@ class ProfileFormWidget extends WidgetBase implements ContainerFactoryPluginInte return; } $profiles = $form_state->get('profiles'); - foreach ($profiles as $profile) { - assert($profile instanceof ProfileInterface); - $profile->setOwnerId($account->id()); - $profile->setPublished(); - $profile->save(); + foreach ($profiles as $profile_list) { + foreach ($profile_list as $profile) { + assert($profile instanceof ProfileInterface); + $profile->setOwnerId($account->id()); + $profile->setPublished(); + $profile->save(); + } } } -- 2.30.0.windows.2