From 791a1d4d9e1a688b201409f5b76d3cd1e0cbc568 Mon Sep 17 00:00:00 2001 From: gonzalo Date: Fri, 21 Apr 2017 15:21:38 -0300 Subject: [PATCH] add action to the store grid --- Ui/Component/Stores/Grid/Column/Actions.php | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Ui/Component/Stores/Grid/Column/Actions.php diff --git a/Ui/Component/Stores/Grid/Column/Actions.php b/Ui/Component/Stores/Grid/Column/Actions.php new file mode 100644 index 00000000..5b4da997 --- /dev/null +++ b/Ui/Component/Stores/Grid/Column/Actions.php @@ -0,0 +1,73 @@ + + * @copyright Ebizmarts (http://ebizmarts.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @date: 4/5/17 11:19 AM + * @file: Actions.php + */ +namespace Ebizmarts\MailChimp\Ui\Component\Stores\Grid\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 ProductActions + */ +class Actions extends Column +{ + /** + * @var UrlInterface + */ + protected $urlBuilder; + + /** + * @param ContextInterface $context + * @param UiComponentFactory $uiComponentFactory + * @param UrlInterface $urlBuilder + * @param array $components + * @param array $data + */ + public function __construct( + ContextInterface $context, + UiComponentFactory $uiComponentFactory, + UrlInterface $urlBuilder, + array $components = [], + array $data = [] + ) { + $this->urlBuilder = $urlBuilder; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare Data Source + * + * @param array $dataSource + * @return array + */ + public function prepareDataSource(array $dataSource) + { + if (isset($dataSource['data']['items'])) { + $storeId = $this->context->getFilterParam('store_id'); + + foreach ($dataSource['data']['items'] as &$item) { + $item[$this->getData('name')]['edit'] = [ + 'href' => $this->urlBuilder->getUrl( + 'mailchimp/stores/edit', + ['id' => $item['id']] + ), + 'label' => __('Edit'), + 'hidden' => false, + ]; + } + } + + return $dataSource; + } +}