From 9be71171b5a477e6f92993c2bcc4bb2c1d1c0f89 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Wed, 26 Apr 2017 14:41:03 -0400 Subject: [PATCH] update legacy visible columns support --- .../TableGateway/RelationalTableGateway.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/api/core/Directus/Database/TableGateway/RelationalTableGateway.php b/api/core/Directus/Database/TableGateway/RelationalTableGateway.php index 2c9f03c6332a7..196ec0260798b 100644 --- a/api/core/Directus/Database/TableGateway/RelationalTableGateway.php +++ b/api/core/Directus/Database/TableGateway/RelationalTableGateway.php @@ -624,6 +624,19 @@ public function applyDefaultEntriesSelectParams(array $params) // Stripe whitespaces $columns = array_map('trim', $columns); + // ---------------------------------------------------------------------------- + // merge legacy visible columns param + // ---------------------------------------------------------------------------- + // if both columns and columns_visible are passed columns are prioritized + // ---------------------------------------------------------------------------- + $visibleColumns = ArrayUtils::get($params, 'columns_visible', []); + // columns_visible are expected to be an array + if (!is_array($visibleColumns)) { + $visibleColumns = [$visibleColumns]; + } + + $columns = array_merge($visibleColumns, $columns); + // Add columns to params if it's not empty. // otherwise remove from params if (!empty($columns)) { @@ -773,8 +786,8 @@ public function loadItems(array $params = [], \Closure $queryCallback = null) $builder = new Builder($this->getAdapter()); $builder->from($this->getTable()); - if (ArrayUtils::has($params, 'columns') || ArrayUtils::has($params, 'columns_visible')) { - $columns = array_unique(array_merge($tableSchema->getPrimaryKeysName(), ArrayUtils::get($params, 'columns', []), ArrayUtils::get($params, 'columns_visible', []))); + if (ArrayUtils::has($params, 'columns')) { + $columns = array_unique(array_merge($tableSchema->getPrimaryKeysName(), ArrayUtils::get($params, 'columns', []))); } else { $columns = $tableSchema->getColumnsName(); } @@ -806,7 +819,7 @@ public function loadItems(array $params = [], \Closure $queryCallback = null) $depth = ArrayUtils::get($params, 'depth', null); if ($depth !== null) { - $paramColumns = array_merge(ArrayUtils::get($params, 'columns', []), ArrayUtils::get($params, 'columns_visible', [])); + $paramColumns = ArrayUtils::get($params, 'columns', []); $relationalColumns = $tableSchema->getRelationalColumnsName(); if ($paramColumns) {