diff --git a/src/Service/UwBlockManualRender.php b/src/Service/UwBlockManualRender.php index 6176bca013ff574d43047b364ad16e8704971af7..639befcab2dc5d94d6b0daa91a05e3744f0391ce 100644 --- a/src/Service/UwBlockManualRender.php +++ b/src/Service/UwBlockManualRender.php @@ -256,48 +256,78 @@ class UwBlockManualRender { */ private function getCatalogItemRender(array $config): array { - // Get the view for catalog items. + // Load the view. $view = $this->entityTypeManager ->getStorage('view') ->load('uw_view_catalog_search') ->getExecutable(); - // Set the display to the embed view. - $view->setDisplay('catalog_search_all_embed'); - - // If there are catalog items, add them to the - // contextual filter of the view. + // Load the correct view display, based on if a + // catalog was entered. if ( - isset($config['catalog_item']['catalog_item_ids']) && - count($config['catalog_item']['catalog_item_ids']) > 0 + isset($config['catalog_item']['in_catalog']) && + $config['catalog_item']['in_catalog'] == 1 ) { - // The catalog id contextual filter value. - $catalog_ids = ''; + // Set the display unset the all items flag. + $view->setDisplay('search_specific_embed'); + + // Set the catalog argument list. + $catalog_arg_list = $this->uwBlockService->getTermList($config['catalog']); + + // Get the catalog filter, set the value and set the handler. + $filter = $view->getHandler( + 'search_specific_embed', + 'filter', + 'field_uw_catalog_catalog_target_id' + ); + $filter['value'] = explode(',', $catalog_arg_list); + $view->setHandler( + 'search_specific_embed', + 'filter', + 'field_uw_catalog_catalog_target_id', + $filter + ); + } + else { - // Counter used to add the + sign in between filters. - $counter = 0; + // Set the display to the embed view. + $view->setDisplay('catalog_search_all_embed'); - // Step through each of the catalog item ids and add them - // to the catalog ids filter value. - foreach ($config['catalog_item']['catalog_item_ids'] as $catalog_item_id) { + // If there are catalog items, add them to the + // contextual filter of the view. + if ( + isset($config['catalog_item']['catalog_item_ids']) && + count($config['catalog_item']['catalog_item_ids']) > 0 + ) { - // If we are past the first value add the plus sign so - // that the contextual filters work correctly. - if ($counter > 0) { - $catalog_ids .= '+'; - } + // The catalog id contextual filter value. + $catalog_ids = ''; + + // Counter used to add the + sign in between filters. + $counter = 0; - // Add the value to the filters. - $catalog_ids .= $catalog_item_id['id']; + // Step through each of the catalog item ids and add them + // to the catalog ids filter value. + foreach ($config['catalog_item']['catalog_item_ids'] as $catalog_item_id) { - // Increment the counter so we get the plus sign if required. - $counter++; - } + // If we are past the first value add the plus sign so + // that the contextual filters work correctly. + if ($counter > 0) { + $catalog_ids .= '+'; + } - // If there are catalog id filters, add to the view. - if ($catalog_ids) { - $view->setArguments([$catalog_ids]); + // Add the value to the filters. + $catalog_ids .= $catalog_item_id['id']; + + // Increment the counter so we get the plus sign if required. + $counter++; + } + + // If there are catalog id filters, add to the view. + if ($catalog_ids) { + $view->setArguments([$catalog_ids]); + } } }