Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r14244 -r14572 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14244) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14572) @@ -1,6 +1,6 @@ createItemFiles($event->Prefix, true); // create image fields $file_helper->createItemFiles($event->Prefix, false); // create file fields - // add EditorsPick to ForcedSorting if needed - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - if (array_key_exists('ForceEditorPick', $config_mapping) && $this->Application->ConfigValue($config_mapping['ForceEditorPick'])) { - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); + $this->changeSortings($event); - $new_forced_sorting = Array ('EditorsPick' => 'DESC'); - - if (array_key_exists('ForcedSorting', $list_sortings[''])) { - foreach ($list_sortings['']['ForcedSorting'] as $sort_field => $sort_order) { - $new_forced_sorting[$sort_field] = $sort_order; - } - } - $list_sortings['']['ForcedSorting'] = $new_forced_sorting; - - $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); - } - // add grids for advanced view (with primary category column) $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); $process_grids = Array ('Default', 'Radio'); @@ -2570,6 +2555,38 @@ $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields); } + function changeSortings(&$event) + { + $remove_sortings = Array (); + + if (!$this->Application->isAdmin) { + // remove Pick sorting on Front-end, when not required + $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + + if (!isset($config_mapping['ForceEditorPick']) || !$this->Application->ConfigValue($config_mapping['ForceEditorPick'])) { + $remove_sortings[] = 'EditorsPick'; + } + } + else { + // remove all forced sortings in Admin Console + $remove_sortings = array_merge($remove_sortings, Array ('Priority', 'EditorsPick')); + } + + if (!$remove_sortings) { + return ; + } + + $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); + + foreach ($list_sortings as $special => $sorting_fields) { + foreach ($remove_sortings as $sorting_field) { + unset($list_sortings[$special]['ForcedSorting'][$sorting_field]); + } + } + + $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); + } + /** * Returns file contents associated with item *