Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use ContaoCommunityAlliance\UrlBuilder\UrlBuilderFactoryInterface;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use MetaModels\Attribute\IInternal;
use MetaModels\BackendIntegration\TemplateList;
use MetaModels\CoreBundle\Assets\IconBuilder;
use MetaModels\Filter\Setting\FilterSettingFactory;
Expand Down Expand Up @@ -249,37 +250,51 @@ public function editRenderSettingButton(DC_Table $dataContainer)
*
* @param DC_Table $objDc The data container calling this method.
*
* @return string[] array of all attributes as colName => human name
* @return array<string, array<string, string>> array of all attributes as colName => human name
*
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
public function getAttributeNames(DC_Table $objDc)
{
$attributeNames = [
'sorting' => $this->translator->trans('metamodels_sorting', [], 'metamodels_list'),
'random' => $this->translator->trans('random', [], 'metamodels_list'),
'id' => $this->translator->trans('id', [], 'metamodels_list')
];

/** @psalm-suppress UndefinedMagicPropertyFetch */
assert(null !== $objDc->activeRecord);

try {
$metaModelName = $this->factory->translateIdToMetaModelName($objDc->activeRecord->metamodel);
} catch (RuntimeException $exception) {
// No valid MetaModel selected, can not add attributes of it.
return $attributeNames;
return [];
}
$metaModel = $this->factory->getMetaModel($metaModelName);
if (null === $metaModel) {
return [];
}
$metaModel = $this->factory->getMetaModel($metaModelName);

if ($metaModel) {
foreach ($metaModel->getAttributes() as $objAttribute) {
$attributeNames[$objAttribute->getColName()] = $objAttribute->getName();
$result = [];
// Add meta fields.
$result['meta'] = [
'sorting' => $this->translator->trans('metamodels_sorting', [], 'metamodels_list'),
'random' => $this->translator->trans('random', [], 'metamodels_list'),
'id' => $this->translator->trans('id', [], 'metamodels_list'),
];

foreach ($metaModel->getAttributes() as $attribute) {
// Hide virtual types.
if ($attribute instanceof IInternal) {
continue;
}

$colName = $attribute->getColName();
$result['attributes'][$colName] = sprintf(
'%s [%s, "%s"]',
$attribute->getName(),
$attribute->get('type'),
$colName,
);
}

return $attributeNames;
return $result;
}

/**
Expand Down
Loading
Loading