diff --git a/src/Form/EntityBrowserForm.php b/src/Form/EntityBrowserForm.php index e530819..484f610 100644 --- a/src/Form/EntityBrowserForm.php +++ b/src/Form/EntityBrowserForm.php @@ -16,6 +16,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface { /** + * UUID generator service. + * + * @var \Drupal\Component\Uuid\UuidInterface + */ + protected $uuidGenerator; + + /** * The entity browser object. * * @var \Drupal\entity_browser\EntityBrowserInterface @@ -23,6 +30,25 @@ class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface { protected $entity_browser; /** + * Constructs a EntityBrowserForm object. + * + * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * The UUID generator service. + */ + public function __construct(UuidInterface $uuid_generator) { + $this->uuidGenerator = $uuid_generator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('uuid') + ); + } + + /** * {@inheritdoc} */ public function getFormId() { @@ -45,11 +71,11 @@ class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface { protected function init(FormStateInterface $form_state) { // Flag that this form has been initialized. $form_state->set('entity_form_initialized', TRUE); - if (empty($_GET['uuid'])) { - $form_state->set(['entity_browser', 'instance_uuid'], \Drupal::service('uuid')->generate()); + if ($this->getRequest()->query->has('uuid')) { + $form_state->set(['entity_browser', 'instance_uuid'], $this->getRequest()->query->get('uuid')); } else { - $form_state->set(['entity_browser', 'instance_uuid'], $_GET['uuid']); + $form_state->set(['entity_browser', 'instance_uuid'], $this->uuidGenerator->generate()); } $form_state->set(['entity_browser', 'selected_entities'], []); $form_state->set(['entity_browser', 'selection_completed'], FALSE);