Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Review.php
Go to the documentation of this file.
1 <?php
7 
15 use Magento\Framework\Module\Manager as ModuleManager;
17 
24 class Review extends AbstractModifier
25 {
26  const GROUP_REVIEW = 'review';
27  const GROUP_CONTENT = 'content';
28  const DATA_SCOPE_REVIEW = 'grouped';
29  const SORT_ORDER = 20;
30  const LINK_TYPE = 'associated';
31 
36  protected $locator;
37 
42  protected $urlBuilder;
43 
47  private $moduleManager;
48 
53  public function __construct(
56  ) {
57  $this->locator = $locator;
58  $this->urlBuilder = $urlBuilder;
59  }
60 
65  public function modifyMeta(array $meta)
66  {
67  if (!$this->locator->getProduct()->getId() || !$this->getModuleManager()->isOutputEnabled('Magento_Review')) {
68  return $meta;
69  }
70 
71  $meta[static::GROUP_REVIEW] = [
72  'children' => [
73  'review_listing' => [
74  'arguments' => [
75  'data' => [
76  'config' => [
77  'autoRender' => true,
78  'componentType' => 'insertListing',
79  'dataScope' => 'review_listing',
80  'externalProvider' => 'review_listing.review_listing_data_source',
81  'selectionsProvider' => 'review_listing.review_listing.product_columns.ids',
82  'ns' => 'review_listing',
83  'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
84  'realTimeLink' => false,
85  'behaviourType' => 'simple',
86  'externalFilterMode' => true,
87  'imports' => [
88  'productId' => '${ $.provider }:data.product.current_product_id'
89  ],
90  'exports' => [
91  'productId' => '${ $.externalProvider }:params.current_product_id'
92  ],
93  ],
94  ],
95  ],
96  ],
97  ],
98  'arguments' => [
99  'data' => [
100  'config' => [
101  'label' => __('Product Reviews'),
102  'collapsible' => true,
103  'opened' => false,
104  'componentType' => Form\Fieldset::NAME,
105  'sortOrder' =>
106  $this->getNextGroupSortOrder(
107  $meta,
108  static::GROUP_CONTENT,
109  static::SORT_ORDER
110  ),
111  ],
112  ],
113  ],
114  ];
115 
116  return $meta;
117  }
118 
123  public function modifyData(array $data)
124  {
125  $productId = $this->locator->getProduct()->getId();
126 
127  $data[$productId][self::DATA_SOURCE_DEFAULT]['current_product_id'] = $productId;
128 
129  return $data;
130  }
131 
139  private function getModuleManager()
140  {
141  if ($this->moduleManager === null) {
142  $this->moduleManager = ObjectManager::getInstance()->get(ModuleManager::class);
143  }
144  return $this->moduleManager;
145  }
146 }
getNextGroupSortOrder(array $meta, $groupCodes, $defaultSortOrder, $iteration=1)
__()
Definition: __.php:13
__construct(LocatorInterface $locator, UrlInterface $urlBuilder)
Definition: Review.php:53