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

Revert "Fix formatting for alias on relations (#745)" #782

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

cancan101
Copy link
Contributor

@cancan101 cancan101 commented Dec 5, 2024

This reverts commit 91d1903.

Closes #780

The original fix was at the wrong location in the evaluation tree. 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. Not sure why.

@fashxp
@solverat
@la-lisa

Copy link

sonarqubecloud bot commented Dec 5, 2024

@solverat
Copy link
Contributor

solverat commented Dec 5, 2024

Yes, that fixes the issue. The original issue (#744) should be addressed at the operator "Alias" itself.

@cancan101
Copy link
Contributor Author

cancan101 commented Dec 5, 2024

It might be more complicated than just fixing in the alias operator as the alias operator could itself be nested. I have to investigate that

@robertSt7 robertSt7 added the Bug label Dec 9, 2024
@robertSt7 robertSt7 changed the base branch from 1.6 to 1.7 December 9, 2024 13:52
@robertSt7 robertSt7 self-assigned this Dec 9, 2024
@cancan101
Copy link
Contributor Author

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.

@robertSt7 robertSt7 modified the milestones: 1.7.2, 1.7.3 Dec 10, 2024
@robertSt7 robertSt7 merged commit 98e47dc into pimcore:1.7 Dec 10, 2024
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2024
@robertSt7
Copy link
Contributor

@cancan101 Thanks for reverting your PR. For further discussions I have re-opened the issue #744

@cancan101 cancan101 deleted the revert-745-fix/alias-relation branch December 11, 2024 02:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants