Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator Alias in Grid View on Many-to-One Relation Produces [object Object] #744

Open
cancan101 opened this issue Nov 13, 2024 · 1 comment · Fixed by #745
Open

Operator Alias in Grid View on Many-to-One Relation Produces [object Object] #744

cancan101 opened this issue Nov 13, 2024 · 1 comment · Fixed by #745
Labels

Comments

@cancan101
Copy link
Contributor

Actual:
Image
Image

Expected:
Image
Image

Field:
Image

@cancan101
Copy link
Contributor Author

Whatever is calling Alias handles result from alias differently from result from DefaultValue. I need to track that down.

Basically without Alias, getFullPath (or similar) gets called and with alias it does not. I believe the rendering code path is very different for the case of an Alias vs direct field:

if (str_starts_with($key, '#')) {
if (!$haveHelperDefinition) {
$helperDefinitions = self::getHelperDefinitions();
$haveHelperDefinition = true;
}
if (!empty($helperDefinitions[$key])) {
$context['fieldname'] = $key;
$data[$key] = \Pimcore\Model\DataObject\Service::calculateCellValue($object, $helperDefinitions, $key, $context);
}
} elseif (str_starts_with($key, '~')) {
$type = $keyParts[1];
if ($type === 'classificationstore') {
$data[$key] = self::getStoreValueForObject($object, $key, $requestedLanguage);
}
} elseif (count($keyParts) > 1) {
// brick
$brickType = $keyParts[0];
if (str_contains($brickType, '?')) {
$brickDescriptor = substr($brickType, 1);
$brickDescriptor = json_decode($brickDescriptor, true);
$brickType = $brickDescriptor['containerKey'];
}
$brickKey = $keyParts[1];
$key = Service::getFieldForBrickType($object->getclass(), $brickType);
$brickClass = Objectbrick\Definition::getByKey($brickType);
$context['outerFieldname'] = $key;
if ($brickDescriptor) {
$innerContainer = $brickDescriptor['innerContainer'] ?? 'localizedfields';
/** @var Model\DataObject\ClassDefinition\Data\Localizedfields $localizedFields */
$localizedFields = $brickClass->getFieldDefinition($innerContainer);
$def = $localizedFields->getFieldDefinition($brickDescriptor['brickfield']);
} elseif ($brickClass instanceof Objectbrick\Definition) {
$def = $brickClass->getFieldDefinition($brickKey, $context);
}
}
if (!empty($key)) {
// some of the not editable field require a special response
$getter = 'get' . ucfirst($key);
$needLocalizedPermissions = false;
// if the definition is not set try to get the definition from localized fields
if (!$def) {
/** @var Model\DataObject\ClassDefinition\Data\Localizedfields|null $locFields */
$locFields = $object->getClass()->getFieldDefinition('localizedfields');
if ($locFields) {
$def = $locFields->getFieldDefinition($key, $context);
if ($def) {
$needLocalizedPermissions = true;
}
}
}
//relation type fields with remote owner do not have a getter
if (method_exists($object, $getter)) {
//system columns must not be inherited
if (in_array($key, Concrete::SYSTEM_COLUMN_NAMES)) {
$data[$dataKey] = $object->$getter();
} else {
$valueObject = self::getValueForObject($object, $key, $brickType, $brickKey, $def, $context, $brickDescriptor, $requestedLanguage);
$data['inheritedFields'][$dataKey] = ['inherited' => $valueObject->objectid != $object->getId(), 'objectid' => $valueObject->objectid];
if ($csvMode || method_exists($def, 'getDataForGrid')) {
if ($brickKey) {
$context['containerType'] = 'objectbrick';
$context['containerKey'] = $brickType;
$context['outerFieldname'] = $key;
}
$params = array_merge($params, ['context' => $context]);
if (!isset($params['purpose'])) {
$params['purpose'] = 'gridview';
}
if ($csvMode) {
$getterParams = ['language' => $requestedLanguage];
$tempData = $def->getForCsvExport($object, $getterParams);
} elseif (method_exists($def, 'getDataForGrid')) {
$tempData = $def->getDataForGrid($valueObject->value, $object, $params);
} else {
continue;
}
if ($def instanceof ClassDefinition\Data\Localizedfields) {
$needLocalizedPermissions = true;
foreach ($tempData as $tempKey => $tempValue) {
$data[$tempKey] = $tempValue;
}
} else {
$data[$dataKey] = $tempData;
if (
$def instanceof Model\DataObject\ClassDefinition\Data\Select
&& !$def->useConfiguredOptions()
&& $def->getOptionsProviderClass()
) {
$data[$dataKey . '%options'] = $def->getOptions();
}
}
} else {
$data[$dataKey] = $valueObject->value;
}
}
}
// because the key for the classification store has not a direct getter, you have to check separately if the data is inheritable
if (str_starts_with($key, '~') && empty($data[$key]['value'])) {
$type = $keyParts[1];
if ($type === 'classificationstore') {
if (!empty($inheritedData = self::getInheritedData($object, $key, $requestedLanguage))) {
$data[$dataKey] = $inheritedData['value'];
$data['inheritedFields'][$dataKey] = ['inherited' => $inheritedData['parent']->getId() != $object->getId(), 'objectid' => $inheritedData['parent']->getId()];
}
}
}
if ($needLocalizedPermissions) {
if (!$user->isAdmin()) {
$locale = \Pimcore::getContainer()->get(LocaleServiceInterface::class)->findLocale();
$permissionTypes = ['View', 'Edit'];
foreach ($permissionTypes as $permissionType) {
//TODO, this needs refactoring! Ideally, call it only once!
$languagesAllowed = Service::getLanguagePermissions($object, $user, 'l' . $permissionType);
if ($languagesAllowed) {
$languagesAllowed = array_keys($languagesAllowed);
if (!in_array($locale, $languagesAllowed)) {
$data['metadata']['permission'][$key]['no' . $permissionType] = 1;
if ($permissionType === 'View') {
$data[$key] = null;
}
}
}
}
}
}
}
}
}
return $data;
}

something in the case of the direct field causes it to render as the full path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants