This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Topic;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Topic;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Topic
*/
class Edit extends Container
{
/**
* Core registry
*
* @var Registry
*/
public $coreRegistry;
/**
* Edit constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
parent::__construct($context, $data);
}
/**
* Initialize Topic edit block
*
* @return void
*/
protected function _construct()
{
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_topic';
parent::_construct();
$this->buttonList->add(
'save-and-continue',
[
'label' => __('Save and Continue Edit'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'saveAndContinueEdit',
'target' => '#edit_form'
]
]
]
],
-100
);
}
/**
* Retrieve text for header element depending on loaded Topic
*
* @return string
*/
public function getHeaderText()
{
/** @var Topic $topic */
$topic = $this->coreRegistry->registry('mageplaza_blog_topic');
if ($topic->getId()) {
return __("Edit Topic '%1'", $this->escapeHtml($topic->getName()));
}
return __('New Topic');
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Button;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
/**
* Button "Create Topic" in "New Category" slide-out panel of a product page
*/
class CreateTopic implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Create Topic'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 10
];
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Topic\Edit
*/
class Form extends Generic
{
/**
* @inheritdoc
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create([
'data' => [
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
'enctype' => 'multipart/form-data'
]
]);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
@@ -0,0 +1,285 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Tab;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid\Column;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Backend\Helper\Data;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\PostFactory;
use Mageplaza\Blog\Model\ResourceModel\Post\Collection;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Tab
*/
class Post extends Extended implements TabInterface
{
/**
* Registry
*
* @var Registry
*/
public $coreRegistry;
/**
* Post factory
*
* @var PostFactory
*/
public $postFactory;
/**
* Post constructor.
*
* @param Registry $coreRegistry
* @param PostFactory $postFactory
* @param Context $context
* @param Data $backendHelper
* @param array $data
*/
public function __construct(
Registry $coreRegistry,
PostFactory $postFactory,
Context $context,
Data $backendHelper,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
$this->postFactory = $postFactory;
parent::__construct($context, $backendHelper, $data);
}
/**
* Set grid params
*/
public function _construct()
{
parent::_construct();
$this->setId('post_grid');
$this->setDefaultSort('position');
$this->setDefaultDir('ASC');
$this->setUseAjax(true);
if ($this->getTopic()->getId()) {
$this->setDefaultFilter(['in_posts' => 1]);
}
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->postFactory->create()->getCollection();
$collection->getSelect()->joinLeft(
['related' => $collection->getTable('mageplaza_blog_post_topic')],
'related.post_id=main_table.post_id AND related.topic_id=' . (int) $this->getRequest()->getParam('id', 0),
['position']
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return $this
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn('in_posts', [
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_post',
'values' => $this->_getSelectedPosts(),
'align' => 'center',
'index' => 'post_id'
]);
$this->addColumn('post_id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'post_id',
'type' => 'number',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]);
$this->addColumn('title', [
'header' => __('Name'),
'index' => 'name',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]);
$this->addColumn('position', [
'header' => __('Position'),
'name' => 'position',
'width' => 60,
'type' => 'number',
'validate_class' => 'validate-number',
'index' => 'position',
'editable' => true,
]);
return $this;
}
/**
* Retrieve selected Posts
* @return array
*/
protected function _getSelectedPosts()
{
$posts = $this->getRequest()->getPost('topic_posts', null);
if (!is_array($posts)) {
$posts = $this->getTopic()->getPostsPosition();
return array_keys($posts);
}
return $posts;
}
/**
* Retrieve selected Posts
* @return array
*/
public function getSelectedPosts()
{
$selected = $this->getTopic()->getPostsPosition();
if (!is_array($selected)) {
$selected = [];
} else {
foreach ($selected as $key => $value) {
$selected[$key] = ['position' => $value];
}
}
return $selected;
}
/**
* @param \Mageplaza\Blog\Model\Post|Object $item
*
* @return string
*/
public function getRowUrl($item)
{
return '#';
}
/**
* get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/postsGrid', ['id' => $this->getTopic()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Topic
*/
public function getTopic()
{
return $this->coreRegistry->registry('mageplaza_blog_topic');
}
/**
* @param Column $column
*
* @return $this
* @throws LocalizedException
*/
protected function _addColumnFilterToCollection($column)
{
if ($column->getId() === 'in_posts') {
$postIds = $this->_getSelectedPosts();
if (empty($postIds)) {
$postIds = 0;
}
if ($column->getFilter()->getValue()) {
$this->getCollection()->addFieldToFilter('main_table.post_id', ['in' => $postIds]);
} elseif ($postIds) {
$this->getCollection()->addFieldToFilter('main_table.post_id', ['nin' => $postIds]);
}
} else {
parent::_addColumnFilterToCollection($column);
}
return $this;
}
/**
* @return string
*/
public function getTabLabel()
{
return __('Posts');
}
/**
* @return bool
*/
public function isHidden()
{
return false;
}
/**
* @return string
*/
public function getTabTitle()
{
return $this->getTabLabel();
}
/**
* @return bool
*/
public function canShowTab()
{
return true;
}
/**
* @return string
*/
public function getTabUrl()
{
return $this->getUrl('mageplaza_blog/topic/posts', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
}
@@ -0,0 +1,221 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Tab;
use Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Cms\Model\Wysiwyg\Config;
use Magento\Config\Model\Config\Source\Design\Robots;
use Magento\Config\Model\Config\Source\Enabledisable;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Registry;
use Magento\Store\Model\System\Store;
/**
* Class Topic
* @package Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Tab
*/
class Topic extends Generic implements TabInterface
{
/**
* Wysiwyg config
*
* @var Config
*/
protected $wysiwygConfig;
/**
* Country options
*
* @var Yesno
*/
protected $booleanOptions;
/**
* @var Enabledisable
*/
protected $enableDisable;
/**
* @var Robots
*/
protected $metaRobotsOptions;
/**
* @var Store
*/
protected $systemStore;
/**
* Topic constructor.
*
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Config $wysiwygConfig
* @param Yesno $booleanOptions
* @param Enabledisable $enableDisable
* @param Robots $metaRobotsOptions
* @param Store $systemStore
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Config $wysiwygConfig,
Yesno $booleanOptions,
Enabledisable $enableDisable,
Robots $metaRobotsOptions,
Store $systemStore,
array $data = []
) {
$this->wysiwygConfig = $wysiwygConfig;
$this->booleanOptions = $booleanOptions;
$this->enableDisable = $enableDisable;
$this->metaRobotsOptions = $metaRobotsOptions;
$this->systemStore = $systemStore;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @inheritdoc
*/
protected function _prepareForm()
{
/** @var \Mageplaza\Blog\Model\Topic $topic */
$topic = $this->_coreRegistry->registry('mageplaza_blog_topic');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('topic_');
$form->setFieldNameSuffix('topic');
$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Topic Information'),
'class' => 'fieldset-wide'
]);
if ($topic->getId()) {
$fieldset->addField('topic_id', 'hidden', ['name' => 'topic_id']);
}
$fieldset->addField('name', 'text', [
'name' => 'name',
'label' => __('Name'),
'title' => __('Name'),
'required' => true,
]);
$fieldset->addField('url_key', 'text', [
'name' => 'url_key',
'label' => __('URL Key'),
'title' => __('URL Key')
]);
$fieldset->addField('enabled', 'select', [
'name' => 'enabled',
'label' => __('Status'),
'title' => __('Status'),
'values' => $this->enableDisable->toOptionArray(),
]);
if (!$topic->hasData('enabled')) {
$topic->setEnabled(1);
}
$fieldset->addField('description', 'editor', [
'name' => 'description',
'label' => __('Description'),
'title' => __('Description'),
'config' => $this->wysiwygConfig->getConfig(['add_variables' => false, 'add_widgets' => false])
]);
if (!$this->_storeManager->isSingleStoreMode()) {
/** @var RendererInterface $rendererBlock */
$rendererBlock = $this->getLayout()->createBlock(
Element::class
);
$fieldset->addField('store_ids', 'multiselect', [
'name' => 'store_ids',
'label' => __('Store Views'),
'title' => __('Store Views'),
'values' => $this->systemStore->getStoreValuesForForm(false, true)
])->setRenderer($rendererBlock);
if (!$topic->hasData('store_ids')) {
$topic->setStoreIds(0);
}
} else {
$fieldset->addField('store_ids', 'hidden', [
'name' => 'store_ids',
'value' => $this->_storeManager->getStore()->getId()
]);
}
$form->addValues($topic->getData());
$this->setForm($form);
$this->_eventManager->dispatch('adminhtml_blog_edit_form_prepare_form', ['block' => $this]);
return parent::_prepareForm();
}
/**
* Prepare label for tab
*
* @return string
*/
public function getTabLabel()
{
return __('Topic');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return $this->getTabLabel();
}
/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
return true;
}
/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
}
@@ -0,0 +1,43 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Topic\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('topic_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Topic Information'));
}
}