From 299b3208e6ebc603e86fe1700fa2556a58b250fc Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Tue, 18 Feb 2025 17:29:22 +0200 Subject: [PATCH 1/2] 11873-Move-All-Form-Options-From-Plus-And-Extra-To-Basic --- Block/Adminhtml/Post/RelatedProductsRule.php | 200 ++++++++++++ Model/Config/Source/Authors.php | 73 +++++ Model/Config/Source/CustomerGroups.php | 60 ++++ Model/Config/Source/NoYes.php | 40 +++ Model/Config/Source/PostsSortBy.php | 12 + etc/di.xml | 154 +++++++++ view/adminhtml/layout/blog_category_edit.xml | 3 + view/adminhtml/layout/blog_post_edit.xml | 3 + view/adminhtml/layout/blog_tag_edit.xml | 3 + .../templates/form/versionsManager.phtml | 146 +++++++++ .../ui_component/blog_category_form.xml | 297 ++++++++++++++++++ .../adminhtml/ui_component/blog_post_form.xml | 244 ++++++++++++++ view/adminhtml/ui_component/blog_tag_form.xml | 60 ++++ .../js/components/url-key-handle-changes.js | 44 +++ 14 files changed, 1339 insertions(+) create mode 100644 Block/Adminhtml/Post/RelatedProductsRule.php create mode 100755 Model/Config/Source/Authors.php create mode 100644 Model/Config/Source/CustomerGroups.php create mode 100644 Model/Config/Source/NoYes.php create mode 100644 view/adminhtml/templates/form/versionsManager.phtml create mode 100644 view/adminhtml/web/js/components/url-key-handle-changes.js diff --git a/Block/Adminhtml/Post/RelatedProductsRule.php b/Block/Adminhtml/Post/RelatedProductsRule.php new file mode 100644 index 00000000..ffc4decd --- /dev/null +++ b/Block/Adminhtml/Post/RelatedProductsRule.php @@ -0,0 +1,200 @@ +rendererFieldset = $rendererFieldset; + $this->conditions = $conditions; + $this->ruleFactory = $ruleFactory; + parent::__construct($context, $registry, $formFactory, $data); + } + + /** + * {@inheritdoc} + * @codeCoverageIgnore + */ + public function getTabClass() + { + return null; + } + + /** + * {@inheritdoc} + */ + public function getTabUrl() + { + return null; + } + + /** + * {@inheritdoc} + */ + public function isAjaxLoaded() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function getTabLabel() + { + return __('Conditions'); + } + + /** + * {@inheritdoc} + */ + public function getTabTitle() + { + return __('Conditions'); + } + + /** + * {@inheritdoc} + */ + public function canShowTab() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isHidden() + { + return false; + } + + /** + * Prepare form before rendering HTML + * + * @return $this + */ + protected function _prepareForm() + { + $model = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); + $form = $this->addTabToForm($model); + $this->setForm($form); + + return parent::_prepareForm(); + } + + /** + * Handles addition of conditions tab to supplied form. + * + * @param \Magento\SalesRule\Model\Rule $model + * @param string $fieldsetId + * @param string $formName + * @return \Magento\Framework\Data\Form + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function addTabToForm($model, $fieldsetId = 'rp_conditions_serialized_fieldset', $formName = 'blog_post_form') + { + + $model = $this->_coreRegistry->registry('current_model'); + $rule = $this->ruleFactory->create(); + $rule->setData('conditions_serialized', $model->getData('rp_conditions_serialized')); + $model = $rule; + $conditionsFieldSetId = $model->getConditionsFieldSetId($formName); + $newChildUrl = $this->getUrl( + 'sales_rule/promo_quote/newConditionHtml/form/' . $conditionsFieldSetId, + ['form_namespace' => $formName] + ); + + /** @var \Magento\Framework\Data\Form $form */ + $form = $this->_formFactory->create(); + $form->setHtmlIdPrefix('rule_'); + $renderer = $this->rendererFieldset->setTemplate( + 'Magento_CatalogRule::promo/fieldset.phtml' + )->setNameInLayout( + 'rp_condition_block' + )->setNewChildUrl( + $newChildUrl + )->setFieldSetId( + $conditionsFieldSetId + ); + + $fieldset = $form->addFieldset( + $fieldsetId, + [ + 'legend' => __( + 'Apply the rule only if the following conditions are met (leave blank to disable rule conditions).' + ) + ] + )->setRenderer( + $renderer + ); + $fieldset->addField( + 'rp_conditions_serialized', + 'text', + [ + 'name' => 'rp_conditions_serialized', + 'label' => __('Conditions'), + 'title' => __('Conditions'), + 'required' => true, + 'data-form-part' => $formName + ] + )->setRule( + $model + )->setRenderer( + $this->conditions + ); + + $form->setValues($model->getData()); + $this->setConditionFormName($model->getConditions(), $formName); + + return $form; + } + + /** + * Handles addition of form name to condition and its conditions. + * + * @param \Magento\Rule\Model\Condition\AbstractCondition $conditions + * @param string $formName + * @return void + */ + private function setConditionFormName(\Magento\Rule\Model\Condition\AbstractCondition $conditions, $formName) + { + $conditions->setFormName($formName); + if ($conditions->getConditions() && is_array($conditions->getConditions())) { + foreach ($conditions->getConditions() as $condition) { + $this->setConditionFormName($condition, $formName); + } + } + } +} diff --git a/Model/Config/Source/Authors.php b/Model/Config/Source/Authors.php new file mode 100755 index 00000000..234abe7d --- /dev/null +++ b/Model/Config/Source/Authors.php @@ -0,0 +1,73 @@ +authorCollectionFactory = $authorCollectionFactory; + } + + /** + * Options getter + * + * @return array + */ + public function toOptionArray() + { + if ($this->options === null) { + $collection = $this->authorCollectionFactory->create(); + + foreach ($collection as $item) { + $this->options[] = [ + 'label' => $item->getName(), + 'value' => $item->getId(), + ]; + } + } + + return $this->options; + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toArray() + { + $array = []; + foreach ($this->toOptionArray() as $item) { + $array[$item['value']] = $item['label']; + } + return $array; + } +} diff --git a/Model/Config/Source/CustomerGroups.php b/Model/Config/Source/CustomerGroups.php new file mode 100644 index 00000000..5bf45dc3 --- /dev/null +++ b/Model/Config/Source/CustomerGroups.php @@ -0,0 +1,60 @@ +groupRepository = $groupRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->objectConverter = $objectConverter; + } + + /** + * @return array + */ + public function toOptionArray() + { + $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems(); + $options = $this->objectConverter->toOptionArray($customerGroups, 'id', 'code'); + foreach ($options as $key => $option) { + if (!$option['value']) { + $options[$key]['label'] = __('All Groups'); + break; + } + } + + return $options; + } +} diff --git a/Model/Config/Source/NoYes.php b/Model/Config/Source/NoYes.php new file mode 100644 index 00000000..2ce4a859 --- /dev/null +++ b/Model/Config/Source/NoYes.php @@ -0,0 +1,40 @@ + self::DISABLED, 'label' => __('No')], + ['value' => self::ENABLED, 'label' => __('Yes')], + ]; + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toArray() + { + $array = []; + foreach ($this->toOptionArray() as $item) { + $array[$item['value']] = $item['label']; + } + return $array; + } +} diff --git a/Model/Config/Source/PostsSortBy.php b/Model/Config/Source/PostsSortBy.php index 8efb1bd6..ce960be2 100644 --- a/Model/Config/Source/PostsSortBy.php +++ b/Model/Config/Source/PostsSortBy.php @@ -28,6 +28,16 @@ class PostsSortBy implements \Magento\Framework\Option\ArrayInterface */ const TITLE = 2; + /** + * @const int + */ + const END_DATE_ASC = 100; + + /** + * @const int + */ + const END_DATE_DESC = 101; + /** * Options int * @@ -39,6 +49,8 @@ public function toOptionArray() ['value' => self::PUBLISH_DATE, 'label' => __('Publish Date (default)')], ['value' => self::POSITION, 'label' => __('Position')], ['value' => self::TITLE, 'label' => __('Title')], + ['value' => self::END_DATE_ASC, 'label' => __('End Date - Ascending orde - Blog Extra')], + ['value' => self::END_DATE_DESC, 'label' => __('End Date - Descending order - Blog Extra')] ]; } diff --git a/etc/di.xml b/etc/di.xml index 9f1610d2..3ceb1e74 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -88,6 +88,133 @@ list-modern Magefan_Blog::post/list-modern.phtml + + block-0-1-full - Blog Extra + block-0-1-full + Magefan_BlogExtra::post/list/block-0-1-full.phtml + + + block-0-2-full - Blog Extra + block-0-2-full + Magefan_BlogExtra::post/list/block-0-2-full.phtml + + + block-0-4-row-full - Blog Extra + block-0-4-row-full + Magefan_BlogExtra::post/list/block-0-4-row-full.phtml + + + block-0-5-full - Blog Extra + block-0-5-full + Magefan_BlogExtra::post/list/block-0-5-full.phtml + + + block-0-6-full - Blog Extra + block-0-6-full + Magefan_BlogExtra::post/list/block-0-6-full.phtml + + + block-1-1-full - Blog Extra + block-1-1-full + Magefan_BlogExtra::post/list/block-1-1-full.phtml + + + block-1-2-full - Blog Extra + block-1-2-full + Magefan_BlogExtra::post/list/block-1-2-full.phtml + + + block-1-3-full - Blog Extra + block-1-3-full + Magefan_BlogExtra::post/list/block-1-3-full.phtml + + + block-2-1-full - Blog Extra + block-2-1-full + Magefan_BlogExtra::post/list/block-2-1-full.phtml + + + block-2-2-full - Blog Extra + block-2-2-full + Magefan_BlogExtra::post/list/block-2-2-full.phtml + + + block-2-3 - Blog Extra + block-2-3 + Magefan_BlogExtra::post/list/block-2-3.phtml + + + + block-2-1-shortcontent - Blog Extra + block-2-1-shortcontent + Magefan_BlogExtra::post/list/block-2-1-shortcontent.phtml + + + block-2-2-shortcontent - Blog Extra + block-2-2-shortcontent + Magefan_BlogExtra::post/list/block-2-2-shortcontent.phtml + + + block-2-3-shortcontent - Blog Extra + block-2-3-shortcontent + Magefan_BlogExtra::post/list/block-2-3-shortcontent.phtml + + + + block-3-1-full - Blog Extra + block-3-1-full + Magefan_BlogExtra::post/list/block-3-1-full.phtml + + + block-3-2 - Blog Extra + block-3-2 + Magefan_BlogExtra::post/list/block-3-2.phtml + + + block-3-3 - Blog Extra + block-3-3 + Magefan_BlogExtra::post/list/block-3-3.phtml + + + block-3-4 - Blog Extra + block-3-4 + Magefan_BlogExtra::post/list/block-3-4-full.phtml + + + block-3-5 - Blog Extra + block-3-5 + Magefan_BlogExtra::post/list/block-3-5-full.phtml + + + block-3-6 - Blog Extra + block-3-6 + Magefan_BlogExtra::post/list/block-3-6.phtml + + + block-4-1 - Blog Extra + block-4-1 + Magefan_BlogExtra::post/list/block-4-1.phtml + + + block-4-2-full - Blog Extra + block-4-2-full + Magefan_BlogExtra::post/list/block-4-2-full.phtml + + + block-5-1-full - Blog Extra + block-5-1-full + Magefan_BlogExtra::post/list/block-5-1-full.phtml + + + block-5-2 - Blog Extra + block-5-2 + Magefan_BlogExtra::post/list/block-5-2.phtml + + + block-5-3 - Blog Extra + block-5-3 + Magefan_BlogExtra::post/list/block-5-3.phtml + @@ -119,6 +246,11 @@ + + Modern - Blog Extra + modern + Magefan_BlogExtra::post/view/relatedposts-modern.phtml + @@ -126,6 +258,28 @@ + + Carousel Slider - Blog Extra + carousel + Magefan_BlogExtra::post/list/carousel-slider.phtml + + + Modern - Blog Extra + modern + Magefan_BlogExtra::sidebar/recent-modern.phtml + + + + + Use System Settings + + + + + Modern - Blog Extra + modern + Magefan_BlogExtra::post/view/categoryposts-modern.phtml + diff --git a/view/adminhtml/layout/blog_category_edit.xml b/view/adminhtml/layout/blog_category_edit.xml index 417cce40..a3fa0432 100644 --- a/view/adminhtml/layout/blog_category_edit.xml +++ b/view/adminhtml/layout/blog_category_edit.xml @@ -12,6 +12,9 @@ + + + diff --git a/view/adminhtml/layout/blog_post_edit.xml b/view/adminhtml/layout/blog_post_edit.xml index bd59d1a2..da6078ad 100644 --- a/view/adminhtml/layout/blog_post_edit.xml +++ b/view/adminhtml/layout/blog_post_edit.xml @@ -16,6 +16,9 @@ + + + diff --git a/view/adminhtml/layout/blog_tag_edit.xml b/view/adminhtml/layout/blog_tag_edit.xml index 93ecaca1..6697199a 100644 --- a/view/adminhtml/layout/blog_tag_edit.xml +++ b/view/adminhtml/layout/blog_tag_edit.xml @@ -12,6 +12,9 @@ + + + diff --git a/view/adminhtml/templates/form/versionsManager.phtml b/view/adminhtml/templates/form/versionsManager.phtml new file mode 100644 index 00000000..981effc3 --- /dev/null +++ b/view/adminhtml/templates/form/versionsManager.phtml @@ -0,0 +1,146 @@ + + + +get(\Magefan\Community\Api\GetModuleVersionInterface::class); + +$currentPlan = 'Basic'; + +if ($getModuleVersion->execute('Magefan_BlogExtra')) { + return; +} elseif ($getModuleVersion->execute('Magefan_BlogPlus')) { + $currentPlan = 'Plus'; +} +?> + + { + mutations.forEach(mutation => { + for (let plan in versionsManager._selector) { + let planFeatures = versionsManager._selector[plan]; + + planFeatures.forEach(selector => { + var elements = document.querySelectorAll(selector); + if (elements.length > 0) { + elements.forEach(element => { + + if (uploadElements.includes(selector)) { + const clonedElement = element.cloneNode(true); + element.parentNode.replaceChild(clonedElement, element); + element = clonedElement; + } + const handleEvent = function (event) { + event.preventDefault(); + event.stopPropagation(); + if (element.tagName === 'SELECT') { + var selectedOptionText = this.options[this.selectedIndex].text; + if (selectedOptionText.includes('Blog '+ plan)) { + versionsManager.showAlert(plan); + this.selectedIndex = 0; + this.dispatchEvent(new Event('change', { bubbles: true })); + } + } else { + this.value = ''; + if (versionsManager._currentPlan !== plan) { + versionsManager.showAlert(plan); + } + } + }; + + if (element.tagName === 'SELECT') { + element.addEventListener('change', handleEvent); + } else { + element.addEventListener('click', handleEvent); + } + }); + + versionsManager._selector[plan] = versionsManager._selector[plan].filter(item => item !== selector); + } + }); + } + }); + }); + + observer.observe(document.body, { childList: true, subtree: true }); + }, + + showAlert: function (extensionPlan) { + require(['jquery', 'Magento_Ui/js/modal/alert'], function($, alert) { + if (extensionPlan === 'Plus') { + extensionPlan = 'Plus or Extra'; + } + alert({ + title: 'You cannot use this option.', + content: 'This feature is available in' + ' ' + extensionPlan + ' plan only.', + buttons: [{ + text: 'Upgrade Plan Now', + class: 'action primary accept', + click: function () { + window.open('https://magefan.com'); + } + }] + }); + }); + } + }; + + versionsManager.initListener(); + + "; +?> + +renderTag('script', [], $script, false) ?> \ No newline at end of file diff --git a/view/adminhtml/ui_component/blog_category_form.xml b/view/adminhtml/ui_component/blog_category_form.xml index 102a9cfd..a0490f9e 100644 --- a/view/adminhtml/ui_component/blog_category_form.xml +++ b/view/adminhtml/ui_component/blog_category_form.xml @@ -322,6 +322,87 @@ + + + Magefan\Blog\Model\Config\Source\CustomerGroups + + Visible For Customer Groups (Blog Plus) + number + multiselect + + true + + post + groups + 0 + + + + + + + true + Category Image (Blog Plus) + 10 + magefan_blog_category + + + + ui/form/element/uploader/image + string + + true + false + + + + + false + + + + Magento_Catalog/image-preview + Category Image + magefan_blog + jpg jpeg png + 4194304 + + + + + + + + text + Category Image Alt (Blog Plus) + input + post + category_img_alt + 15 + + + + +
+ + + true + Bottom Content (Blog Plus) + 30 + + + + + + + wysiwyg + category + true + bottom_content + admin__field-wide + + +
@@ -351,6 +432,22 @@ + + + boolean + + + + + Create Permanent Redirect for old URL (Blog Plus) + + 0 + 1 + + + + + @@ -524,4 +621,204 @@
+
+ + + true + Posts in Category (Blog Extra) + 45 + + + +
+ + + false + Posts + admin__fieldset-section category + 20 + + + + + + + false + Assign posts to the blog category. + ui/form/components/complex + + + + + + Add Posts + Magento_Ui/js/form/components/button + + + blog_category_form.blog_category_form.related.product.modal + toggleModal + + + blog_category_form.blog_category_form.related.product.modal.blog_related_category_listing + render + + + false + + + + + + + + + + Magento_Ui/js/modal/modal-component + + Add Related Posts + + + Cancel + + closeModal + + + + Add Selected Posts + action-primary + + + index=blog_related_category_listing + save + + closeModal + + + + + + + + + + false + blog_related_post_listing + blog_related_post_listing.blog_related_post_listing_data_source + blog_related_post_listing.blog_related_post_listing.post_columns.ids + blog_related_post_listing + + true + + false + true + + simple + true + + ${ $.provider }:data.post.current_post_id + + + ${ $.externalProvider }:data.post.current_post_id + + Magento_Ui/js/form/components/insert-listing + + + + + + + + + admin__field-wide + dynamicRows + + false + false + true + false + ui/dynamic-rows/templates/grid + Magento_Ui/js/dynamic-rows/dynamic-rows-grid + false + record + data.links + Remove + data.blog_related_post_listing + + post_id + title + status + + + ${ $.provider }:${ $.dataProvider } + + + 2 + + + + + + true + true + Magento_Ui/js/dynamic-rows/record + container + + + + + + + input + ui/dynamic-rows/cells/text + Magento_Ui/js/form/element/text + text + id + false + ID + 10 + + + + + + + input + ui/dynamic-rows/cells/text + Magento_Ui/js/form/element/text + text + title + false + Title + 20 + + + + + + + data-grid-actions-cell + text + Actions + true + 80 + + + + + + + input + number + position + true + Thumbnail + 90 + false + + + + + +
+
diff --git a/view/adminhtml/ui_component/blog_post_form.xml b/view/adminhtml/ui_component/blog_post_form.xml index 29cb9601..f088ded3 100755 --- a/view/adminhtml/ui_component/blog_post_form.xml +++ b/view/adminhtml/ui_component/blog_post_form.xml @@ -287,6 +287,150 @@ + + + + true + Featured List Image (Blog Plus) + 16 + magefan_blog_post + + + + ui/form/element/uploader/image + string + + true + false + + + + + false + + + + Magento_Catalog/image-preview + Featured List Image (Blog Plus) + magefan_blog + jpg jpeg png + 4194304 + + + + + + + + text + Featured List Image Alt (Blog Plus) + input + post + featured_list_img_alt + 17 + + + + + + + Publish Date (Blog Plus) + text + date + post + publish_time + 20 + + + true + + + + + + + Magefan\Blog\Model\Config\Source\CustomerGroups + + Visible For Customer Groups (Blog Plus) + number + multiselect + + true + + post + groups + 0 + + + + + + Magento\Config\Model\Config\Source\Yesno + + text + Enable Comments (Blog Plus) + select + enable_comments + true + 1 + 65 + + + + + + + End Date (Blog Extra) + text + date + post + end_time + 25 + You can set an end date of the publication. The post will not be available for reading after this date. + + true + + + + + + + + + false + container + Magento_Ui/js/form/components/group + 34 + + + + + Magefan\Blog\Model\Config\Source\Authors + + Co-Authors (Blog Extra) + select + Magefan_Blog/js/components/new-category + ui/grid/filters/elements/ui-select + coauthors + true + true + true + true + true + 1 + 35 + false + + setParsed + toggleOptionSelected + + + + +