As modyfing data for grid only should be, in my opinion, kept around the grid itself I've implemented some small column class modification by:
modyfing the layout column node:
<column name="required" class="\Vendor\ModuleName\Ui\Component\Listing\Column\Yesno">
and creating class \Vendor\ModuleName\Ui\Component\Listing\Column\Yesno
:
<?php
namespace \Vendor\ModuleName\Ui\Component\Listing\Column;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Store\Model\StoreManagerInterface;
class Yesno extends \Magento\Ui\Component\Listing\Columns\Column
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param StoreManagerInterface $storeManager
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
StoreManagerInterface $storeManager,
array $components = [],
array $data = []
) {
$this->storeManager = $storeManager;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if(isset($dataSource['data']['items'])) {
foreach($dataSource['data']['items'] as & $item) {
if($item) {
$item['required'] = ($item['required'] == 1 ? __('Yes') : new __('No'));
}
}
}
return $dataSource;
}
}