Ui/Component/Listing/Column/PostActions.php
<?php
/**
* Copyright © EAdesign by Eco Active S.R.L.,All rights reserved.
* See LICENSE for license details.
*/
namespace Eadesigndev\Pdfgenerator\Ui\Component\Listing\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\UrlInterface;
class PostActions extends Column
{
/** Url path */
const TEMPLATE_EDIT = 'pdfgenerator/templates/edit';
const TEMPLATE_DELETE = 'pdfgenerator/templates/delete';
/** @var UrlInterface */
private $urlBuilder;
/**
* @var string
*/
private $editUrl;
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
* @param string $editUrl
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = [],
$editUrl = self::TEMPLATE_EDIT
) {
$this->urlBuilder = $urlBuilder;
$this->editUrl = $editUrl;
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) {
$name = $this->getData('name');
if (isset($item['template_id'])) {
$item[$name]['edit'] = [
'href' => $this->urlBuilder->getUrl(
$this->editUrl,
['template_id' => $item['template_id']]
),
'label' => __('Edit')
];
$item[$name]['delete'] = [
'href' => $this->urlBuilder->getUrl(
self::TEMPLATE_DELETE,
['template_id' => $item['template_id']]
),
'label' => __('Delete'),
'confirm' => [
'title' => __('Delete "${ $.$data.title }"'),
'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?')
]
];
}
}
}
return $dataSource;
}
}