public function onLoadCallback(DataContainer $dc): void
    {
        if (!($dc instanceof Driver)) {
            return;
        }

        $ids = [];

        // Collect the top tags from all registries
        foreach ($this->registry->getAliases() as $alias) {
            $manager = $this->registry->get($alias);

            if ($manager instanceof DefaultManager) {
                foreach ($manager->getTopTagIds([], null, true) as $id => $count) {
                    $ids[$id] = $count;
                }
            }
        }

        // Append all other tags
        foreach ($this->db->executeQuery("SELECT id FROM {$dc->table}")->fetchAll(\PDO::FETCH_COLUMN, 0) as $id) {
            if (!\array_key_exists($id, $ids)) {
                $ids[$id] = 0;
            }
        }

        /** @var AttributeBagInterface $bag */
        $bag = $this->session->getBag('contao_backend');
        $session = $bag->all();

        // Handle the sorting selection
        switch ($session['sorting'][$dc->table]) {
            case 'total_asc':
                \asort($ids);
                break;
            case 'total_desc':
                \arsort($ids);
                break;
            default:
                $session['sorting'][$dc->table] = null;
                $bag->replace($session);

                return;
        }

        /** @var Database $db */
        $db = $this->framework->createInstance(Database::class);
        $dc->setOrderBy([$db->findInSet('id', \array_keys($ids))]);

        // Prevent adding an extra column to the listing
        $dc->setFirstOrderBy('name');
    }