diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php index 6e4274c8755..8e0fbbc6dbc 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php +++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php @@ -455,6 +455,12 @@ public function saveAction() return $response; } + if ($this->formWasSubmitted('newList')) { + // Remove submit now from parameters + $this->getRequest()->getPost()->set('newList', null)->set('submitButton', null); + return $this->forwardTo('MyResearch', 'editList', ['id' => 'NEW']); + } + // Process form submission: if ($this->formWasSubmitted()) { return $this->processSave(); diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index 4ec433c9eab..e20473e3d86 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -533,9 +533,22 @@ public function saveAction() ['cartIds' => $ids, 'cartAction' => 'Save'] ); } - + $viewModel = $this->createViewModel( + [ + 'records' => $this->getRecordLoader()->loadBatch($ids), + 'lists' => $this->getDbService(UserListServiceInterface::class)->getUserListsByUser($user), + ] + ); + if ($submitDisabled ?? false) { + return $viewModel; + } + if ($this->formWasSubmitted('newList')) { + // Remove submit now from parameters + $this->getRequest()->getPost()->set('newList', null)->set('submitButton', null); + return $this->forwardTo('MyResearch', 'editlist', ['id' => 'NEW']); + } // Process submission if necessary: - if (!($submitDisabled ?? false) && $this->formWasSubmitted()) { + if ($this->formWasSubmitted()) { $results = $this->getService(FavoritesService::class) ->saveRecordsToFavorites($this->getRequest()->getPost()->toArray(), $user); $listUrl = $this->url()->fromRoute( @@ -553,11 +566,6 @@ public function saveAction() } // Pass record and list information to view: - return $this->createViewModel( - [ - 'records' => $this->getRecordLoader()->loadBatch($ids), - 'lists' => $this->getDbService(UserListServiceInterface::class)->getUserListsByUser($user), - ] - ); + return $viewModel; } } diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index d52b431b83d..6c6288e8c76 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -42,6 +42,7 @@ use VuFind\Crypt\SecretCalculator; use VuFind\Db\Entity\SearchEntityInterface; use VuFind\Db\Entity\UserEntityInterface; +use VuFind\Db\Entity\UserListEntityInterface; use VuFind\Db\Service\SearchServiceInterface; use VuFind\Db\Service\UserListServiceInterface; use VuFind\Db\Service\UserResourceServiceInterface; @@ -1180,9 +1181,9 @@ protected function processEditList(UserEntityInterface $user, $list) // If the user is in the process of saving a record, send them back // to the save screen; otherwise, send them back to the list they // just edited. - $recordId = $this->params()->fromQuery('recordId'); - $recordSource - = $this->params()->fromQuery('recordSource', DEFAULT_SEARCH_BACKEND); + $recordId = $this->params()->fromQuery('recordId') ?? $this->params()->fromPost('recordId'); + $recordSource = $this->params()->fromQuery('recordSource') + ?? $this->params()->fromPost('recordSource', DEFAULT_SEARCH_BACKEND); if (!empty($recordId)) { $details = $this->getRecordRouter()->getActionRouteDetails( $recordSource . '|' . $recordId, @@ -1196,19 +1197,12 @@ protected function processEditList(UserEntityInterface $user, $list) // Similarly, if the user is in the process of bulk-saving records, // send them back to the appropriate place in the cart. - $bulkIds = $this->params()->fromPost( - 'ids', - $this->params()->fromQuery('ids', []) - ); + $bulkIds = $this->params()->fromPost('ids') ?? $this->params()->fromQuery('ids', []); if (!empty($bulkIds)) { - $params = []; - foreach ($bulkIds as $id) { - $params[] = urlencode('ids[]') . '=' . urlencode($id); - } - $saveUrl = $this->url()->fromRoute('cart-save'); - $saveUrl .= (!str_contains($saveUrl, '?')) ? '?' : '&'; - return $this->redirect() - ->toUrl($saveUrl . implode('&', $params)); + // Add final id of the list to request post so cartcontroller saveaction + // can properly load the list + $this->getRequest()->getPost()->set('list', $finalId); + return $this->forwardTo('Cart', 'Save'); } return $this->redirect()->toRoute('userList', ['id' => $finalId]); @@ -1240,7 +1234,7 @@ public function editlistAction() // Is this a new list or an existing list? Handle the special 'NEW' value // of the ID parameter: - $id = $this->params()->fromRoute('id', $this->params()->fromQuery('id')); + $id = $this->params()->fromRoute('id') ?? $this->params()->fromQuery('id') ?? $this->params()->fromPost('id'); $newList = ($id == 'NEW'); // If this is a new list, use the FavoritesService to pre-populate some values in // a fresh object; if it's an existing list, we can just fetch from the database. @@ -1255,10 +1249,8 @@ public function editlistAction() } // Process form submission: - if ($this->formWasSubmitted()) { - if ($redirect = $this->processEditList($user, $list)) { - return $redirect; - } + if ($this->formWasSubmitted() && $redirect = $this->processEditList($user, $list)) { + return $redirect; } $listTags = null; @@ -1273,6 +1265,10 @@ public function editlistAction() 'list' => $list, 'newList' => $newList, 'listTags' => $listTags, + 'recordIds' => $this->params()->fromQuery('ids') ?? $this->params()->fromPost('ids', []), + 'recordId' => $this->params()->fromQuery('recordId') ?? $this->params()->fromPost('recordId', false), + 'recordSource' => $this->params()->fromQuery('recordSource') + ?? $this->params()->fromPost('recordSource', DEFAULT_SEARCH_BACKEND), ] ); } diff --git a/themes/bootstrap3/templates/cart/form-record-hidden-inputs.phtml b/themes/bootstrap3/templates/cart/form-record-hidden-inputs.phtml new file mode 100644 index 00000000000..0c93ff1e089 --- /dev/null +++ b/themes/bootstrap3/templates/cart/form-record-hidden-inputs.phtml @@ -0,0 +1,21 @@ +driver?->getUniqueId() ?? $this->recordId ?? false; + $recordSource = $this->driver?->getSourceIdentifier() ?? $this->recordSource ?? DEFAULT_SEARCH_BACKEND; +?> + + + + + + +recordIds)) { + $this->recordIds = array_map( + fn ($record) => $record->getSourceIdentifier() . '|' . $record->getUniqueId(), + $this->records ?? [] + ); + } +?> +recordIds as $current): ?> + + diff --git a/themes/bootstrap3/templates/cart/save.phtml b/themes/bootstrap3/templates/cart/save.phtml index 341b2aa4cea..f24a6f04b07 100644 --- a/themes/bootstrap3/templates/cart/save.phtml +++ b/themes/bootstrap3/templates/cart/save.phtml @@ -12,11 +12,7 @@ records) > 0): ?>
=$this->transEsc('This item is already part of the following list/lists') ?>: containingLists as $i => $list): ?> @@ -41,7 +40,7 @@ - =$showLists ? $this->transEsc('or create a new list') : $this->transEsc('Create a List'); ?> +