Process the action.

@param Action               $action      The action being handled.
@param EnvironmentInterface $environment Current dc-general environment.

@return string
166106
protected function process(Action $action, EnvironmentInterface $environment)
    {
        // Edit only mode, forward to edit action.
        if ($environment->getDataDefinition()->getBasicDefinition()->isEditOnlyMode()) {
            return $this->callAction($environment, 'edit', $action->getArguments());
        }

        $grouping = ViewHelpers::getGroupingMode($environment);

        Message::reset();

        // Process now.
        $collection = $this->loadCollection($environment);
        $this->handleEditAllButton($collection, $environment);
        $this->renderCollection($environment, $collection, $grouping);

        $template = $this->determineTemplate($grouping)
            ->set('collection', $collection)
            ->set('mode', ($grouping ? $grouping['mode'] : null))
            ->set('theme', Backend::getTheme());
        $this->renderTemplate($template, $environment);

        $clipboard = new ViewEvent($environment, $action, DcGeneralViews::CLIPBOARD, []);
        $environment->getEventDispatcher()->dispatch(DcGeneralEvents::VIEW, $clipboard);

        return \implode(
            "\n",
            [
                'language'  => $this->languageSwitcher($environment),
                'panel'     => $this->panel($environment),
                'buttons'   => $this->generateHeaderButtons($environment),
                'clipboard' => $clipboard->getResponse(),
                'body'      => $template->parse()
            ]
        );
    }
1356157
private function getOperation(Action $action, EnvironmentInterface $environment)
    {
        /** @var Contao2BackendViewDefinitionInterface $definition */
        $definition = $environment->getDataDefinition()->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $name       = $action->getName();
        $commands   = $definition->getModelCommands();

        if (!$commands->hasCommandNamed($name)) {
            return null;
        }

        return $commands->getCommandNamed($name);
    }
636858
protected function getCollectionFromSession(Action $action, EnvironmentInterface $environment)
    {
        $inputProvider  = $environment->getInputProvider();
        $sessionStorage = $environment->getSessionStorage();
        $dataDefinition = $environment->getDataDefinition();
        $dataProvider   = $environment->getDataProvider($dataDefinition->getName());

        $addEditProperties =
            $inputProvider->hasValue('FORM_INPUTS')
            && ($dataDefinition->getName() === $inputProvider->getValue('FORM_SUBMIT'));

        $session = $this->getSession($action, $environment);

        $editProperties = [];

        $modelIds = [];
        foreach ($session['models'] as $modelId) {
            $modelIds[] = ModelId::fromSerialized($modelId)->getId();

            if ($addEditProperties) {
                $modelEditProperties = $inputProvider->getValue(\str_replace('::', '____', $modelId) . '_', true);
                $inputProvider->unsetValue(\str_replace('::', '____', $modelId) . '_');

                $editProperties[$modelId] = $modelEditProperties;
            }
        }

        $idProperty = \method_exists($dataProvider, 'getIdProperty') ? $dataProvider->getIdProperty() : 'id';
        $collection = $dataProvider->fetchAll(
            $dataProvider->getEmptyConfig()->setFilter(
                [['operation' => 'IN', 'property' => $idProperty, 'values' => $modelIds]]
            )
        );

        $session['editProperties'] = $editProperties;

        $sessionStorage->set($dataDefinition->getName() . '.' . $this->getMode($action), $session);

        return $collection;
    }
362890
public function load(Action $action)
    {
        if ($action instanceof LoggerAwareInterface) {
            $action->setLogger(
                $this->getServiceLocator()->get(LoggerService::SERVICE_ID)
                    ->addLogger(
                        $this->hideColors
                            ? new VerboseLogger($this->getMinimumLogLevel())
                            : new ColoredVerboseLogger($this->getMinimumLogLevel())
                    )
            );
        }
    }
1160156
protected function formatAction($action)
    {
        if ($this->rootNamespace && ! (strpos($action, '\\') === 0)) {
            return $this->rootNamespace.'\\'.$action;
        } else {
            return trim($action, '\\');
        }
    }
95951
public function handleEvent(ActionEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $environment = $event->getEnvironment();

        if (null === ($serializedId = $this->getModelId($environment))) {
            return;
        }

        $operation = $this->getOperation($event->getAction(), $environment);
        if (!($operation instanceof ToggleCommandInterface)) {
            return;
        }

        if (false === $this->checkPermission($event)) {
            $event->stopPropagation();

            return;
        }

        $this->process($environment, $operation, $serializedId);
    }
1119180
protected function process(EnvironmentInterface $environment)
    {
        $modelId = ModelId::fromSerialized($environment->getInputProvider()->getParameter('source'));

        $dataDefinition = $environment->getDataDefinition();
        $this->guardValidEnvironment($dataDefinition, $modelId);
        // We want a redirect here if not creatable.
        $this->guardIsCreatable($environment, $modelId, true);

        if ($dataDefinition->getBasicDefinition()->isEditOnlyMode()) {
            return $this->callAction($environment, 'edit');
        }

        // Manual sorting mode. The ClipboardController should pick it up.
        $manualSortingProperty = ViewHelpers::getManualSortingProperty($environment);
        if ($manualSortingProperty && $environment->getDataProvider()->fieldExists($manualSortingProperty)) {
            return false;
        }

        $copiedModel = $this->copy($environment, $modelId);

        // If edit several don´t redirect do home.
        if ('select' === $environment->getInputProvider()->getParameter('act')) {
            return false;
        }

        $this->redirect($environment, ModelId::fromModel($copiedModel));

        return null;
    }
315845
public function patch(
        EnvironmentInterface $environment
    ) {
        $this->copyDirectory(
            $environment->getDefaultsFilesystem(),
            $environment->getIdeConfigFilesystem(),
            'inspectionProfiles'
        );

        $this->setProjectProfiles($environment);
    }
1009773
public static function init($locale, $environment, $version)
    {
        $envFilename = Registry::get('applicationPath') . '/.env';
        if (file_exists($envFilename)) {
            $env = Ini::parse($envFilename, true, $locale . '-' . $environment . '-' . $version, 'common', false);
            $env = self::mergeEnvVariables($env);
        } else {
            $env = new \StdClass();
        }
        self::$data = Ini::bindArrayToObject($env);
    }
135261
public function handleAction($request, $action)
    {
        $handles = parent::allowedActions(false);
        $defaultMapping = $this->stat('allowed_actions');
        $handles['index'] = 'handleIndex';
        $siteConfig = SiteConfig::current_site_config();
        foreach ($defaultMapping as $key) {
            $map = ucfirst($key . 'Action');
            if ($siteConfig->$map) {
                $handles[$siteConfig->$map] = $key;
            }
            if (!array_key_exists($key, $handles)) {
                $handles[$key] = $key;
            }
        }
        self::$url_handlers = $handles;
        $this->needsRedirect();

        return parent::handleAction($request, $handles[$action]);
    }
282754
protected function processAction($action, FormInterface $form = null, $statusCode = Response::HTTP_NO_CONTENT)
    {
        $statusCode = $this->getParameterResolver()->resolveStatusCode($statusCode);

        $this->getRestEventDispatcher()->dispatch(
            RestEvents::ACTION,
            $event = new ActionEvent($this->resource, $action, $form, $statusCode)
        );

        $view = $event->getView();
        $statusCode = $view->getStatusCode();

        return $statusCode >= 300 && $statusCode < 400
            ? $this->handleView($view)
            : $this->processView($action, $view);
    }
799731
private function getModelIds(EnvironmentInterface $environment, Action $action, $submitAction)
    {
        $valueKey = \in_array($submitAction, ['edit', 'override']) ? 'properties' : 'models';
        $modelIds = (array) $environment->getInputProvider()->getValue($valueKey);

        if (!empty($modelIds)) {
            $modelIds = \array_map(
                function ($modelId) {
                    return ModelId::fromSerialized($modelId);
                },
                $modelIds
            );

            $event = new PrepareMultipleModelsActionEvent($environment, $action, $modelIds, $submitAction);
            $environment->getEventDispatcher()->dispatch($event::NAME, $event);

            $modelIds = $event->getModelIds();
        }

        return $modelIds;
    }
1133298
public static function redirectHome(EnvironmentInterface $environment)
    {
        $input = $environment->getInputProvider();

        if ($input->hasParameter('table') && ($hasParentId = $input->hasParameter('pid'))) {
            if ($hasParentId) {
                $event = new RedirectEvent(
                    \sprintf(
                        'contao?do=%s&table=%s&pid=%s',
                        $input->getParameter('do'),
                        $input->getParameter('table'),
                        $input->getParameter('pid')
                    )
                );
            } else {
                $event = new RedirectEvent(
                    \sprintf(
                        'contao?do=%s&table=%s',
                        $input->getParameter('do'),
                        $input->getParameter('table')
                    )
                );
            }
        } else {
            $event = new RedirectEvent(
                \sprintf(
                    'contao?do=%s',
                    $input->getParameter('do')
                )
            );
        }

        $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $event);
    }
1277118
protected function runAction($action)
    {
        $dir = getcwd();
        chdir($this->getVendorDir());
        foreach ($this->managers as $m) {
            if ($m->hasDependencies()) {
                $m->runAction($action);
            }
        }
        chdir($dir);
    }
1320390
protected function isAddingAllowed(EnvironmentInterface $environment)
    {
        $inputProvider = $environment->getInputProvider();

        // No manual sorting property defined, no need to add it to the clipboard.
        // Or we already have an after or into attribute, a handler can pick it up.
        return (!ViewHelpers::getManualSortingProperty($environment)
                || $inputProvider->hasParameter('after')
                || $inputProvider->hasParameter('into')
        );
    }
979411
protected function renderPasteTopButton(EnvironmentInterface $environment, $sorting)
    {
        $definition     = $environment->getDataDefinition();
        $dispatcher     = $environment->getEventDispatcher();
        $languageDomain = 'contao_' . $definition->getName();

        $filter = new Filter();
        $filter->andModelIsFromProvider($definition->getBasicDefinition()->getDataProvider());

        if (!$sorting || $environment->getClipboard()->isEmpty($filter)) {
            return null;
        }
        if (!ViewHelpers::getManualSortingProperty($environment)) {
            return null;
        }

        /** @var AddToUrlEvent $urlEvent */
        $urlEvent = $dispatcher->dispatch(
            ContaoEvents::BACKEND_ADD_TO_URL,
            new AddToUrlEvent(
                'act=paste&after=' . ModelId::fromValues($definition->getName(), '0')->getSerialized()
            )
        );

        /** @var GenerateHtmlEvent $imageEvent */
        $imageEvent = $dispatcher->dispatch(
            ContaoEvents::IMAGE_GET_HTML,
            new GenerateHtmlEvent(
                'pasteafter.svg',
                $this->translate('pasteafter.0', $languageDomain),
                'class="blink"'
            )
        );

        return \sprintf(
            '<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>',
            $urlEvent->getUrl(),
            StringUtil::specialchars($this->translate('pasteafter.0', $languageDomain)),
            $imageEvent->getHtml()
        );
    }
863483
protected function executePhpAction(Config\Action $action) : void
    {
        $this->beforeAction();
        $runner = new Action\PHP();
        $runner->execute($this->config, $this->io, $this->repository, $action);
        $this->afterAction();
    }