/** * Prepare add review form * * @return void */ protected function _prepareForm() { /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $fieldset = $form->addFieldset('add_review_form', array('legend' => __('Review Details'))); $fieldset->addField('product_name', 'note', array('label' => __('Product'), 'text' => 'product_name')); $fieldset->addField('detailed_rating', 'note', array('label' => __('Product Rating'), 'required' => true, 'text' => '<div id="rating_detail">' . $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->toHtml() . '</div>')); $fieldset->addField('status_id', 'select', array('label' => __('Status'), 'required' => true, 'name' => 'status_id', 'values' => $this->_reviewData->getReviewStatusesOptionArray())); /** * Check is single store mode */ if (!$this->_storeManager->isSingleStoreMode()) { $field = $fieldset->addField('select_stores', 'multiselect', array('label' => __('Visible In'), 'required' => true, 'name' => 'select_stores[]', 'values' => $this->_systemStore->getStoreValuesForForm())); $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'); $field->setRenderer($renderer); } $fieldset->addField('nickname', 'text', array('name' => 'nickname', 'title' => __('Nickname'), 'label' => __('Nickname'), 'maxlength' => '50', 'required' => true)); $fieldset->addField('title', 'text', array('name' => 'title', 'title' => __('Summary of Review'), 'label' => __('Summary of Review'), 'maxlength' => '255', 'required' => true)); $fieldset->addField('detail', 'textarea', array('name' => 'detail', 'title' => __('Review'), 'label' => __('Review'), 'style' => 'height: 600px;', 'required' => true)); $fieldset->addField('product_id', 'hidden', array('name' => 'product_id')); /*$gridFieldset = $form->addFieldset('add_review_grid', array('legend' => __('Please select a product'))); $gridFieldset->addField('products_grid', 'note', array( 'text' => $this->getLayout()->createBlock('Magento\Review\Block\Adminhtml\Product\Grid')->toHtml(), ));*/ $form->setMethod('post'); $form->setUseContainer(true); $form->setId('edit_form'); $form->setAction($this->getUrl('review/product/post')); $this->setForm($form); }
/** * Prepare grid mass actions * * @return void */ protected function _prepareMassaction() { $this->setMassactionIdField('review_id'); $this->setMassactionIdFilter('rt.review_id'); $this->setMassactionIdFieldOnlyIndexValue(true); $this->getMassactionBlock()->setFormFieldName('reviews'); $this->getMassactionBlock()->addItem('delete', ['label' => __('Delete'), 'url' => $this->getUrl('*/*/massDelete', ['ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : 'index']), 'confirm' => __('Are you sure?')]); $statuses = $this->_reviewData->getReviewStatusesOptionArray(); array_unshift($statuses, ['label' => '', 'value' => '']); $this->getMassactionBlock()->addItem('update_status', ['label' => __('Update Status'), 'url' => $this->getUrl('*/*/massUpdateStatus', ['ret' => $this->_coreRegistry->registry('usePendingFilter') ? 'pending' : 'index']), 'additional' => ['status' => ['name' => 'status', 'type' => 'select', 'class' => 'required-entry', 'label' => __('Status'), 'values' => $statuses]]]); }
/** * Prepare edit review form * * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareForm() { $review = $this->_coreRegistry->registry('review_data'); $product = $this->_productFactory->create()->load($review->getEntityPkValue()); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getUrl('review/*/save', ['id' => $this->getRequest()->getParam('id'), 'ret' => $this->_coreRegistry->registry('ret')]), 'method' => 'post']]); $fieldset = $form->addFieldset('review_details', ['legend' => __('Review Details'), 'class' => 'fieldset-wide']); $fieldset->addField('product_name', 'note', ['label' => __('Product'), 'text' => '<a href="' . $this->getUrl('catalog/product/edit', ['id' => $product->getId()]) . '" onclick="this.target=\'blank\'">' . $this->escapeHtml($product->getName()) . '</a>']); try { $customer = $this->customerRepository->getById($review->getCustomerId()); $customerText = __('<a href="%1" onclick="this.target=\'blank\'">%2 %3</a> <a href="mailto:%4">(%4)</a>', $this->getUrl('customer/index/edit', ['id' => $customer->getId(), 'active_tab' => 'review']), $this->escapeHtml($customer->getFirstname()), $this->escapeHtml($customer->getLastname()), $this->escapeHtml($customer->getEmail())); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { $customerText = $review->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID ? __('Administrator') : __('Guest'); } $fieldset->addField('customer', 'note', ['label' => __('Author'), 'text' => $customerText]); $fieldset->addField('summary_rating', 'note', ['label' => __('Summary Rating'), 'text' => $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Summary')->toHtml()]); $fieldset->addField('detailed_rating', 'note', ['label' => __('Detailed Rating'), 'required' => true, 'text' => '<div id="rating_detail">' . $this->getLayout()->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->toHtml() . '</div>']); $fieldset->addField('status_id', 'select', ['label' => __('Status'), 'required' => true, 'name' => 'status_id', 'values' => $this->_reviewData->getReviewStatusesOptionArray()]); /** * Check is single store mode */ if (!$this->_storeManager->hasSingleStore()) { $field = $fieldset->addField('select_stores', 'multiselect', ['label' => __('Visibility'), 'required' => true, 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm()]); $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element'); $field->setRenderer($renderer); $review->setSelectStores($review->getStores()); } else { $fieldset->addField('select_stores', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]); $review->setSelectStores($this->_storeManager->getStore(true)->getId()); } $fieldset->addField('nickname', 'text', ['label' => __('Nickname'), 'required' => true, 'name' => 'nickname']); $fieldset->addField('title', 'text', ['label' => __('Summary of Review'), 'required' => true, 'name' => 'title']); $fieldset->addField('detail', 'textarea', ['label' => __('Review'), 'required' => true, 'name' => 'detail', 'style' => 'height:24em;']); $form->setUseContainer(true); $form->setValues($review->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * {@inheritdoc} */ public function toOptionArray() { return $this->source->getReviewStatusesOptionArray(); }