diff --git a/src/Plugin/EntityBrowser/Widget/BynderUpload.php b/src/Plugin/EntityBrowser/Widget/BynderUpload.php index a481636..f93bbba 100644 --- a/src/Plugin/EntityBrowser/Widget/BynderUpload.php +++ b/src/Plugin/EntityBrowser/Widget/BynderUpload.php @@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Drupal\Core\Entity\EntityStorageException; /** * Uses upload to create media entities. @@ -255,7 +256,13 @@ class BynderUpload extends BynderWidgetBase { $media = $this->prepareEntities($form, $form_state); array_walk($media, function (MediaInterface $item) { if (!$item->id()) { - $item->save(); + // Some race conditions might occur in some circumstances and could + // try to save this entity twice. + try { + $item->save(); + } + catch (EntityStorageException $e) { + } } }); $this->selectEntities($media, $form_state);