Selector.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\UrlRewrite\Block;
  7. class Selector extends \Magento\Backend\Block\Template
  8. {
  9. /**
  10. * List of available modes from source model
  11. * key => label
  12. *
  13. * @var array
  14. */
  15. protected $_modes;
  16. /**
  17. * @var string
  18. */
  19. protected $_template = 'Magento_UrlRewrite::selector.phtml';
  20. /**
  21. * Set block template and get available modes
  22. *
  23. * @return void
  24. */
  25. protected function _construct()
  26. {
  27. $this->_modes = [
  28. 'id' => __('Custom'),
  29. 'category' => __('For Category'),
  30. 'product' => __('For Product'),
  31. 'cms_page' => __('For CMS page'),
  32. ];
  33. }
  34. /**
  35. * Available modes getter
  36. *
  37. * @return array
  38. */
  39. public function getModes()
  40. {
  41. return $this->_modes;
  42. }
  43. /**
  44. * Label getter
  45. *
  46. * @return \Magento\Framework\Phrase
  47. */
  48. public function getSelectorLabel()
  49. {
  50. return __('Create URL Rewrite');
  51. }
  52. /**
  53. * Check whether selection is in specified mode
  54. *
  55. * @param string $mode
  56. * @return bool
  57. */
  58. public function isMode($mode)
  59. {
  60. return $this->getRequest()->has($mode);
  61. }
  62. /**
  63. * Get default mode
  64. *
  65. * @return string
  66. */
  67. public function getDefaultMode()
  68. {
  69. $keys = array_keys($this->_modes);
  70. return array_shift($keys);
  71. }
  72. /**
  73. * Get mode Url
  74. *
  75. * @param string $mode
  76. * @return string
  77. */
  78. public function getModeUrl($mode)
  79. {
  80. return $this->getUrl('adminhtml/*/*') . $mode;
  81. }
  82. }