mundipagg/magento2

View on GitHub
Ui/Component/Listing/Column/Translate.php

Summary

Maintainability
A
35 mins
Test Coverage
<?php

namespace MundiPagg\MundiPagg\Ui\Component\Listing\Column;

use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;

class Translate extends Column
{
    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        array $components = [],
        array $data = []
    ) {
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }

    public function prepareDataSource(array $dataSource)
    {
        if (!isset($dataSource['data']['items'])) {
            return $dataSource;
        }

        $fieldName = $this->getData('name');
        foreach ($dataSource['data']['items'] as &$item) {
            $item[$fieldName] = __($item[$fieldName]);

            if ($fieldName != 'installments') {
                continue;
            }
            $item[$fieldName] = __('No');

            if ($item[$fieldName]) {
                $item[$fieldName] = __('Yes');
            }
        }

        return $dataSource;
    }
}