Skip to content

Commit

Permalink
Fixes language panel
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed Aug 16, 2024
1 parent 3773bc8 commit f6ac44e
Showing 1 changed file with 49 additions and 34 deletions.
83 changes: 49 additions & 34 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace ContaoCommunityAlliance\DcGeneral\Controller;

use Contao\CoreBundle\Intl\Locales;
use Contao\System;
use ContaoCommunityAlliance\DcGeneral\Action;
use ContaoCommunityAlliance\DcGeneral\BaseConfigRegistryInterface;
use ContaoCommunityAlliance\DcGeneral\Clipboard\ClipboardInterface;
Expand Down Expand Up @@ -65,7 +67,16 @@
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException;
use ContaoCommunityAlliance\DcGeneral\Factory\DcGeneralFactory;
use ContaoCommunityAlliance\Translator\TranslatorInterface;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use UnexpectedValueException;

use function array_keys;
use function in_array;
use function is_int;
use function is_string;
use function trigger_error;

/**
* This class serves as main controller class in dc general.
Expand Down Expand Up @@ -145,7 +156,7 @@ public function setEnvironment(EnvironmentInterface $environment)
assert($definition instanceof ContainerInterface);

$mode = $definition->getBasicDefinition()->getMode();
assert(\is_int($mode));
assert(is_int($mode));

$this->relationshipManager = new RelationshipManager(
$definition->getModelRelationshipDefinition(),
Expand Down Expand Up @@ -184,20 +195,20 @@ public function handle(Action $action)
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::searchParentOfIn().
*
* @see ModelCollector::searchParentOfIn
* @see ModelCollector::searchParentOfIn
*/
public function searchParentOfIn(ModelInterface $model, CollectionInterface $models)
{
// @codingStandardsIgnoreStart
@\trigger_error(
@trigger_error(
'Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::searchParentOfIn().',
E_USER_DEPRECATED
);
// @codingStandardsIgnoreEnd

$parent = $this->modelCollector->searchParentOfIn($model, $models);
if (null === $parent) {
throw new \RuntimeException('Not found');
throw new RuntimeException('Not found');
}

return $parent;
Expand All @@ -210,20 +221,20 @@ public function searchParentOfIn(ModelInterface $model, CollectionInterface $mod
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::searchParentOf().
*
* @see ModelCollector::searchParentOf
* @see ModelCollector::searchParentOf
*/
public function searchParentOf(ModelInterface $model)
{
// @codingStandardsIgnoreStart
@\trigger_error(
@trigger_error(
'Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::searchParentOf().',
E_USER_DEPRECATED
);
// @codingStandardsIgnoreEnd

$parent = $this->modelCollector->searchParentOf($model);
if (null === $parent) {
throw new \RuntimeException('Not found');
throw new RuntimeException('Not found');
}

return $parent;
Expand All @@ -234,12 +245,12 @@ public function searchParentOf(ModelInterface $model)
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::collectChildrenOf().
*
* @see ModelCollector::collectChildrenOf
* @see ModelCollector::collectChildrenOf
*/
public function assembleAllChildrenFrom($model, $providerName = '')
{
// @codingStandardsIgnoreStart
@\trigger_error(
@trigger_error(
'Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::collectChildrenOf()',
E_USER_DEPRECATED
);
Expand Down Expand Up @@ -267,7 +278,7 @@ protected function assembleSiblingsFor(
ModelIdInterface $parentId = null
) {
// @codingStandardsIgnoreStart
@\trigger_error(
@trigger_error(
'Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::collectSiblingsOf()',
E_USER_DEPRECATED
);
Expand Down Expand Up @@ -369,12 +380,16 @@ public function getSupportedLanguages($mixID)
assert($translator instanceof TranslatorInterface);

// Make an array from the collection.
$languages = [];
$languages = [];
$intlLocales = System::getContainer()->get('contao.intl.locales');
assert($intlLocales instanceof Locales);
$labels = $intlLocales->getLocales();

foreach ($supportedLanguages as $value) {
/** @var LanguageInformationInterface $value */
$locale = $value->getLocale();

$languages[$locale] = $translator->translate('LNG.' . $locale, 'languages');
$languages[$locale] = $labels[$locale];
}

return $languages;
Expand Down Expand Up @@ -433,7 +448,7 @@ public function createClonedModel($model)
$dataProvider = $environment->getDataProvider($clone->getProviderName());
assert($dataProvider instanceof DataProviderInterface);

foreach (\array_keys($clone->getPropertiesAsArray()) as $propName) {
foreach (array_keys($clone->getPropertiesAsArray()) as $propName) {
// If the property is not known, remove it.
if (!$properties->hasProperty($propName)) {
continue;
Expand All @@ -449,24 +464,24 @@ public function createClonedModel($model)
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException When the model id is invalid.
* @throws InvalidArgumentException When the model id is invalid.
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::getModel().
*
* @see ModelCollector::getModel
* @see ModelCollector::getModel
*/
public function fetchModelFromProvider($modelId, $providerName = null)
{
// @codingStandardsIgnoreStart
@\trigger_error(
@trigger_error(
'Use \ContaoCommunityAlliance\DcGeneral\Controller\ModelCollector::getModel()',
E_USER_DEPRECATED
);
// @codingStandardsIgnoreEnd

$model = $this->modelCollector->getModel($modelId, $providerName);
if (null === $model) {
throw new \RuntimeException('Not found');
throw new RuntimeException('Not found');
}

return $model;
Expand Down Expand Up @@ -553,7 +568,7 @@ public function getModelsFromClipboard(ModelIdInterface $parentModelId = null)

$basicDefinition = $dataDefinition->getBasicDefinition();
$modelProviderName = $basicDefinition->getDataProvider();
assert(\is_string($modelProviderName));
assert(is_string($modelProviderName));

$clipboard = $environment->getClipboard();
assert($clipboard instanceof ClipboardInterface);
Expand Down Expand Up @@ -597,7 +612,7 @@ public function applyClipboardActions(
*
* @return array
*
* @throws \InvalidArgumentException When the model id is invalid.
* @throws InvalidArgumentException When the model id is invalid.
*/
private function getActionsFromSource(ModelIdInterface $source, ModelIdInterface $parentModelId = null)
{
Expand All @@ -608,13 +623,13 @@ private function getActionsFromSource(ModelIdInterface $source, ModelIdInterface
assert($basicDefinition instanceof BasicDefinitionInterface);

$dataProvider = $basicDefinition->getDataProvider();
assert(\is_string($dataProvider));
assert(is_string($dataProvider));

$filter = new Filter();
$filter->andModelIsFromProvider($dataProvider);
if (null !== $basicDefinition->getParentDataProvider()) {
$parentDataProvider = $basicDefinition->getDataProvider();
assert(\is_string($parentDataProvider));
assert(is_string($parentDataProvider));

$filter->andParentIsFromProvider($parentDataProvider);
} else {
Expand Down Expand Up @@ -662,7 +677,7 @@ private function fetchModelsFromClipboard(FilterInterface $filter = null, ModelI
if ($filter instanceof Filter) {
$basicDefinition = $dataDefinition->getBasicDefinition();
$modelProviderName = $basicDefinition->getDataProvider();
assert(\is_string($modelProviderName));
assert(is_string($modelProviderName));
$filter->andModelIsFromProvider($modelProviderName);
if ($parentModelId) {
$filter->andParentIsFromProvider($parentModelId->getDataProviderName());
Expand Down Expand Up @@ -779,7 +794,7 @@ private function applyAction(array &$action, array &$deepCopyList, ModelInterfac
}

if (!$model) {
throw new \UnexpectedValueException(
throw new UnexpectedValueException(
'Invalid clipboard action entry, no model created. ' . $item->getAction()
);
}
Expand Down Expand Up @@ -895,7 +910,7 @@ private function processPasteAfter(CollectionInterface $models, ModelIdInterface
{
if ($after && $models->count() && $after->getId()) {
$manualSorting = ViewHelpers::getManualSortingProperty($this->getEnvironment());
assert(\is_string($manualSorting));
assert(is_string($manualSorting));

$model = $this->modelCollector->getModel($after);
assert($model instanceof ModelInterface);
Expand All @@ -919,7 +934,7 @@ private function processPasteInto(CollectionInterface $models, ModelIdInterface
{
if ($into && $models->count() && $into->getId()) {
$manualSorting = ViewHelpers::getManualSortingProperty($this->getEnvironment());
assert(\is_string($manualSorting));
assert(is_string($manualSorting));

$model = $this->modelCollector->getModel($into);
assert($model instanceof ModelInterface);
Expand Down Expand Up @@ -953,7 +968,7 @@ private function processPasteTopWithoutReference(
|| ($into && (0 === (int) $into->getId())))
) {
$manualSorting = ViewHelpers::getManualSortingProperty($this->getEnvironment());
assert(\is_string($manualSorting));
assert(is_string($manualSorting));

$dataDefinition = $this->getEnvironment()->getDataDefinition();
assert($dataDefinition instanceof ContainerInterface);
Expand Down Expand Up @@ -1183,12 +1198,12 @@ public function pasteTop(CollectionInterface $models, $sortedBy, ModelIdInterfac
/**
* {@inheritDoc}
*
* @throws \RuntimeException When no models have been passed.
* @throws RuntimeException When no models have been passed.
*/
public function pasteAfter(ModelInterface $previousModel, CollectionInterface $models, $sortedBy)
{
if (0 === $models->length()) {
throw new \RuntimeException('No models passed to pasteAfter().');
throw new RuntimeException('No models passed to pasteAfter().');
}

$environment = $this->getEnvironment();
Expand All @@ -1197,7 +1212,7 @@ public function pasteAfter(ModelInterface $previousModel, CollectionInterface $m
assert($definition instanceof ContainerInterface);

if (
\in_array(
in_array(
$definition->getBasicDefinition()->getMode(),
[
BasicDefinitionInterface::MODE_HIERARCHICAL,
Expand All @@ -1209,7 +1224,7 @@ public function pasteAfter(ModelInterface $previousModel, CollectionInterface $m
$parentModel = $this->modelCollector->searchParentOf($previousModel);
assert($parentModel instanceof ModelInterface);

$parentName = $parentModel->getProviderName();
$parentName = $parentModel->getProviderName();
$this->relationshipManager->setSameParentForAll($models, $previousModel, $parentName);
} else {
$this->relationshipManager->setAllRoot($models);
Expand Down Expand Up @@ -1269,7 +1284,7 @@ private function clearModelCollection(CollectionInterface $models)
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::isRoot().
*
* @see \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::isRoot()
* @see RelationshipManager::isRoot
*/
public function isRootModel(ModelInterface $model)
{
Expand All @@ -1281,7 +1296,7 @@ public function isRootModel(ModelInterface $model)
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::setRoot().
*
* @see \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::setRoot()
* @see RelationshipManager::setRoot
*/
public function setRootModel(ModelInterface $model)
{
Expand All @@ -1295,7 +1310,7 @@ public function setRootModel(ModelInterface $model)
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::setParent().
*
* @see \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::setParent()
* @see RelationshipManager::setParent
*/
public function setParent(ModelInterface $childModel, ModelInterface $parentModel)
{
Expand All @@ -1309,7 +1324,7 @@ public function setParent(ModelInterface $childModel, ModelInterface $parentMode
*
* @deprecated Use \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::setSameParent().
*
* @see \ContaoCommunityAlliance\DcGeneral\Controller\RelationshipManager::setSameParent()
* @see RelationshipManager::setSameParent
*/
public function setSameParent(ModelInterface $receivingModel, ModelInterface $sourceModel, $parentTable)
{
Expand Down

0 comments on commit f6ac44e

Please sign in to comment.