diff --git a/composer.json b/composer.json
index 0fd7b64b8..e15f6ae37 100644
--- a/composer.json
+++ b/composer.json
@@ -31,7 +31,7 @@
"require": {
"php": "^8.1",
"ext-dom": "*",
- "contao-community-alliance/dc-general": "^2.3.19",
+ "contao-community-alliance/dc-general": "^2.3.20",
"contao-community-alliance/events-contao-bindings": "^4.13.1",
"contao-community-alliance/meta-palettes": "^2.0.10",
"contao-community-alliance/translator": "^2.4.2",
diff --git a/src/CoreBundle/Controller/Backend/ConfigurationController.php b/src/CoreBundle/Controller/Backend/ConfigurationController.php
index 6795b63cb..9c7d06ad0 100644
--- a/src/CoreBundle/Controller/Backend/ConfigurationController.php
+++ b/src/CoreBundle/Controller/Backend/ConfigurationController.php
@@ -56,7 +56,10 @@ public function __invoke(
TranslatorInterface $translator,
ContaoFramework $framework,
): Response {
- $containerName = (string) $request->query->get('table', 'tl_metamodel');
+ $containerName = (string) $request->query->get('table', '');
+ if ('' === $containerName) {
+ $containerName = (string) ($request->attributes->get('_route_params', [])['tableName'] ?? 'tl_metamodel');
+ }
$controllerResult = $this->bootDcGeneralAndProcess(
$request,
$containerName,
diff --git a/src/CoreBundle/EventListener/DcGeneral/Table/Attribute/AttributeRendererListener.php b/src/CoreBundle/EventListener/DcGeneral/Table/Attribute/AttributeRendererListener.php
index 5e57b2e0f..7d15a69a4 100644
--- a/src/CoreBundle/EventListener/DcGeneral/Table/Attribute/AttributeRendererListener.php
+++ b/src/CoreBundle/EventListener/DcGeneral/Table/Attribute/AttributeRendererListener.php
@@ -98,7 +98,7 @@ public function modelToLabel(ModelToLabelEvent $event)
->setLabel(
'
%s [%s%s]
- %s%s - %s
+ %s %s - %s
'
)
->setArgs([
diff --git a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php
index 16e7e87ba..a95036c44 100644
--- a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php
+++ b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php
@@ -149,7 +149,7 @@ private function drawAttribute(ModelToLabelEvent $event)
$event
->setLabel('%s [%s%s]
- %s%s%s %s
+ %s %s%s %s
')
->setArgs([
$model->getProperty('published') ? 'published' : 'unpublished',
diff --git a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php
index 3ddc2a5d5..1776bca73 100644
--- a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php
+++ b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php
@@ -22,11 +22,14 @@
namespace MetaModels\CoreBundle\EventListener\DcGeneral\Table\DcaSettingCondition;
+use Contao\System;
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\DecodePropertyValueForWidgetEvent;
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\EncodePropertyValueFromWidgetEvent;
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent;
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\ManipulateWidgetEvent;
use ContaoCommunityAlliance\DcGeneral\Data\DataProviderInterface;
+use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface;
+use ContaoCommunityAlliance\DcGeneral\Data\MultiLanguageDataProviderInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\PropertyInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
use ContaoCommunityAlliance\DcGeneral\Event\AbstractEnvironmentAwareEvent;
@@ -37,6 +40,12 @@
use MetaModels\ITranslatedMetaModel;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use function is_array;
+use function method_exists;
+use function str_replace;
+use function str_starts_with;
+use function substr;
+
/**
* This handles the rendering of models to labels.
*
@@ -68,7 +77,7 @@ public function getValueOptions(GetPropertyOptionsEvent $event)
$attribute = $metaModel->getAttributeById((int) $attributeId);
if ($attribute) {
- $options = $this->getOptionsViaDcGeneral($metaModel, $event->getEnvironment(), $attribute);
+ $options = $this->getOptionsViaDcGeneral($metaModel, $event->getEnvironment(), $attribute, $model);
$mangled = [];
foreach ($options as $key => $option) {
$mangled['value_' . $key] = $option;
@@ -104,7 +113,7 @@ public function decodeValue(DecodePropertyValueForWidgetEvent $event)
$currentLanguage = $this->extractCurrentLanguageContext($metaModel);
- if (\is_array($event->getValue())) {
+ if (is_array($event->getValue())) {
$values = [];
foreach ($event->getValue() as $value) {
@@ -133,17 +142,19 @@ public function encodeValue(EncodePropertyValueFromWidgetEvent $event)
$model = $event->getPropertyValueBag();
$metaModel = $this->getMetaModel($event->getEnvironment());
- if (null === $attributeId = $model->getPropertyValue('attr_id')) {
+ if (null === $attributeOption = $model->getPropertyValue('attr_id')) {
return;
}
- if (null === $attribute = $metaModel->getAttributeById((int) $attributeId)) {
+ // Cut off the 'mm_xyz_' prefix.
+ $attrColName = \substr($attributeOption, \strlen($metaModel->getTableName() . '_'));
+ if (null === $attribute = $metaModel->getAttribute($attrColName)) {
return;
}
$currentLanguage = $this->extractCurrentLanguageContext($metaModel);
- if (\is_array($event->getValue())) {
+ if (is_array($event->getValue())) {
$values = [];
foreach ($event->getValue() as $value) {
@@ -191,11 +202,11 @@ protected function wantToHandle(AbstractEnvironmentAwareEvent $event)
if (!parent::wantToHandle($event)) {
return false;
}
- if (\method_exists($event, 'getPropertyName') && ('value' !== $event->getPropertyName())) {
+ if (method_exists($event, 'getPropertyName') && ('value' !== $event->getPropertyName())) {
return false;
}
- if (\method_exists($event, 'getProperty')) {
+ if (method_exists($event, 'getProperty')) {
$property = $event->getProperty();
if ($property instanceof PropertyInterface) {
$property = $property->getName();
@@ -215,10 +226,11 @@ protected function wantToHandle(AbstractEnvironmentAwareEvent $event)
* @param IMetaModel $metaModel The metamodel instance to obtain the values from.
* @param EnvironmentInterface $environment The environment used in the input screen table dc-general.
* @param IAttribute $attribute The attribute to obtain the values for.
+ * @param ModelInterface $model The model being edited.
*
* @return array
*/
- private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
+ private function getOptionsViaDcGeneral($metaModel, $environment, $attribute, $model)
{
$factory = DcGeneralFactory::deriveEmptyFromEnvironment($environment)
->setContainerName($metaModel->getTableName());
@@ -227,6 +239,22 @@ private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
$subEnv = $dcGeneral->getEnvironment();
$dataProvider = $subEnv->getDataProvider();
assert($dataProvider instanceof DataProviderInterface);
+ if ($dataProvider instanceof MultiLanguageDataProviderInterface) {
+ // FIXME: check if language supported.
+ $locale = System::getContainer()->get('request_stack')->getCurrentRequest()?->getLocale();
+ $languages = $dataProvider->getLanguages($model->getId());
+ $found = false;
+ foreach ($languages as $language) {
+ if ($language->getLocale() === $locale) {
+ $dataProvider->setCurrentLanguage($locale);
+ $found = true;
+ break;
+ }
+ }
+ if (!$found) {
+ $dataProvider->setCurrentLanguage($dataProvider->getFallbackLanguage($model->getId()));
+ }
+ }
$optEv = new GetPropertyOptionsEvent($subEnv, $dataProvider->getEmptyModel());
$optEv->setPropertyName($attribute->getColName());
$dispatcher = $subEnv->getEventDispatcher();
@@ -244,18 +272,18 @@ private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
* @param IAttribute $attribute The attribute.
* @param string $language The language to used for the convertion.
*
- * @return string The value to be saved.
+ * @return string|null The value to be saved.
*/
- private function aliasToId(string $alias, IAttribute $attribute, string $language): string
+ private function aliasToId(string $alias, IAttribute $attribute, string $language): ?string
{
if ($attribute instanceof IAliasConverter) {
- $idForAlias = $attribute->getIdForAlias(\substr($alias, 6), $language);
+ $idForAlias = $attribute->getIdForAlias(substr($alias, 6), $language);
if ($idForAlias !== null) {
return $idForAlias;
}
}
- return \substr($alias, 6);
+ return substr($alias, 6);
}
/**
@@ -270,8 +298,9 @@ private function aliasToId(string $alias, IAttribute $attribute, string $languag
*/
private function idToAlias(string $idValue, IAttribute $attribute, string $language): string
{
- if (\str_starts_with($idValue, 'value_')) {
- $idValue = \substr($idValue, 6);
+ // FIXME: When can this happen?
+ if (str_starts_with($idValue, 'value_')) {
+ $idValue = substr($idValue, 6);
}
if ($attribute instanceof IAliasConverter) {
@@ -309,6 +338,6 @@ private function extractCurrentLanguageContext(IMetaModel $metaModel): string
}
// Use the current backend language then.
- return \str_replace('-', '_', (string) $GLOBALS['TL_LANGUAGE']);
+ return str_replace('-', '_', (string) $GLOBALS['TL_LANGUAGE']);
}
}
diff --git a/src/CoreBundle/EventListener/DcGeneral/Table/RenderSetting/ModelToLabelListener.php b/src/CoreBundle/EventListener/DcGeneral/Table/RenderSetting/ModelToLabelListener.php
index 850215805..a414644e4 100644
--- a/src/CoreBundle/EventListener/DcGeneral/Table/RenderSetting/ModelToLabelListener.php
+++ b/src/CoreBundle/EventListener/DcGeneral/Table/RenderSetting/ModelToLabelListener.php
@@ -121,7 +121,7 @@ public function handle(ModelToLabelEvent $event)
$event
->setLabel('%s [%s%s]
- %s%s
+ %s %s
')
->setArgs([
$model->getProperty('enabled') ? 'published' : 'unpublished',
diff --git a/src/CoreBundle/Resources/config/routing.yml b/src/CoreBundle/Resources/config/routing.yml
index e786c10b8..097258082 100644
--- a/src/CoreBundle/Resources/config/routing.yml
+++ b/src/CoreBundle/Resources/config/routing.yml
@@ -11,12 +11,13 @@ metamodels.rendersetting.add_all:
defaults: { _controller: metamodels.controller.rendersetting.add_all, _scope: backend, _token_check: true }
metamodels.configuration:
- path: /contao/metamodels
+ path: /contao/metamodels/{tableName}
defaults:
_controller: MetaModels\CoreBundle\Controller\Backend\ConfigurationController
_scope: backend
_dcg_referer_update: true
_token_check: true
+ tableName: ~
metamodels.metamodel:
path: /contao/metamodel/{tableName}
diff --git a/src/CoreBundle/Resources/translations/tl_metamodel_dcasetting_condition.en.xlf b/src/CoreBundle/Resources/translations/tl_metamodel_dcasetting_condition.en.xlf
index efbcc4020..e729ed3f1 100644
--- a/src/CoreBundle/Resources/translations/tl_metamodel_dcasetting_condition.en.xlf
+++ b/src/CoreBundle/Resources/translations/tl_metamodel_dcasetting_condition.en.xlf
@@ -166,8 +166,7 @@
-
+
@@ -179,7 +178,13 @@
-
+
+
+
+
+
+
+