Skip to content
Snippets Groups Projects
Commit 27eef099 authored by Lily Yan's avatar Lily Yan
Browse files

ISTWCMS-7116 Remove 'In catalog' if selecting the checkbox

parent b9b57a71
No related branches found
No related tags found
1 merge request!249ISTWCMS-7116 Add option to disable showing which catalog an item is from in listing blocks
...@@ -256,48 +256,78 @@ class UwBlockManualRender { ...@@ -256,48 +256,78 @@ class UwBlockManualRender {
*/ */
private function getCatalogItemRender(array $config): array { private function getCatalogItemRender(array $config): array {
// Get the view for catalog items. // Load the view.
$view = $this->entityTypeManager $view = $this->entityTypeManager
->getStorage('view') ->getStorage('view')
->load('uw_view_catalog_search') ->load('uw_view_catalog_search')
->getExecutable(); ->getExecutable();
// Set the display to the embed view. // Load the correct view display, based on if a
$view->setDisplay('catalog_search_all_embed'); // catalog was entered.
// If there are catalog items, add them to the
// contextual filter of the view.
if ( if (
isset($config['catalog_item']['catalog_item_ids']) && isset($config['catalog_item']['in_catalog']) &&
count($config['catalog_item']['catalog_item_ids']) > 0 $config['catalog_item']['in_catalog'] == 1
) { ) {
// The catalog id contextual filter value. // Set the display unset the all items flag.
$catalog_ids = ''; $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. // Set the display to the embed view.
$counter = 0; $view->setDisplay('catalog_search_all_embed');
// Step through each of the catalog item ids and add them // If there are catalog items, add them to the
// to the catalog ids filter value. // contextual filter of the view.
foreach ($config['catalog_item']['catalog_item_ids'] as $catalog_item_id) { 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 // The catalog id contextual filter value.
// that the contextual filters work correctly. $catalog_ids = '';
if ($counter > 0) {
$catalog_ids .= '+'; // Counter used to add the + sign in between filters.
} $counter = 0;
// Add the value to the filters. // Step through each of the catalog item ids and add them
$catalog_ids .= $catalog_item_id['id']; // 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. // If we are past the first value add the plus sign so
$counter++; // that the contextual filters work correctly.
} if ($counter > 0) {
$catalog_ids .= '+';
}
// If there are catalog id filters, add to the view. // Add the value to the filters.
if ($catalog_ids) { $catalog_ids .= $catalog_item_id['id'];
$view->setArguments([$catalog_ids]);
// 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]);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment