Skip to content

Commit 2111fe2

Browse files
committed
Fix list of attributes in MM List as CE and Module
1 parent ef5824e commit 2111fe2

File tree

8 files changed

+258
-150
lines changed

8 files changed

+258
-150
lines changed

src/CoreBundle/Contao/Hooks/AbstractContentElementAndModuleCallback.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use ContaoCommunityAlliance\UrlBuilder\UrlBuilderFactoryInterface;
3030
use Doctrine\DBAL\Connection;
3131
use Doctrine\DBAL\Exception;
32+
use MetaModels\Attribute\IInternal;
3233
use MetaModels\BackendIntegration\TemplateList;
3334
use MetaModels\CoreBundle\Assets\IconBuilder;
3435
use MetaModels\Filter\Setting\FilterSettingFactory;
@@ -249,37 +250,51 @@ public function editRenderSettingButton(DC_Table $dataContainer)
249250
*
250251
* @param DC_Table $objDc The data container calling this method.
251252
*
252-
* @return string[] array of all attributes as colName => human name
253+
* @return array<string, array<string, string>> array of all attributes as colName => human name
253254
*
254255
* @SuppressWarnings(PHPMD.Superglobals)
255256
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
256257
*/
257258
public function getAttributeNames(DC_Table $objDc)
258259
{
259-
$attributeNames = [
260-
'sorting' => $this->translator->trans('metamodels_sorting', [], 'metamodels_list'),
261-
'random' => $this->translator->trans('random', [], 'metamodels_list'),
262-
'id' => $this->translator->trans('id', [], 'metamodels_list')
263-
];
264-
265260
/** @psalm-suppress UndefinedMagicPropertyFetch */
266261
assert(null !== $objDc->activeRecord);
267262

268263
try {
269264
$metaModelName = $this->factory->translateIdToMetaModelName($objDc->activeRecord->metamodel);
270265
} catch (RuntimeException $exception) {
271266
// No valid MetaModel selected, can not add attributes of it.
272-
return $attributeNames;
267+
return [];
268+
}
269+
$metaModel = $this->factory->getMetaModel($metaModelName);
270+
if (null === $metaModel) {
271+
return [];
273272
}
274-
$metaModel = $this->factory->getMetaModel($metaModelName);
275273

276-
if ($metaModel) {
277-
foreach ($metaModel->getAttributes() as $objAttribute) {
278-
$attributeNames[$objAttribute->getColName()] = $objAttribute->getName();
274+
$result = [];
275+
// Add meta fields.
276+
$result['meta'] = [
277+
'sorting' => $this->translator->trans('metamodels_sorting', [], 'metamodels_list'),
278+
'random' => $this->translator->trans('random', [], 'metamodels_list'),
279+
'id' => $this->translator->trans('id', [], 'metamodels_list'),
280+
];
281+
282+
foreach ($metaModel->getAttributes() as $attribute) {
283+
// Hide virtual types.
284+
if ($attribute instanceof IInternal) {
285+
continue;
279286
}
287+
288+
$colName = $attribute->getColName();
289+
$result['attributes'][$colName] = sprintf(
290+
'%s [%s, "%s"]',
291+
$attribute->getName(),
292+
$attribute->get('type'),
293+
$colName,
294+
);
280295
}
281296

282-
return $attributeNames;
297+
return $result;
283298
}
284299

285300
/**

0 commit comments

Comments
 (0)