Remove Moderated content tab

Created on 6 March 2021, about 4 years ago
Updated 24 February 2023, about 2 years ago

If I disable or delete the Moderated content view under for /admin/content/moderated the tab persists there.

How can it be removed?

💬 Support request
Status

Closed: outdated

Version

9.4

Component
Content moderation 

Last updated 14 days ago

Created by

🇩🇪Germany demonde

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇷Greece dspachos

    Hi, you need to implement a custom hook, something like that:

    /**
     * Implements hook_menu_local_tasks_alter()
     */
    function MYMODULE_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) {
      if ($route_name == 'system.admin_content') {
        unset($data['tabs'][1]['content_moderation.content']);
      }
    }
    
    
  • 🇨🇦Canada fengtan Montreal, Canada

    I ran into this as well.

    This is because the path /admin/content/moderated is served by both:

    So, if you disable the view, then /admin/content/moderated will not go away and will be served by the controller instead. It looks like there is no way to remove /admin/content/moderated unless you disable the route altogether (as shown by #5 above).

  • 🇨🇦Canada fengtan Montreal, Canada

    Here is how I removed the "Moderated content" tab. This will always deny access to /admin/content/moderated (assuming the view content_moderated has also been disabled).

    // web/modules/custom/mymodule/src/Routing/MyModuleRouteSubscriber.php
    
    namespace Drupal\mymodule\Routing;
    
    use Drupal\Core\Routing\RouteSubscriberBase;
    use Symfony\Component\Routing\RouteCollection;
    
    class MyModuleRouteSubscriber extends RouteSubscriberBase {
    
      /**
       * {@inheritdoc}
       */
      protected function alterRoutes(RouteCollection $collection) {
        // Always deny access to /admin/content/moderated (assuming view 'content_moderated' has been disabled).
        if ($route = $collection->get('content_moderation.admin_moderated_content')) {
          // Second parameter must be a string, see https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones#s-altering-existing-routes
          $route->setRequirement('_access', 'FALSE');
        }
      }
    
    }
    
    
Production build 0.71.5 2024