Skip to content

replace deprecated escaper #38135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions app/code/Magento/Cms/Ui/Component/Listing/Column/BlockActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ class BlockActions extends Column
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
* @param Escaper|null $escaper
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
array $data = [],
Escaper $escaper = null
) {
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
}

/**
Expand All @@ -60,7 +63,7 @@ public function prepareDataSource(array $dataSource)
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
if (isset($item['block_id'])) {
$title = $this->getEscaper()->escapeHtmlAttr($item['title']);
$title = $this->escaper->escapeHtmlAttr($item['title']);
$item[$this->getData('name')] = [
'edit' => [
'href' => $this->urlBuilder->getUrl(
Expand Down Expand Up @@ -92,19 +95,4 @@ public function prepareDataSource(array $dataSource)

return $dataSource;
}

/**
* Get instance of escaper
*
* @return Escaper
* @deprecated 101.0.7
*/
private function getEscaper()
{
if (!$this->escaper) {
// phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
}
return $this->escaper;
}
}
25 changes: 7 additions & 18 deletions app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
class PageActions extends Column
{
/** Url path */
const CMS_URL_PATH_EDIT = 'cms/page/edit';
const CMS_URL_PATH_DELETE = 'cms/page/delete';
public const CMS_URL_PATH_EDIT = 'cms/page/edit';
public const CMS_URL_PATH_DELETE = 'cms/page/delete';

/**
* @var \Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder
Expand Down Expand Up @@ -56,6 +56,7 @@ class PageActions extends Column
* @param array $data
* @param string $editUrl
* @param \Magento\Cms\ViewModel\Page\Grid\UrlBuilder|null $scopeUrlBuilder
* @param Escaper|null $escaper
*/
public function __construct(
ContextInterface $context,
Expand All @@ -65,14 +66,16 @@ public function __construct(
array $components = [],
array $data = [],
$editUrl = self::CMS_URL_PATH_EDIT,
\Magento\Cms\ViewModel\Page\Grid\UrlBuilder $scopeUrlBuilder = null
\Magento\Cms\ViewModel\Page\Grid\UrlBuilder $scopeUrlBuilder = null,
Escaper $escaper = null
) {
$this->urlBuilder = $urlBuilder;
$this->actionUrlBuilder = $actionUrlBuilder;
$this->editUrl = $editUrl;
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->scopeUrlBuilder = $scopeUrlBuilder ?: ObjectManager::getInstance()
->get(\Magento\Cms\ViewModel\Page\Grid\UrlBuilder::class);
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
}

/**
Expand All @@ -88,7 +91,7 @@ public function prepareDataSource(array $dataSource)
'href' => $this->urlBuilder->getUrl($this->editUrl, ['page_id' => $item['page_id']]),
'label' => __('Edit'),
];
$title = $this->getEscaper()->escapeHtml($item['title']);
$title = $this->escaper->escapeHtml($item['title']);
$item[$name]['delete'] = [
'href' => $this->urlBuilder->getUrl(self::CMS_URL_PATH_DELETE, ['page_id' => $item['page_id']]),
'label' => __('Delete'),
Expand All @@ -115,18 +118,4 @@ public function prepareDataSource(array $dataSource)

return $dataSource;
}

/**
* Get instance of escaper
*
* @return Escaper
* @deprecated 101.0.7
*/
private function getEscaper()
{
if (!$this->escaper) {
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
}
return $this->escaper;
}
}