src/CoreBundle/Contao/Hooks/FixupUserGroupModules.php
public function fixupModules(DataContainer $dataContainer)
    {
        if (!class_exists('tl_user_group', false)) {
            throw new \RuntimeException('data container is not loaded!');
        }

        $original = new \tl_user_group();
        $modules  = $original->getModules();

        // 1. remove all MetaModels
        foreach (array_keys($modules) as $group) {
            foreach ($modules[$group] as $key => $module) {
                if (strpos($module, 'metamodel_') === 0) {
                    unset($modules[$group][$key]);
                }
            }
            // Otherwise we end up with an associative array.
            $modules[$group] = array_values($modules[$group]);
        }

        // 2. Add our "custom" modules and remove the main module.
        $modules['metamodels'][] = 'support_metamodels';
        if (false !== $index = array_search('metamodels', $modules['metamodels'], true)) {
            unset($modules['metamodels'][$index]);
            $modules['metamodels'] = array_values($modules['metamodels']);
        }

        // 3. Add back all MetaModels for the current group.
        $combinations = $this->combinationBuilder->getCombinationsForUser([$dataContainer->activeRecord->id], 'be');

        $screenIds = array_map(function ($combination) {
            return $combination['dca_id'];
        }, $combinations['byName']);

        $screens = $this->inputScreens->fetchInputScreens($screenIds);

        $locale = $this->requestStack->getCurrentRequest()->getLocale();
        foreach ($screens as $metaModel => $screen) {
            if ('standalone' === $screen['meta']['rendertype']) {
                $modules[$screen['meta']['backendsection']][] = 'metamodel_' . $metaModel;
                $this->buildLanguageString('metamodel_' . $metaModel, $screen, $locale);
            }
        }

        return $modules;
    }
public function fixupModules(DataContainer $dataContainer)
    {
        if (!class_exists('tl_user_group', false)) {
            throw new \RuntimeException('data container is not loaded!');
        }

        $original = new \tl_user_group();
        $modules  = $original->getModules();

        // 1. remove all MetaModels
        foreach (array_keys($modules) as $group) {
            foreach ($modules[$group] as $key => $module) {
                if (strpos($module, 'metamodel_') === 0) {
                    unset($modules[$group][$key]);
                }
            }
            // Otherwise we end up with an associative array.
            $modules[$group] = array_values($modules[$group]);
        }

        // 2. Add our "custom" modules and remove the main module.
        $modules['metamodels'][] = 'support_metamodels';
        if (false !== $index = array_search('metamodels', $modules['metamodels'], true)) {
            unset($modules['metamodels'][$index]);
            $modules['metamodels'] = array_values($modules['metamodels']);
        }

        // 3. Add back all MetaModels for the current group.
        $combinations = $this->combinationBuilder->getCombinationsForUser([$dataContainer->activeRecord->id], 'be');

        $screenIds = array_map(function ($combination) {
            return $combination['dca_id'];
        }, $combinations['byName']);

        $screens = $this->inputScreens->fetchInputScreens($screenIds);

        $locale = $this->requestStack->getCurrentRequest()->getLocale();
        foreach ($screens as $metaModel => $screen) {
            if ('standalone' === $screen['meta']['rendertype']) {
                $modules[$screen['meta']['backendsection']][] = 'metamodel_' . $metaModel;
                $this->buildLanguageString('metamodel_' . $metaModel, $screen, $locale);
            }
        }

        return $modules;
    }
Fix up the modules in the backend.

@param DataContainer $dataContainer The current data container.

@return array

@throws \RuntimeException When the "parenting" class can not be found.