Delete.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Controller\Adminhtml\Bookmark;
  7. use Magento\Backend\App\Action\Context;
  8. use Magento\Framework\View\Element\UiComponentFactory;
  9. use Magento\Ui\Api\BookmarkManagementInterface;
  10. use Magento\Ui\Api\BookmarkRepositoryInterface;
  11. use Magento\Ui\Controller\Adminhtml\AbstractAction;
  12. /**
  13. * Class Delete action
  14. */
  15. class Delete extends AbstractAction
  16. {
  17. /**
  18. * @var BookmarkRepositoryInterface
  19. */
  20. protected $bookmarkRepository;
  21. /**
  22. * @var BookmarkManagementInterface
  23. */
  24. private $bookmarkManagement;
  25. /**
  26. * @param Context $context
  27. * @param UiComponentFactory $factory
  28. * @param BookmarkRepositoryInterface $bookmarkRepository
  29. * @param BookmarkManagementInterface $bookmarkManagement
  30. */
  31. public function __construct(
  32. Context $context,
  33. UiComponentFactory $factory,
  34. BookmarkRepositoryInterface $bookmarkRepository,
  35. BookmarkManagementInterface $bookmarkManagement
  36. ) {
  37. parent::__construct($context, $factory);
  38. $this->bookmarkRepository = $bookmarkRepository;
  39. $this->bookmarkManagement = $bookmarkManagement;
  40. }
  41. /**
  42. * Action for AJAX request
  43. *
  44. * @return void
  45. */
  46. public function execute()
  47. {
  48. $viewIds = explode('.', $this->_request->getParam('data'));
  49. $bookmark = $this->bookmarkManagement->getByIdentifierNamespace(
  50. array_pop($viewIds),
  51. $this->_request->getParam('namespace')
  52. );
  53. if ($bookmark && $bookmark->getId()) {
  54. $this->bookmarkRepository->delete($bookmark);
  55. }
  56. }
  57. }