Edit.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block\Adminhtml\Rating;
  7. /**
  8. * Rating edit form
  9. */
  10. class Edit extends \Magento\Backend\Block\Widget\Form\Container
  11. {
  12. /**
  13. * Core registry
  14. *
  15. * @var \Magento\Framework\Registry
  16. */
  17. protected $_coreRegistry = null;
  18. /**
  19. * Rating factory
  20. *
  21. * @var \Magento\Review\Model\RatingFactory
  22. */
  23. protected $_ratingFactory;
  24. /**
  25. * @var string
  26. */
  27. protected $_blockGroup = 'Magento_Review';
  28. /**
  29. * @param \Magento\Backend\Block\Widget\Context $context
  30. * @param \Magento\Review\Model\RatingFactory $ratingFactory
  31. * @param \Magento\Framework\Registry $registry
  32. * @param array $data
  33. */
  34. public function __construct(
  35. \Magento\Backend\Block\Widget\Context $context,
  36. \Magento\Review\Model\RatingFactory $ratingFactory,
  37. \Magento\Framework\Registry $registry,
  38. array $data = []
  39. ) {
  40. $this->_ratingFactory = $ratingFactory;
  41. $this->_coreRegistry = $registry;
  42. parent::__construct($context, $data);
  43. }
  44. /**
  45. * @return void
  46. */
  47. protected function _construct()
  48. {
  49. parent::_construct();
  50. $this->_objectId = 'id';
  51. $this->_controller = 'adminhtml_rating';
  52. $this->_blockGroup = 'Magento_Review';
  53. $this->buttonList->update('save', 'label', __('Save Rating'));
  54. $this->buttonList->update('delete', 'label', __('Delete Rating'));
  55. if ($this->getRequest()->getParam($this->_objectId)) {
  56. $ratingData = $this->_ratingFactory->create()->load($this->getRequest()->getParam($this->_objectId));
  57. $this->_coreRegistry->register('rating_data', $ratingData);
  58. }
  59. }
  60. /**
  61. * @return \Magento\Framework\Phrase
  62. */
  63. public function getHeaderText()
  64. {
  65. $ratingData = $this->_coreRegistry->registry('rating_data');
  66. if ($ratingData && $ratingData->getId()) {
  67. return __("Edit Rating #%1", $this->escapeHtml($ratingData->getRatingCode()));
  68. } else {
  69. return __('New Rating');
  70. }
  71. }
  72. }