Get the edit properties by model id.

@param Action               $action      The action.
@param ModelIdInterface     $modelId     The model id.
@param EnvironmentInterface $environment The environment.

@return array
973630
protected function getEditPropertiesByModelId(
        Action $action,
        ModelIdInterface $modelId,
        EnvironmentInterface $environment
    ) {
        $session = $this->getSession($action, $environment);

        return $session['editProperties'][$modelId->getSerialized()];
    }
803888
private function setIntersectProperties(CollectionInterface $collection, EnvironmentInterface $environment)
    {
        $sessionStorage = $environment->getSessionStorage();
        $dataDefinition = $environment->getDataDefinition();

        $session =
            $sessionStorage->get($dataDefinition->getName() . '.' . $this->getSubmitAction($environment, true));

        $session['intersectProperties'] = $this->collectIntersectModelProperties($collection, $environment);
        $sessionStorage->set($dataDefinition->getName() . '.' . $this->getSubmitAction($environment, true), $session);
    }
722069
private function process(Action $action, EnvironmentInterface $environment)
    {
        $inputProvider = $environment->getInputProvider();

        return $this->callAction(
            $environment,
            'showAll',
            \array_merge(
                $action->getArguments(),
                [
                    'mode' => $inputProvider->getParameter('mode'),
                    'select' => $inputProvider->getParameter('select')
                ]
            )
        );
    }
289153
private function updateCounter(ModelEvent $event, $action)
    {
        if (!$this->constraint->isVersioningService()) {
            return;
        }

        $qb = $this->documentManager->createQueryBuilder($event->getCollectionClass());
        if ('update' == $action) {
            $qb->findAndUpdate()
                ->field('id')->equals($event->getCollectionId())
                ->field(VersionServiceConstraint::FIELD_NAME)->inc(1)
                ->getQuery()->execute();
        } else {
            $qb->findAndUpdate()
                ->field('id')->equals($event->getCollectionId())
                ->field(VersionServiceConstraint::FIELD_NAME)->set(1)
                ->getQuery()->execute();
        }
    }
1190583
protected function process(EnvironmentInterface $environment)
    {
        $inputProvider = $environment->getInputProvider();
        $modelId       = ModelId::fromSerialized($inputProvider->getParameter('id'));
        $dataProvider  = $environment->getDataProvider($modelId->getDataProviderName());

        $view = $environment->getView();
        if (!$view instanceof BaseView) {
            return false;
        }

        $this->checkRestoreVersion($environment, $modelId);

        if (!($model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId())))) {
            throw new DcGeneralRuntimeException('Could not retrieve model with id ' . $modelId->getSerialized());
        }

        $clone = clone $model;
        $clone->setId($model->getId());

        if ('select' !== $inputProvider->getParameter('act')) {
            $this->handleGlobalCommands($environment);
        }

        return (new EditMask($view, $model, $clone, null, null, $view->breadcrumb()))->execute();
    }
386505
public function getViewParameters(
        Action $action,
        FormInterface $form = null,
        $data = null,
        array $listRouteParameters = []
    ): array {
        $parameters = [
            'listPath' => $this->routingHelper->getAdminListPath($action->getAdmin(), $listRouteParameters),
            'admin' => $action->getAdmin(),
        ];

        if ($form) {
            $parameters['form'] = $form->createView();
        }
        if ($data) {
            $parameters['data'] = $data;
        }

        return $parameters;
    }
866054
private function getActiveModel(ModelIdInterface $modelId)
    {
        if (!Database::getInstance()->tableExists($modelId->getDataProviderName())) {
            return null;
        }
        $dataProvider = $this->itemContainer->getEnvironment()->getDataProvider();

        return $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
    }
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;
    }
1305448
public static function log(Model $model, $action, Admin $admin = null)
    {
        // Create a new change instance
        if (static::shouldWriteChange($model, $action)) {
            $changed = static::getChanged($model, $action);
            $change = static::createLog($model, $action, $admin, $changed);
        }

        // Log published / unpblished changes
        static::logPublishingChange($model, $action, $admin);

        // If the action was a deletion, mark all of the records for this model as
        // deleted
        if ($action == 'deleted') {
            DB::table('changes')
                ->where('model', get_class($model))
                ->where('key', $model->getKey())
                ->update(['deleted' => 1]);
        }

        // Return the changed instance
        if (isset($change)) {
            return $change;
        }
    }
930126
public function getModelVersionById($modelId, $versionId)
    {
        $modelResult = $this->getRequest()->request(
            'GET',
            $this->getRequestUrl(sprintf('models/%s/versions/%s', $modelId, $versionId))
        );

        if (isset($modelResult['model_version'])) {
            $modelVersion = new ModelVersion($modelResult['model_version']);
        } else {
            throw new \Exception('Model Versions Not Found');
        }

        return $modelVersion;
    }
1316761
public function getDefaultFormOptions(
        Action $action,
        Request $request,
        DataInterface $data
    ): array {
        $formOptions = $this->baseFormHelper->getDefaultFormOptions($action, $request, $data->getId());
        $formOptions['family'] = $data->getFamily();
        $formOptions['label'] = $this->tryTranslate(
            [
                "admin.family.{$data->getFamilyCode()}.{$action->getCode()}.title",
                "admin.{$action->getAdmin()->getCode()}.{$action->getCode()}.title",
                "admin.action.{$action->getCode()}.title",
            ],
            [],
            ucfirst($action->getCode())
        );

        return array_merge($formOptions, $data->getFamily()->getFormOptions());
    }
1185044
private function prepareFileSelector(ModelIdInterface $modelId, Ajax $ajax = null)
    {
        $inputProvider = $this->itemContainer->getEnvironment()->getInputProvider();
        $propertyName  = $inputProvider->getParameter('field');
        $information   = (array) $GLOBALS['TL_DCA'][$modelId->getDataProviderName()]['fields'][$propertyName];

        if (!isset($information['eval'])) {
            $information['eval'] = [];
        }

        // Merge with the information from the data container.
        $property = $this
            ->itemContainer
            ->getEnvironment()
            ->getDataDefinition()
            ->getPropertiesDefinition()
            ->getProperty($propertyName);
        $extra    = $property->getExtra();

        $information['eval'] = \array_merge($extra, (array) $information['eval']);

        $this->session->set('filePickerRef', Environment::get('request'));

        $combat = new DcCompat($this->itemContainer->getEnvironment(), $this->getActiveModel($modelId), $propertyName);

        /** @var FileSelector $fileSelector */
        $fileSelector = new $GLOBALS['BE_FFL']['fileSelector'](
            Widget::getAttributesFromDca(
                $information,
                $propertyName,
                $this->prepareValuesForFileSelector($propertyName, $modelId, $combat),
                $propertyName,
                $modelId->getDataProviderName(),
                $combat
            ),
            $combat
        );

        // AJAX request.
        if ($ajax) {
            $ajax->executePostActions($combat);
        }

        return $fileSelector;
    }
1108951
private function getActionsFromSource(ModelIdInterface $source, ModelIdInterface $parentModelId = null)
    {
        $basicDefinition = $this->getEnvironment()->getDataDefinition()->getBasicDefinition();

        $filter = new Filter();
        $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
        if ($basicDefinition->getParentDataProvider()) {
            $filter->andParentIsFromProvider($basicDefinition->getParentDataProvider());
        } else {
            $filter->andHasNoParent();
        }
        $filter->andModelIs($source);
        $item = $this->getEnvironment()->getClipboard()->fetch($filter)[0];

        $action  = $item ? $item->getAction() : ItemInterface::CUT;
        $model   = $this->modelCollector->getModel($source);
        $actions = [
            [
                'model' => $model,
                'item'  => new Item($action, $parentModelId, ModelId::fromModel($model))
            ]
        ];

        return $actions;
    }
727589
private function getTableHead(EnvironmentInterface $environment)
    {
        $tableHead  = [];
        $definition = $environment->getDataDefinition();
        $properties = $definition->getPropertiesDefinition();
        $formatter  = $this->getViewSection($definition)->getListingConfig()->getLabelFormatter($definition->getName());
        $sorting    = ViewHelpers::getCurrentSorting($environment);
        $columns    = $this->getSortingColumns($sorting);
        foreach ($formatter->getPropertyNames() as $field) {
            // Skip unknown properties. This may happen if the property is not defined for editing but only listing.
            if (!$properties->hasProperty($field)) {
                continue;
            }

            $tableHead[] = [
                'class'   => 'tl_folder_tlist col_' . $field . (\in_array($field, $columns) ? ' ordered_by' : ''),
                'content' => $properties->getProperty($field)->getLabel()
            ];
        }

        $tableHead[] = [
            'class'   => 'tl_folder_tlist tl_right_nowrap',
            'content' => $this->renderPasteTopButton($environment, $sorting) ?: '&nbsp;'
        ];

        return $tableHead;
    }
115667
protected function getModel(EnvironmentInterface $environment)
    {
        $modelId      = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'));
        $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        if ($model) {
            return $model;
        }

        $eventDispatcher = $environment->getEventDispatcher();

        $eventDispatcher->dispatch(
            ContaoEvents::SYSTEM_LOG,
            new LogEvent(
                \sprintf(
                    'Could not find ID %s in %s. DC_General show()',
                    $modelId->getId(),
                    $environment->getDataDefinition()->getName()
                ),
                __CLASS__ . '::' . __FUNCTION__,
                TL_ERROR
            )
        );

        $eventDispatcher->dispatch(
            ContaoEvents::CONTROLLER_REDIRECT,
            new RedirectEvent('contao?act=error')
        );

        return null;
    }
571042
private function valueToWidget(ModelInterface $model, PropertyInterface $property)
    {
        $environment = $this->getEnvironment();

        $event = new DecodePropertyValueForWidgetEvent($environment, $model);
        $event
            ->setProperty($property->getName())
            ->setValue($model->getProperty($property->getName()));

        $environment->getEventDispatcher()->dispatch($event::NAME, $event);
        $value = $event->getValue();

        $propExtra = $property->getExtra();

        if ((0 === (int) $value)
            && \is_numeric($value)
            && empty($propExtra['mandatory'])
            && (isset($propExtra['rgxp']) && \in_array($propExtra['rgxp'], ['date', 'time', 'datim']))
        ) {
            $value = '';
        }

        return $value;
    }
429650
static private function shouldWriteChange(Model $model, $action)
    {
        if (in_array($action, ['created', 'deleted'])) return true;
        $changed_attributes = array_keys($model->getDirty());
        $ignored = ['updated_at', 'public'];
        $loggable = array_diff($changed_attributes, $ignored);
        return count($loggable) > 0;
    }