Skip to content

Commit b43980b

Browse files
committed
Grid Export rendered data is not reflecting in the exported File, Displayed ID instead of Rendered Label #25963.
Fixed grids export: option labels are taken from grid filters and columns now.
1 parent 0ac3443 commit b43980b

File tree

1 file changed

+70
-16
lines changed

1 file changed

+70
-16
lines changed

app/code/Magento/Ui/Model/Export/MetadataProvider.php

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Ui\Model\Export;
78

9+
use DateTime;
10+
use DateTimeZone;
11+
use Exception;
812
use Magento\Framework\Api\Search\DocumentInterface;
13+
use Magento\Framework\Data\OptionSourceInterface;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Framework\Locale\ResolverInterface;
16+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
917
use Magento\Framework\View\Element\UiComponentInterface;
1018
use Magento\Ui\Component\Filters;
1119
use Magento\Ui\Component\Filters\Type\Select;
1220
use Magento\Ui\Component\Listing\Columns;
21+
use Magento\Ui\Component\Listing\Columns\Column;
1322
use Magento\Ui\Component\MassAction\Filter;
14-
use Magento\Framework\Locale\ResolverInterface;
15-
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1623

1724
/**
18-
* Metadata Provider
25+
* Metadata Provider for grid listing export.
26+
*
1927
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2028
*/
2129
class MetadataProvider
@@ -76,7 +84,7 @@ public function __construct(
7684
*
7785
* @param UiComponentInterface $component
7886
* @return UiComponentInterface
79-
* @throws \Exception
87+
* @throws Exception
8088
*/
8189
protected function getColumnsComponent(UiComponentInterface $component)
8290
{
@@ -85,14 +93,16 @@ protected function getColumnsComponent(UiComponentInterface $component)
8593
return $childComponent;
8694
}
8795
}
88-
throw new \Exception('No columns found'); // @codingStandardsIgnoreLine
96+
throw new Exception('No columns found'); // @codingStandardsIgnoreLine
8997
}
9098

9199
/**
92100
* Returns columns list
93101
*
94102
* @param UiComponentInterface $component
103+
*
95104
* @return UiComponentInterface[]
105+
* @throws Exception
96106
*/
97107
protected function getColumns(UiComponentInterface $component)
98108
{
@@ -111,7 +121,9 @@ protected function getColumns(UiComponentInterface $component)
111121
* Retrieve Headers row array for Export
112122
*
113123
* @param UiComponentInterface $component
124+
*
114125
* @return string[]
126+
* @throws Exception
115127
*/
116128
public function getHeaders(UiComponentInterface $component)
117129
{
@@ -127,7 +139,9 @@ public function getHeaders(UiComponentInterface $component)
127139
* Returns DB fields list
128140
*
129141
* @param UiComponentInterface $component
142+
*
130143
* @return array
144+
* @throws Exception
131145
*/
132146
public function getFields(UiComponentInterface $component)
133147
{
@@ -184,34 +198,73 @@ protected function getComplexLabel($list, $label, &$output)
184198
}
185199

186200
/**
187-
* Returns array of Select options
201+
* Prepare array of options.
202+
*
203+
* @param array $options
188204
*
189-
* @param Select $filter
190205
* @return array
191206
*/
192-
protected function getFilterOptions(Select $filter)
207+
protected function getOptionsArray(array $options): array
193208
{
194-
$options = [];
195-
foreach ($filter->getData('config/options') as $option) {
209+
$preparedOptions = [];
210+
foreach ($options as $option) {
196211
if (!is_array($option['value'])) {
197-
$options[$option['value']] = $option['label'];
212+
$preparedOptions[$option['value']] = $option['label'];
198213
} else {
199214
$this->getComplexLabel(
200215
$option['value'],
201216
$option['label'],
202-
$options
217+
$preparedOptions
203218
);
204219
}
205220
}
206-
return $options;
221+
222+
return $preparedOptions;
207223
}
208224

209225
/**
210226
* Returns Filters with options
211227
*
212228
* @return array
229+
* @throws LocalizedException
213230
*/
214231
public function getOptions()
232+
{
233+
return array_merge(
234+
$this->getColumnOptions(),
235+
$this->getFilterOptions()
236+
);
237+
}
238+
239+
/**
240+
* Get options from columns.
241+
*
242+
* @return array
243+
* @throws LocalizedException
244+
* @throws Exception
245+
*/
246+
protected function getColumnOptions()
247+
{
248+
$options = [];
249+
$component = $this->filter->getComponent();
250+
/** @var Column $columnComponent */
251+
foreach ($this->getColumns($component) as $columnComponent) {
252+
/** @var OptionSourceInterface $options */
253+
if ($optionSource = $columnComponent->getData('options')) {
254+
$options[$columnComponent->getName()] = $this->getOptionsArray($optionSource->toOptionArray());
255+
}
256+
}
257+
258+
return $options;
259+
}
260+
261+
/**
262+
* Get options from column filters.
263+
*
264+
* @return array
265+
* @throws LocalizedException
266+
*/
267+
protected function getFilterOptions()
215268
{
216269
$options = [];
217270
$component = $this->filter->getComponent();
@@ -221,7 +274,7 @@ public function getOptions()
221274
if ($child instanceof Filters) {
222275
foreach ($child->getChildComponents() as $filter) {
223276
if ($filter instanceof Select) {
224-
$options[$filter->getName()] = $this->getFilterOptions($filter);
277+
$options[$filter->getName()] = $this->getOptionsArray($filter->getData('config/options'));
225278
}
226279
}
227280
}
@@ -232,9 +285,10 @@ public function getOptions()
232285
/**
233286
* Convert document date(UTC) fields to default scope specified
234287
*
235-
* @param \Magento\Framework\Api\Search\DocumentInterface $document
288+
* @param DocumentInterface $document
236289
* @param string $componentName
237290
* @return void
291+
* @throws Exception
238292
*/
239293
public function convertDate($document, $componentName)
240294
{
@@ -247,7 +301,7 @@ public function convertDate($document, $componentName)
247301
continue;
248302
}
249303
$convertedDate = $this->localeDate->date(
250-
new \DateTime($fieldValue, new \DateTimeZone('UTC')),
304+
new DateTime($fieldValue, new DateTimeZone('UTC')),
251305
$this->locale,
252306
true
253307
);

0 commit comments

Comments
 (0)