Get legend property names.

@param ModelInterface        $intersectModel The intersect model.
@param EnvironmentInterface  $environment    The environment.
@param PaletteInterface|null $defaultPalette The default palette.

@return array
773164
private function getLegendPropertyNames(
        ModelInterface $intersectModel,
        EnvironmentInterface $environment,
        PaletteInterface &$defaultPalette = null
    ) {
        $inputProvider      = $environment->getInputProvider();
        $palettesDefinition = $environment->getDataDefinition()->getPalettesDefinition();

        $legendPropertyNames = [];
        if ($inputProvider->hasValue('FORM_INPUTS') && (1 === \count($palettesDefinition->getPalettes()))) {
            return $legendPropertyNames;
        }

        $defaultPalette = $palettesDefinition->findPalette($intersectModel);
        foreach ($defaultPalette->getProperties($intersectModel) as $paletteProperty) {
            $legendPropertyNames[] = $paletteProperty->getName();
        }

        return $legendPropertyNames;
    }
1084532
private function renderParentProperty(EnvironmentInterface $environment, $property, $value)
    {
        $evaluation = $property->getExtra();

        if (\is_array($value)) {
            return \implode(', ', $value);
        }

        $isRendered = false;

        $value = $this->renderForCheckbox($property, $value, $isRendered);
        $value = $this->renderForDateTime($environment, $property, $value, $isRendered);
        $value = $this->renderReference($value, $evaluation['reference'], $isRendered);

        $options = $property->getOptions();
        if ($evaluation['isAssociative'] || \array_is_assoc($options)) {
            $value = $options[$value];
        }

        return $value;
    }
649353
private function getModelId(EnvironmentInterface $environment)
    {
        $inputProvider = $environment->getInputProvider();

        if ($inputProvider->hasParameter('id') && $inputProvider->getParameter('id')) {
            $modelId = ModelId::fromSerialized($inputProvider->getParameter('id'));
        }

        if (!(isset($modelId)
              && ($environment->getDataDefinition()->getName() === $modelId->getDataProviderName()))
        ) {
            return null;
        }

        return $modelId;
    }
1140376
private function renderHeaderFields($parentModel, EnvironmentInterface $environment)
    {
        $definition = $environment->getDataDefinition();
        $parentName = $definition->getBasicDefinition()->getParentDataProvider();
        $add        = [];
        $properties = $environment->getParentDataDefinition()->getPropertiesDefinition();
        foreach ($this->getViewSection($definition)->getListingConfig()->getHeaderPropertyNames() as $field) {
            $value = StringUtil::deserialize($parentModel->getProperty($field));

            if ('tstamp' === $field) {
                $value = date(Config::get('datimFormat'), $value);
            } else {
                $value = $this->renderParentProperty($environment, $properties->getProperty($field), $value);
            }

            // Add the field.
            if ('' !== $value) {
                $add[$this->translateHeaderColumnName($field, $parentName)] = $value;
            }
        }

        $event = new GetParentHeaderEvent($environment, $parentModel);
        $event->setAdditional($add);

        $environment->getEventDispatcher()->dispatch(GetParentHeaderEvent::NAME, $event);

        if (null !== !$event->getAdditional()) {
            $add = $event->getAdditional();
        }

        return \array_map(
            function ($value) {
                if (\is_array($value)) {
                    return $value[0];
                }
                return $value;
            },
            $add
        );
    }
523382
public function getIconSetIconsByType(IconSet $iconSet = null, $includeDefault = true)
    {
        $iconSetIconsList = new ResourceIconSetIconItemList();
        if (null !== $iconSet) {
            $iconSetIcons = $iconSet->getIcons()->toArray();
            $iconSetIconsList->addSetIcons($iconSetIcons);
        }
        if ($includeDefault) {
            $defaultSetIcons = $this->iconItemRepo->findIconsForResourceIconSetByMimeTypes(
                null,
                $iconSetIconsList->getSetIcons()->getMimeTypes()
            );
            $iconSetIconsList->addDefaultIcons($defaultSetIcons);
        }

        return $iconSetIconsList;
    }
1230064
private function getHydraProperties(string $resourceClass, ResourceMetadata $resourceMetadata, string $shortName, string $prefixedShortName, array $context): array
    {
        $classes = [];
        foreach ($resourceMetadata->getCollectionOperations() as $operationName => $operation) {
            $inputMetadata = $resourceMetadata->getTypedOperationAttribute(OperationType::COLLECTION, $operationName, 'input', ['class' => $resourceClass], true);
            if (null !== $inputClass = $inputMetadata['class'] ?? null) {
                $classes[$inputClass] = true;
            }

            $outputMetadata = $resourceMetadata->getTypedOperationAttribute(OperationType::COLLECTION, $operationName, 'output', ['class' => $resourceClass], true);
            if (null !== $outputClass = $outputMetadata['class'] ?? null) {
                $classes[$outputClass] = true;
            }
        }

        $properties = [];
        foreach ($classes as $class => $v) {
            foreach ($this->propertyNameCollectionFactory->create($class, $this->getPropertyNameCollectionFactoryContext($resourceMetadata)) as $propertyName) {
                $propertyMetadata = $this->propertyMetadataFactory->create($class, $propertyName);
                if (true === $propertyMetadata->isIdentifier() && false === $propertyMetadata->isWritable()) {
                    continue;
                }

                if ($this->nameConverter) {
                    $propertyName = $this->nameConverter->normalize($propertyName, $class, self::FORMAT, $context);
                }

                $properties[] = $this->getProperty($propertyMetadata, $propertyName, $prefixedShortName, $shortName);
            }
        }

        return $properties;
    }
454196
private function excludePaletteSelectorProperty(
        Action $action,
        PropertyInterface $property,
        EnvironmentInterface $environment
    ) {
        $palettesDefinition = $environment->getDataDefinition()->getPalettesDefinition();

        if (1 === \count($palettesDefinition->getPalettes())) {
            return false;
        }

        return $this->analyzeExcludeProperty($action, $environment, $property, $palettesDefinition);
    }
716586
public function getMatchCount(ModelInterface $model = null, PropertyValueBag $input = null)
    {
        $totalCount = false;

        foreach ($this->conditions as $condition) {
            if (!($condition instanceof PaletteConditionInterface)) {
                throw new DcGeneralRuntimeException('Invalid condition in chain: ' . \get_class($condition));
            }

            $conditionCount = $condition->getMatchCount($model, $input);

            if (false !== $conditionCount) {
                $totalCount += $conditionCount;
            } elseif (static::AND_CONJUNCTION === $this->conjunction) {
                return false;
            }
        }

        return $totalCount;
    }
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;
    }
973630
protected function getEditPropertiesByModelId(
        Action $action,
        ModelIdInterface $modelId,
        EnvironmentInterface $environment
    ) {
        $session = $this->getSession($action, $environment);

        return $session['editProperties'][$modelId->getSerialized()];
    }
760097
public static function getModelColumns(string $model = '', string $connectionManager = 'default'): array
    {
        $result = $columns = [];

        if (empty($model)) {
            return $result;
        }

        // making sure that model is in table naming conventions.
        $model = Inflector::tableize($model);

        try {
            $connection = ConnectionManager::get($connectionManager);
            $schema = $connection->getSchemaCollection();
            $table = $schema->describe($model);
            $columns = $table->columns();
        } catch (MissingDatasourceConfigException $e) {
            return $result;
        } catch (Exception $e) {
            return $result;
        }

        // A table with no columns?
        if (empty($columns)) {
            return $result;
        }

        foreach ($columns as $column) {
            $result[$column] = $column;
        }

        return $result;
    }
316419
protected function fetchModel(EnvironmentInterface $environment, ModelIdInterface $modelId)
    {
        $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        if (!$model || !$model->getId()) {
            throw new DcGeneralRuntimeException(
                'Could not load model with id ' . $modelId->getSerialized()
            );
        }

        return $model;
    }
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();
    }
222043
private function initIndices(SearchableInterface $searchableModel)
    {
        $indexNames = $searchableModel->getIndices();

        return \array_map(function ($indexName) {
            if ($this->env !== null) {
                $indexName = $this->env . '_' . $indexName;
            }

            return $this->initIndex($indexName);
        }, $indexNames);
    }
809304
public function match(
        ModelInterface $model = null,
        PropertyValueBag $input = null,
        PropertyInterface $property = null,
        LegendInterface $legend = null
    ) {
        if (static::AND_CONJUNCTION === $this->conjunction) {
            foreach ($this->conditions as $condition) {
                if (!($condition instanceof PropertyConditionInterface)) {
                    throw new DcGeneralRuntimeException('Invalid condition in chain: ' . \get_class($condition));
                }

                if (!$condition->match($model, $input, $property, $legend)) {
                    return false;
                }
            }

            return true;
        }

        foreach ($this->conditions as $condition) {
            if (!($condition instanceof PropertyConditionInterface)) {
                throw new DcGeneralRuntimeException('Invalid condition in chain: ' . \get_class($condition));
            }

            if ($condition->match($model, $input, $property, $legend)) {
                return true;
            }
        }

        return false;
    }
414351
private function getPropertyDataProvider(EnvironmentInterface $environment)
    {
        $providerName = 'property.' . $environment->getDataDefinition()->getName();

        $dataProvider = new NoOpDataProvider();
        $dataProvider->setBaseConfig(['name' => $providerName]);

        $this->setPropertyLabelFormatter($providerName, $environment);

        return $dataProvider;
    }
2726
protected function renderModel(ModelInterface $model, EnvironmentInterface $environment)
    {
        $event = new FormatModelLabelEvent($environment, $model);
        $environment->getEventDispatcher()->dispatch(
            DcGeneralEvents::FORMAT_MODEL_LABEL,
            $event
        );

        $model->setMeta($model::LABEL_VALUE, $event->getLabel());
    }