chg: [crud:index] Include all meta-fields regardless of user's preference when in REST context

refacto/CRUDComponent
Sami Mokaddem 2023-11-16 09:02:40 +01:00
parent f0ba0d8316
commit 46bafa045f
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 8 additions and 4 deletions

View File

@ -96,8 +96,9 @@ class CRUDComponent extends Component
$query->order($sort . ' ' . $direction);
}
}
$isRestOrCSV = $this->Controller->ParamHandler->isRest() || $this->request->is('csv');
if ($this->metaFieldsSupported()) {
$query = $this->includeRequestedMetaFields($query);
$query = $this->includeRequestedMetaFields($query, $isRestOrCSV);
}
if (!$this->Controller->ParamHandler->isRest()) {
@ -107,7 +108,7 @@ class CRUDComponent extends Component
}
$data = $this->Controller->paginate($query, $this->Controller->paginate ?? []);
$totalCount = $this->Controller->getRequest()->getAttribute('paging')[$this->TableAlias]['count'];
if ($this->Controller->ParamHandler->isRest() || $this->request->is('csv')) {
if ($isRestOrCSV) {
if (isset($options['hidden'])) {
$data->each(function($value, $key) use ($options) {
$hidden = is_array($options['hidden']) ? $options['hidden'] : [$options['hidden']];
@ -777,8 +778,11 @@ class CRUDComponent extends Component
return $data;
}
protected function includeRequestedMetaFields($query)
protected function includeRequestedMetaFields($query, $isREST=false)
{
if (!empty($isREST)) {
return $query->contain(['MetaFields']);
}
$user = $this->Controller->ACL->getUser();
$tableSettings = IndexSetting::getTableSetting($user, $this->Table);
if (empty($tableSettings['visible_meta_column'])) {

View File

@ -78,7 +78,7 @@ class AppModel extends Entity
$this->meta_fields[$i]['template_namespace'] = $templates[$templateDirectoryId]['namespace'];
}
}
if (!empty($options['smartFlattenMetafields'])) {
if (!empty($this->meta_fields) && !empty($options['smartFlattenMetafields'])) {
$smartFlatten = [];
foreach ($this->meta_fields as $metafield) {
$key = "{$metafield['template_name']}_v{$metafield['template_version']}:{$metafield['field']}";