Hide Courses/Class from Course Catalogue

I have a situation where we want to set up a general/public course catalogue. At the same time, we want to create a class containing additional courses for a specific group of people ("restricted class"). We do not want the 'public' to see the "restricted class" (and its courses) in the LIST in the general/public course catalogue (I am not talking about RESTRICTING ACCESS to the class - that is easy! I am talking about RESTRICTING VISIBILITY of the class entry in the Course Catalogue to subscribed users only.) Access to the "restricted class" will be granted by the Administrator. How can we go about this? Is it possible? Any help is appreciated.

Hi n8in.

Hi n8in. Sorry for the late reply on your question. That *is* tricky. The problem is the courses. It's pretty easy to hide the class. It's more difficult to hide the courses underneath it, because of the way Drupal works. This would require some custom logic. The *easiest* way, although pretty hacky, would be to implement a query alter hook. Create a custom module (tell me if you need any pointers on this), and add this code to it (**not tested**, try on a test server first): /** * Implements hook_views_query_alter(). */ function MY_MODULE_views_query_alter(&$view, &$query) { global $user; // This comment is used by Opigno to filter out courses and classes the user // is a member of. It will target the correct view. if (preg_match('/exclude_own_groups/', $query->options['query_comment'])) { $class_node = node_load(87); $nids = array($class_node->nid); if (!empty($class_node->opigno_class_courses)) { foreach ($class_node->opigno_class_courses as $lang => $items) { foreach ($items as $item) { $nids[] = $item['target_id']; } } } foreach ($query->where as &$conditions) { if (is_array($conditions)) { foreach ($conditions['conditions'] as &$condition) { if ($condition['field'] == 'node.nid') { $condition['value'] += $nids; } } } } } } *P.S. Sorry, the comment filter filters out > and & symbols for code blocks.* It's far from ideal, but it's the best way if you don't want to rewrite the Course Catalogue view. If you have several restricted classes, I would add a custom field to the Class content type (like *Make class restricted*), do an [EntityQuery](https://drupal.org/node/1343708) to fetch the classes and apply the above logic, but with an additional `for()` loop to iterate over the classes. Let me know if this is all gibberish to you :-). I'll explain in more details.