Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlockActions.php
Go to the documentation of this file.
1 <?php
7 
14 
18 class BlockActions extends Column
19 {
23  const URL_PATH_EDIT = 'cms/block/edit';
24  const URL_PATH_DELETE = 'cms/block/delete';
25  const URL_PATH_DETAILS = 'cms/block/details';
26 
30  protected $urlBuilder;
31 
35  private $escaper;
36 
46  public function __construct(
50  array $components = [],
51  array $data = []
52  ) {
53  $this->urlBuilder = $urlBuilder;
54  parent::__construct($context, $uiComponentFactory, $components, $data);
55  }
56 
60  public function prepareDataSource(array $dataSource)
61  {
62  if (isset($dataSource['data']['items'])) {
63  foreach ($dataSource['data']['items'] as & $item) {
64  if (isset($item['block_id'])) {
65  $title = $this->getEscaper()->escapeHtml($item['title']);
66  $item[$this->getData('name')] = [
67  'edit' => [
68  'href' => $this->urlBuilder->getUrl(
69  static::URL_PATH_EDIT,
70  [
71  'block_id' => $item['block_id']
72  ]
73  ),
74  'label' => __('Edit')
75  ],
76  'delete' => [
77  'href' => $this->urlBuilder->getUrl(
78  static::URL_PATH_DELETE,
79  [
80  'block_id' => $item['block_id']
81  ]
82  ),
83  'label' => __('Delete'),
84  'confirm' => [
85  'title' => __('Delete %1', $title),
86  'message' => __('Are you sure you want to delete a %1 record?', $title)
87  ],
88  'post' => true
89  ]
90  ];
91  }
92  }
93  }
94 
95  return $dataSource;
96  }
97 
104  private function getEscaper()
105  {
106  if (!$this->escaper) {
107  $this->escaper = ObjectManager::getInstance()->get(Escaper::class);
108  }
109  return $this->escaper;
110  }
111 }
$title
Definition: default.phtml:14
__()
Definition: __.php:13
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, UrlInterface $urlBuilder, array $components=[], array $data=[])