From bab081692a03f36d297986b61a10c7accb068d50 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Fri, 17 Jun 2022 16:03:55 -0700 Subject: [PATCH] Allow asset IDs to be passed as query params to asset move form. --- .../location/src/Form/AssetMoveActionForm.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/core/location/src/Form/AssetMoveActionForm.php b/modules/core/location/src/Form/AssetMoveActionForm.php index d2796fa4f..a991ecb89 100644 --- a/modules/core/location/src/Form/AssetMoveActionForm.php +++ b/modules/core/location/src/Form/AssetMoveActionForm.php @@ -2,6 +2,7 @@ namespace Drupal\farm_location\Form; +use Drupal\asset\Entity\AssetInterface; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\ConfirmFormBase; @@ -127,8 +128,27 @@ class AssetMoveActionForm extends ConfirmFormBase { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { + + // Check if asset IDs were provided in the asset query param. + $request = \Drupal::request(); + if ($asset_ids = $request->get('asset')) { + + // Wrap in an array, if necessary. + if (!is_array($asset_ids)) { + $asset_ids = [$asset_ids]; + } + + // Add each asset the user has view access to. + $this->entities = array_filter($this->entityTypeManager->getStorage('asset')->loadMultiple($asset_ids), function (AssetInterface $asset) { + return $asset->access('view', $this->user); + }); + } + // Else load entities from the tempStore state. + else { + $this->entities = $this->tempStore->get($this->user->id()); + } + $this->entityType = $this->entityTypeManager->getDefinition('asset'); - $this->entities = $this->tempStore->get($this->user->id()); if (empty($this->entityType) || empty($this->entities)) { return new RedirectResponse($this->getCancelUrl() ->setAbsolute()