This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,161 @@
<?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_RewardPoints
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Helper\Data;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
use Magento\Framework\Registry;
/**
* Class CustomerGrid
* @package Mageplaza\Blog\Block\Adminhtml\Author
*/
class CustomerGrid extends Extended
{
/**
* Core registry
* @var Registry
*/
protected $_coreRegistry = null;
/**
* @var CustomerCollectionFactory
*/
protected $_customerCollectionFactory;
/**
* @var CollectionFactory
*/
protected $customerGroup;
/**
* CustomerGrid constructor.
*
* @param Context $context
* @param Data $backendHelper
* @param CustomerCollectionFactory $customerFactory
* @param CollectionFactory $customerGroup
* @param array $data
*/
public function __construct(
Context $context,
Data $backendHelper,
CustomerCollectionFactory $customerFactory,
CollectionFactory $customerGroup,
array $data = []
) {
$this->_customerCollectionFactory = $customerFactory;
$this->customerGroup = $customerGroup;
parent::__construct($context, $backendHelper, $data);
}
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('customer-grid');
$this->setDefaultSort('entity_id');
$this->setUseAjax(true);
}
/**
* @return Grid
*/
protected function _prepareCollection()
{
$collection = $this->_customerCollectionFactory->create();
$collection->getSelect()->joinLeft(
['author' => $collection->getTable('mageplaza_blog_author')],
'e.entity_id = author.customer_id',
['author.user_id AS user_id']
)->where('author.user_id IS NULL')->getConnection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return Extended
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn('customer_id', [
'header_css_class' => 'a-center',
'type' => 'radio',
'html_name' => 'customer_id',
'align' => 'center',
'index' => 'entity_id',
'filter' => false,
'sortable' => false
]);
$this->addColumn('entity_id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'entity_id'
]);
$this->addColumn('firstname', [
'header' => __('First Name'),
'index' => 'firstname',
'type' => 'text',
'sortable' => true,
]);
$this->addColumn('lastname', [
'header' => __('Last Name'),
'index' => 'lastname',
'type' => 'text',
'sortable' => true,
]);
$this->addColumn('email', [
'header' => __('Email'),
'index' => 'email',
'type' => 'text',
'sortable' => true,
]);
$this->addColumn('group_id', [
'header' => __('Group'),
'index' => 'group_id',
'type' => 'options',
'options' => $this->customerGroup->create()->toOptionHash(),
'sortable' => true,
]);
return parent::_prepareColumns();
}
/**
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('mageplaza_blog/author/customergrid', ['_current' => true]);
}
}
+120
View File
@@ -0,0 +1,120 @@
<?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\Author;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Author;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Author
*/
class Edit extends Container
{
/**
* @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 Post edit block
*
* @return void
*/
protected function _construct()
{
$this->_objectId = 'user_id';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_author';
parent::_construct();
$this->buttonList->add('save-and-continue', [
'label' => __('Save And Continue Edit'),
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'saveAndContinueEdit',
'target' => '#edit_form'
]
]
]
], -100);
$this->buttonList->add(
'delete',
[
'label' => __('Delete'),
'class' => 'delete',
'onclick' => "setLocation('{$this->getUrl('mageplaza_blog/author/delete', [
'id' => $this->getCurrentAuthor()->getId(),
'_current' => true,
'back' => 'edit'
])}')",
],
-101
);
}
/**
* Retrieve text for header element depending on loaded Post
*
* @return string
*/
public function getHeaderText()
{
/** @var Author $author */
$author = $this->getCurrentAuthor();
if ($author->getId()) {
return __("Edit Author '%1'", $this->escapeHtml($author->getName()));
}
return __('New Author');
}
/**
* @return Author
*/
public function getCurrentAuthor()
{
return $this->coreRegistry->registry('mageplaza_blog_author');
}
}
@@ -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\Author\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Author\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,332 @@
<?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\Author\Edit\Tab;
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\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Data\Form;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\System\Store;
use Mageplaza\Blog\Block\Adminhtml\Renderer\Image;
use Mageplaza\Blog\Helper\Data;
use Mageplaza\Blog\Helper\Image as ImageHelper;
use Mageplaza\Blog\Model\Config\Source\AuthorStatus;
/**
* Class Author
* @package Mageplaza\Blog\Block\Adminhtml\Author\Edit\Tab
*/
class Author extends Generic implements TabInterface
{
/**
* @var Store
*/
public $systemStore;
/**
* @var Config
*/
public $wysiwygConfig;
/**
* @var ImageHelper
*/
protected $imageHelper;
/**
* @var AuthorStatus
*/
protected $authorStatus;
/**
* @var Data
*/
protected $_helperData;
/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;
/**
* Author constructor.
*
* @param Config $wysiwygConfig
* @param Store $systemStore
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param ImageHelper $imageHelper
* @param AuthorStatus $authorStatus
* @param Data $helperData
* @param CustomerRepositoryInterface $customerRepository
* @param array $data
*/
public function __construct(
Config $wysiwygConfig,
Store $systemStore,
Context $context,
Registry $registry,
FormFactory $formFactory,
ImageHelper $imageHelper,
AuthorStatus $authorStatus,
Data $helperData,
CustomerRepositoryInterface $customerRepository,
array $data = []
) {
$this->wysiwygConfig = $wysiwygConfig;
$this->systemStore = $systemStore;
$this->imageHelper = $imageHelper;
$this->authorStatus = $authorStatus;
$this->_helperData = $helperData;
$this->customerRepository = $customerRepository;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @inheritdoc
*/
protected function _prepareForm()
{
/** @var \Mageplaza\Blog\Model\Author $author */
$author = $this->_coreRegistry->registry('mageplaza_blog_author');
/** @var Form $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('author_');
$form->setFieldNameSuffix('author');
$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Author Information'),
'class' => 'fieldset-wide'
]);
if ($author->getId()) {
$fieldset->addField('user_id', 'hidden', ['name' => 'user_id']);
}
if ($this->checkCustomerId($author->getCustomerId())) {
$fieldset->addField('customer_id', 'hidden', [
'name' => 'customer_id',
'value' => $author->getCustomerId()
]);
$customer = $this->customerRepository->getById($author->getCustomerId());
$fieldset->addField('customer', 'label', [
'name' => 'customer',
'label' => __('Customer'),
'title' => __('Customer'),
'value' => $customer->getFirstname() . ' ' . $customer->getLastname()
]);
} else {
$fieldset->addField('customer', 'text', [
'name' => 'customer',
'label' => __('Customer'),
'title' => __('Customer')
])->setAfterElementHtml(
'<div id="customer-grid" style="display:none"></div>
<script type="text/x-magento-init">
{
"#author_customer": {
"Mageplaza_Blog/js/view/author":{
"url": "' . $this->getAjaxUrl() . '"
}
}
}
</script>'
);
$fieldset->addField('customer_id', 'hidden', [
'name' => 'customer_id',
'value' => 0
]);
}
$fieldset->addField('name', 'text', [
'name' => 'name',
'label' => __('Display Name'),
'title' => __('Display Name'),
'required' => true,
'note' => __('This name will be displayed on frontend')
]);
$fieldset->addField('status', 'select', [
'name' => 'status',
'label' => __('Status'),
'title' => __('Status'),
'values' => $this->authorStatus->toArray()
]);
$fieldset->addField('type', 'hidden', [
'name' => 'type',
'value' => 0
]);
$fieldset->addField('short_description', 'editor', [
'name' => 'short_description',
'label' => __('Short Description'),
'title' => __('Short Description'),
'note' => __('Short Description'),
'config' => $this->wysiwygConfig->getConfig([
'add_variables' => false,
'add_widgets' => false,
'add_directives' => true
])
]);
$fieldset->addField('image', Image::class, [
'name' => 'image',
'label' => __('Avatar'),
'title' => __('Avatar'),
'path' => $this->imageHelper->getBaseMediaPath(ImageHelper::TEMPLATE_MEDIA_TYPE_AUTH)
]);
$fieldset->addField('url_key', 'text', [
'name' => 'url_key',
'label' => __('URL Key'),
'title' => __('URL Key')
]);
$authorUrlFormat = $this->_storeManager->getDefaultStoreView()->getBaseUrl(UrlInterface::URL_TYPE_LINK)
. 'blog/author/';
$urlSuffix = $this->_helperData->getUrlSuffix();
$fieldset->addField(
'full_url',
'label',
[
'label' => __('Full URL'),
'value' => $author->getUrlKey() ? $authorUrlFormat . $author->getUrlKey() . $urlSuffix : ''
]
)->setAfterElementHtml(
"<script>
require(['jquery'], function($){
$('#author_url_key').on('keyup', function() {
var url = '" . $authorUrlFormat . "'+$(this).val()+'" . $urlSuffix . "';
if ($(this).val() === ''){
url = '';
}
$('.field-full_url .control-value').html(url);
});
});
</script>"
);
$fieldset->addField('facebook_link', 'text', [
'name' => 'facebook_link',
'label' => __('Facebook'),
'title' => __('Facebook'),
'note' => __('Facebook URL'),
'required' => false,
'class' => 'validate-url'
]);
$fieldset->addField('twitter_link', 'text', [
'name' => 'twitter_link',
'label' => __('Twitter'),
'title' => __('Twitter'),
'note' => __('Twitter URL'),
'required' => false,
'class' => 'validate-url'
]);
$form->addValues($author->getData());
$this->setForm($form);
return parent::_prepareForm();
}
/**
* @param $customerId
*
* @return bool
* @throws LocalizedException
*/
public function checkCustomerId($customerId)
{
try {
if ($this->customerRepository->getById($customerId)) {
return true;
}
} catch (NoSuchEntityException $noSuchEntityException) {
return false;
}
return false;
}
/**
* Prepare label for tab
*
* @return string
*/
public function getTabLabel()
{
return __('Author Info');
}
/**
* 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;
}
/**
* Get transaction grid url
* @return string
*/
public function getAjaxUrl()
{
return $this->getUrl('mageplaza_blog/author/customergrid');
}
}
@@ -0,0 +1,217 @@
<?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\Author\Edit\Tab;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Backend\Helper\Data;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\PostFactory;
use Mageplaza\Blog\Model\ResourceModel\Post\Collection;
use Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Tab
*/
class Post extends Extended implements TabInterface
{
/**
* Post collection factory
*
* @var CollectionFactory
*/
public $postCollectionFactory;
/**
* Registry
*
* @var Registry
*/
public $coreRegistry;
/**
* Post factory
*
* @var PostFactory
*/
public $postFactory;
/**
* Post constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param Data $backendHelper
* @param PostFactory $postFactory
* @param CollectionFactory $postCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Data $backendHelper,
PostFactory $postFactory,
CollectionFactory $postCollectionFactory,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
$this->postFactory = $postFactory;
$this->postCollectionFactory = $postCollectionFactory;
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);
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->postCollectionFactory->create();
$collection->addFieldToFilter('author_id', $this->getAuthor()->getId());
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return $this
* @throws Exception
*/
protected function _prepareColumns()
{
$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('publish_date', [
'header' => __('Published'),
'index' => 'publish_date',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]);
return $this;
}
/**
* @param \Mageplaza\Blog\Model\Post|Object $item
*
* @return string
*/
public function getRowUrl($item)
{
return $this->getUrl('mageplaza_blog/post/edit', ['id' => $item->getId()]);
}
/**
* get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/postsgrid', ['id' => $this->getAuthor()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Author
*/
public function getAuthor()
{
return $this->coreRegistry->registry('mageplaza_blog_author');
}
/**
* @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/author/posts', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
}
@@ -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\Author\Edit;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Author\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('author_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Author Information'));
}
}
+46
View File
@@ -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;
use Magento\Backend\Block\Widget\Grid\Container;
/**
* Class Category
* @package Mageplaza\Blog\Block\Adminhtml
*/
class Category extends Container
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
$this->_controller = 'adminhtml_category';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_headerText = __('Categories');
$this->_addButtonLabel = __('Create New Blog Category');
parent::_construct();
}
}
+121
View File
@@ -0,0 +1,121 @@
<?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\Category;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Helper\Data;
use Mageplaza\Blog\Model\Category;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Category
*/
class Edit extends Container
{
/**
* Core registry
*
* @var Registry
*/
public $coreRegistry;
/**
* @var Data
*/
protected $_helperData;
/**
* Edit constructor.
*
* @param Registry $coreRegistry
* @param Data $helperData
* @param Context $context
* @param array $data
*/
public function __construct(
Registry $coreRegistry,
Data $helperData,
Context $context,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
$this->_helperData = $helperData;
parent::__construct($context, $data);
}
/**
* prepare the form
*/
protected function _construct()
{
$this->_objectId = 'id';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_category';
parent::_construct();
/** @var Category $category */
$category = $this->coreRegistry->registry('category');
if ($category->getId() && !$category->getDuplicate()) {
$this->buttonList->add(
'duplicate',
[
'label' => __('Duplicate'),
'class' => 'duplicate',
'onclick' => sprintf("location.href = '%s';", $this->getDuplicateUrl()),
],
-101
);
}
$this->buttonList->remove('delete');
$this->buttonList->remove('back');
$this->buttonList->remove('reset');
$this->buttonList->remove('save');
}
/**
* @return string
*/
protected function getDuplicateUrl()
{
/** @var Category $category */
$category = $this->coreRegistry->registry('category');
return $this->getUrl(
'*/*/duplicate',
['id' => $category->getId(), 'duplicate' => true, 'parent' => $category->getParentId()]
);
}
/**
* @return int
*/
public function getMagentoVersion()
{
return (int)$this->_helperData->versionCompare('2.4.0', '>=') ? '' : '4';
}
}
@@ -0,0 +1,361 @@
<?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\Category\Edit;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Button;
use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category\Tree;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Phrase;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\BlockInterface;
use Mageplaza\Blog\Model\Category as BlogCategory;
use Mageplaza\Blog\Model\CategoryFactory as BlogCategoryFactory;
use Mageplaza\Blog\Model\ResourceModel\Category\Tree as BlogResourceTree;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Category\Edit
*/
class Form extends AbstractCategory
{
/**
* @var array Additional buttons
*/
public $additionalButtons = [];
/**
* @var string Block template
*/
protected $_template = 'category/edit/form.phtml';
/**
* @var EncoderInterface
*/
public $jsonEncoder;
/**
* Form constructor.
*
* @param Context $context
* @param Tree $categoryTree
* @param Registry $registry
* @param CategoryFactory $categoryFactory
* @param BlogResourceTree $blogCategoryTree
* @param BlogCategoryFactory $blogCategoryFactory
* @param EncoderInterface $jsonEncoder
* @param array $data
*/
public function __construct(
Context $context,
Tree $categoryTree,
Registry $registry,
CategoryFactory $categoryFactory,
BlogResourceTree $blogCategoryTree,
BlogCategoryFactory $blogCategoryFactory,
EncoderInterface $jsonEncoder,
array $data = []
) {
parent::__construct($context, $categoryTree, $registry, $categoryFactory, $data);
$this->jsonEncoder = $jsonEncoder;
$this->_categoryTree = $blogCategoryTree;
$this->_categoryFactory = $blogCategoryFactory;
}
/**
* @return AbstractCategory
* @throws LocalizedException
*/
protected function _prepareLayout()
{
$category = $this->getCategory();
$categoryId = (int) $category->getId();
// 0 when we create Blog Category, otherwise some value for editing Blog Category
$this->setChild(
'tabs',
$this->getLayout()->createBlock(Tabs::class, 'tabs')
);
// Save button
$this->addButton('save', [
'id' => 'save',
'label' => __('Save Category'),
'class' => 'save primary save-category',
'data_attribute' => [
'mage-init' => [
'Mageplaza_Blog/category/edit' => [
'url' => $this->getSaveUrl(),
'ajax' => true
]
]
]
]);
// Delete button
if ($categoryId && $categoryId != 1 && !$this->getRequest()->getParam('duplicate')) {
$this->addButton('delete', [
'id' => 'delete',
'label' => __('Delete Category'),
'onclick' => "categoryDelete('" . $this->getUrl('mageplaza_blog/*/delete', ['_current' => true]) . "')",
'class' => 'delete'
]);
}
// Reset button
$resetPath = $categoryId ? 'mageplaza_blog/*/edit' : 'mageplaza_blog/*/add';
$this->addButton('reset', [
'id' => 'reset',
'label' => __('Reset'),
'onclick' => "categoryReset('" . $this->getUrl($resetPath, ['_current' => true]) . "',false)",
'class' => 'reset'
]);
return parent::_prepareLayout();
}
/**
* Retrieve additional buttons html
*
* @return string
*/
public function getAdditionalButtonsHtml()
{
$html = '';
foreach ($this->additionalButtons as $childName) {
$html .= $this->getChildHtml($childName);
}
return $html;
}
/**
* @return mixed
*/
public function isAjax()
{
return $this->getRequest()->isAjax();
}
/**
* @param array $args
*
* @return string
*/
public function getSaveUrl(array $args = [])
{
/** @var BlogCategory $category */
$category = $this->_coreRegistry->registry('category');
$params = ['_current' => false, '_query' => false];
if ($category->getDuplicate()) {
$params['duplicate'] = true;
}
$params = array_merge($params, $args);
return $this->getUrl('mageplaza_blog/*/save', $params);
}
/**
* @return string
*/
public function getEditUrl()
{
return $this->getUrl('mageplaza_blog/category/edit', ['_query' => false, 'id' => null, 'parent' => null]);
}
/**
* @param string $alias
* @param array $config
*
* @return $this
* @throws LocalizedException
*/
public function addAdditionalButton($alias, $config)
{
if (isset($config['name'])) {
$config['element_name'] = $config['name'];
}
if ($this->hasToolbarBlock()) {
$this->addButton($alias, $config);
} else {
$this->setChild(
$alias . '_button',
$this->getLayout()->createBlock(Button::class)->addData($config)
);
$this->additionalButtons[$alias] = $alias . '_button';
}
return $this;
}
/**
* Remove additional button
*
* @param string $alias
*
* @return $this
*/
public function removeAdditionalButton($alias)
{
if (isset($this->additionalButtons[$alias])) {
$this->unsetChild($this->additionalButtons[$alias]);
unset($this->additionalButtons[$alias]);
}
return $this;
}
/**
* @return string
*/
public function getTabsHtml()
{
return $this->getChildHtml('tabs');
}
/**
* @return Phrase|string
*/
public function getHeader()
{
if ($this->getCategoryId()) {
return $this->getCategoryName();
}
$parentId = (int) $this->getRequest()->getParam('parent');
if ($parentId && $parentId !== Category::TREE_ROOT_ID) {
return __('New Child 123 Category');
} else {
return __('New Root 12 Category');
}
}
/**
* @param array $args
*
* @return string
*/
public function getDeleteUrl(array $args = [])
{
$params = ['_current' => true];
$params = array_merge($params, $args);
return $this->getUrl('mageplaza_blog/*/delete', $params);
}
/**
* Return URL for refresh input element 'path' in form
*
* @param array $args
*
* @return string
*/
public function getRefreshPathUrl(array $args = [])
{
$params = ['_current' => true];
$params = array_merge($params, $args);
return $this->getUrl('mageplaza_blog/*/refreshPath', $params);
}
/**
* Get parent Blog Category id
*
* @return int
*/
public function getParentCategoryId()
{
return (int) $this->templateContext->getRequest()->getParam('parent');
}
/**
* Get Blog Category id
*
* @return int
*/
public function getCategoryId()
{
return (int) $this->templateContext->getRequest()->getParam('id');
}
/**
* @param int $buttonId
* @param array $data
*
* @throws LocalizedException
*/
public function addButton($buttonId, array $data)
{
$childBlockId = $buttonId . '_button';
$button = $this->getButtonChildBlock($childBlockId);
$button->setData($data);
$block = $this->getLayout()->getBlock('page.actions.toolbar');
if ($block) {
$block->setChild($childBlockId, $button);
} else {
$this->setChild($childBlockId, $button);
}
}
/**
* @return bool
* @throws LocalizedException
*/
public function hasToolbarBlock()
{
return $this->getLayout()->isBlock('page.actions.toolbar');
}
/**
* @param int $childId
* @param null $blockClassName
*
* @return BlockInterface
* @throws LocalizedException
*/
public function getButtonChildBlock($childId, $blockClassName = null)
{
if ($blockClassName === null) {
$blockClassName = Button::class;
}
return $this->getLayout()->createBlock($blockClassName, $this->getNameInLayout() . '-' . $childId);
}
/**
* @return string
*/
public function getPostsJson()
{
$posts = $this->getCategory()->getPostsPosition();
if (!empty($posts)) {
return $this->jsonEncoder->encode($posts);
}
return '{}';
}
}
@@ -0,0 +1,224 @@
<?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\Category\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\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\Store\Model\System\Store;
/**
* Class Category
* @package Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab
*/
class Category 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;
/**
* Category 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);
}
/**
* @return Generic
* @throws LocalizedException
* @throws NoSuchEntityException
*/
protected function _prepareForm()
{
/** @var \Mageplaza\Blog\Model\Category $category */
$category = $this->_coreRegistry->registry('category');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('category_');
$form->setFieldNameSuffix('category');
$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Category Information'),
'class' => 'fieldset-wide'
]);
if ($category->getId()) {
$fieldset->addField('category_id', 'hidden', ['name' => 'id', 'value' => $category->getId()]);
$fieldset->addField('path', 'hidden', ['name' => 'path', 'value' => $category->getPath()]);
} else {
$fieldset->addField(
'path',
'hidden',
['name' => 'path', 'value' => $this->getRequest()->getParam('parent') ?: 1]
);
}
$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 ($this->_storeManager->isSingleStoreMode()) {
$storeId = $this->_storeManager->getStore()->getId();
$fieldset->addField('store_ids', 'hidden', [
'name' => 'store_ids',
'value' => $storeId
]);
} else {
/** @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 (!$category->hasData('store_ids')) {
$category->setStoreIds(0);
}
}
$form->addValues($category->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 __('Category');
}
/**
* 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,296 @@
<?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\Category\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;
use Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab
*/
class Post extends Extended implements TabInterface
{
/**
* @var CollectionFactory
*/
public $postCollectionFactory;
/**
* @var Registry
*/
public $coreRegistry;
/**
* @var PostFactory
*/
public $postFactory;
/**
* Post constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param Data $backendHelper
* @param PostFactory $postFactory
* @param CollectionFactory $postCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Data $backendHelper,
PostFactory $postFactory,
CollectionFactory $postCollectionFactory,
array $data = []
) {
$this->postCollectionFactory = $postCollectionFactory;
$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->getCategory()->getId()) {
$this->setDefaultFilter(['in_posts' => 1]);
}
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->postCollectionFactory->create();
$collection->getSelect()->joinLeft(
['related' => $collection->getTable('mageplaza_blog_post_category')],
'related.post_id=main_table.post_id AND related.category_id=' . (int) $this->getRequest()->getParam(
'id',
0
),
['position']
);
$collection->addFilterToMap('post_id', 'main_table.post_id');
$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('category_posts', null);
if (!is_array($posts)) {
$posts = $this->getCategory()->getPostsPosition();
return array_keys($posts);
}
return $posts;
}
/**
* Retrieve selected Posts
* @return array
*/
public function getSelectedPosts()
{
$selected = $this->getCategory()->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->getCategory()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Category
*/
public function getCategory()
{
return $this->coreRegistry->registry('category');
}
/**
* @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/category/posts', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
}
@@ -0,0 +1,121 @@
<?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\Category\Edit;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Model\Auth\Session;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Category;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Category\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* @var string
*/
protected $_template = 'Magento_Backend::widget/tabshoriz.phtml';
/**
* @var Registry
*/
public $coreRegistry;
/**
* Tabs constructor.
*
* @param Registry $coreRegistry
* @param Context $context
* @param EncoderInterface $jsonEncoder
* @param Session $authSession
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
EncoderInterface $jsonEncoder,
Session $authSession,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
parent::__construct($context, $jsonEncoder, $authSession, $data);
}
/**
* Initialize Tabs
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('category_info_tabs');
$this->setDestElementId('category_tab_content');
$this->setTitle(__('Category Data'));
}
/**
* Retrieve Blog Category object
*
* @return Category
*/
public function getCategory()
{
return $this->coreRegistry->registry('category');
}
/**
* @inheritdoc
* @throws Exception
*/
protected function _prepareLayout()
{
$this->addTab('category', [
'label' => __('Category information'),
'content' => $this->getLayout()
->createBlock(
Tab\Category::class,
'mageplaza_blog_category_edit_tab_category'
)
->toHtml()
]);
$this->addTab('post', [
'label' => __('Posts'),
'content' => $this->getLayout()
->createBlock(
Tab\Post::class,
'mageplaza_blog_category_edit_tab_post'
)
->toHtml()
]);
// dispatch event add custom tabs
$this->_eventManager->dispatch('adminhtml_mageplaza_blog_category_tabs', ['tabs' => $this]);
return parent::_prepareLayout();
}
}
+215
View File
@@ -0,0 +1,215 @@
<?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\Category;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Model\Auth\Session;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\CategoryFactory as CatalogCategoryFactory;
use Magento\Catalog\Model\ResourceModel\Category\Tree as TreeResource;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\DataObject;
use Magento\Framework\DB\Helper;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\CategoryFactory;
use Mageplaza\Blog\Model\ResourceModel\Category\Tree as BlogTreeResource;
/**
* @method Tree setUseAjax($useAjax)
* @method bool getUseAjax()
*/
class Tree extends \Magento\Catalog\Block\Adminhtml\Category\Tree
{
/**
* @var int Store filter frontend
*/
protected $_blogStore;
/**
* Tree constructor.
*
* @param Context $context
* @param TreeResource $categoryTree
* @param Registry $registry
* @param CatalogCategoryFactory $categoryFactory
* @param EncoderInterface $jsonEncoder
* @param Helper $resourceHelper
* @param Session $backendSession
* @param BlogTreeResource $blogCategoryTree
* @param CategoryFactory $blogCategoryFactory
* @param array $data
*/
public function __construct(
Context $context,
TreeResource $categoryTree,
Registry $registry,
CatalogCategoryFactory $categoryFactory,
EncoderInterface $jsonEncoder,
Helper $resourceHelper,
Session $backendSession,
BlogTreeResource $blogCategoryTree,
CategoryFactory $blogCategoryFactory,
array $data = []
) {
parent::__construct(
$context,
$categoryTree,
$registry,
$categoryFactory,
$jsonEncoder,
$resourceHelper,
$backendSession,
$data
);
$this->_categoryTree = $blogCategoryTree;
$this->_categoryFactory = $blogCategoryFactory;
$this->_withProductCount = false;
}
/**
* @return string
*/
public function getNodesUrl()
{
return $this->getUrl('mageplaza_blog/category/jsonTree');
}
/**
* @return string
*/
public function getMoveUrl()
{
return $this->getUrl('mageplaza_blog/category/move');
}
/**
* @param array $args
*
* @return string
*/
public function getSaveUrl(array $args = [])
{
$params = ['_current' => false, '_query' => false];
$params = array_merge($params, $args);
return $this->getUrl('mageplaza_blog/*/save', $params);
}
/**
* @return string
*/
public function getEditUrl()
{
return $this->getUrl(
'mageplaza_blog/category/edit',
['store' => null, '_query' => false, 'id' => null, 'parent' => null]
);
}
/**
* @param null $parentNodeCategory
* @param null $store
*
* @return array
*/
public function getTree($parentNodeCategory = null, $store = null)
{
$this->_blogStore = $store;
return parent::getTree($parentNodeCategory);
}
/**
* Get category name
*
* @param DataObject $node
*
* @return string
*/
public function buildNodeName($node)
{
$result = $this->escapeHtml($node->getName());
if ($this->_withProductCount) {
$result .= ' (' . $node->getProductCount() . ')';
}
return $result;
}
/**
* Get JSON of a tree node or an associative array
*
* @param Node|array $node
* @param int $level
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _getNodeJson($node, $level = 0)
{
// create a node from data array
if (is_array($node)) {
$node = new Node($node, 'category_id', new \Magento\Framework\Data\Tree());
}
$storeIds = $node->getStoreIds() ? explode(',', $node->getStoreIds() ?? '') : [];
if (!($this->_blogStore === null)
&& !empty($storeIds)
&& !in_array(0, $storeIds, false)
&& !in_array($this->_blogStore, $storeIds, false)) {
return null;
}
$node->setIsActive(true);
if ($item = parent::_getNodeJson($node, $level)) {
$item['url'] = $node->getData('url_key');
$item['storeIds'] = $node->getData('store_ids');
$item['allowDrag'] = $this->_isCategoryMoveable($node) && ($node->getLevel() == 0 ? false : true);
$item['enabled'] = $node->getData('enabled');
return $item;
}
return null;
}
/**
* Return ids of root categories as array
*
* @return array
*/
public function getRootIds()
{
$ids = $this->getData('root_ids');
if ($ids === null) {
$ids = [Category::TREE_ROOT_ID];
$this->setData('root_ids', $ids);
}
return $ids;
}
}
+45
View File
@@ -0,0 +1,45 @@
<?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;
use Magento\Backend\Block\Widget\Grid\Container;
/**
* Class Comment
* @package Mageplaza\Blog\Block\Adminhtml
*/
class Comment extends Container
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
$this->_controller = 'adminhtml_comment';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_addButtonLabel = __('New Comment');
parent::_construct();
}
}
+123
View File
@@ -0,0 +1,123 @@
<?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\Comment;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Comment;
use Mageplaza\Blog\Model\Post;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Comment
*/
class Edit extends Container
{
/**
* Core registry
*
* @var Registry
*/
public $coreRegistry;
/**
* constructor
*
* @param Registry $coreRegistry
* @param Context $context
* @param array $data
*/
public function __construct(
Registry $coreRegistry,
Context $context,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
parent::__construct($context, $data);
}
/**
* Initialize Post edit block
*
* @return void
*/
protected function _construct()
{
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_comment';
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
);
$this->buttonList->update('save', 'label', 'Save Comment');
$this->buttonList->remove('reset');
}
/**
* Retrieve text for header element depending on loaded Post
*
* @return string
*/
public function getHeaderText()
{
/** @var Comment $comment */
$comment = $this->coreRegistry->registry('mageplaza_blog_comment');
if ($comment->getId()) {
return __("Edit Comment");
}
return __('New Comment');
}
/**
* Get form action URL
*
* @return string
*/
public function getFormActionUrl()
{
/** @var Post $post */
$comment = $this->coreRegistry->registry('mageplaza_blog_comment');
if ($id = $comment->getId()) {
return $this->getUrl('*/*/save', ['id' => $id]);
}
return parent::getFormActionUrl();
}
}
@@ -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\Comment\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Comment\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,217 @@
<?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\Comment\Edit\Tab;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\System\Store;
use Mageplaza\Blog\Model\Config\Source\Comments\Status;
use Mageplaza\Blog\Model\PostFactory;
/**
* Class Comment
* @package Mageplaza\Blog\Block\Adminhtml\Comment\Edit\Tab
*/
class Comment extends Generic implements TabInterface
{
/**
* @var CustomerRepositoryInterface
*/
protected $_customerRepository;
/**
* @var PostFactory
*/
protected $_postFactory;
/**
* @var Status
*/
protected $_commentStatus;
/**
* @var Store
*/
protected $systemStore;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* Comment constructor.
*
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param CustomerRepositoryInterface $customerRepository
* @param PostFactory $postFactory
* @param Status $commentStatus
* @param Store $systemStore
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
CustomerRepositoryInterface $customerRepository,
PostFactory $postFactory,
Status $commentStatus,
Store $systemStore,
array $data = []
) {
$this->_commentStatus = $commentStatus;
$this->_customerRepository = $customerRepository;
$this->_postFactory = $postFactory;
$this->systemStore = $systemStore;
$this->storeManager = $context->getStoreManager();
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @return Generic
* @throws LocalizedException
* @throws NoSuchEntityException
*/
protected function _prepareForm()
{
$comment = $this->_coreRegistry->registry('mageplaza_blog_comment');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('comment_');
$form->setFieldNameSuffix('comment');
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('Comment Details'), 'class' => 'fieldset-wide']
);
if ($comment->getId()) {
$fieldset->addField('comment_id', 'hidden', ['name' => 'comment_id']);
}
$post = $this->_postFactory->create()->load($comment->getPostId());
$postText = '<a href="' . $this->getUrl('mageplaza_blog/post/edit', ['id' => $comment->getPostId()])
. '" onclick="this.target=\'blank\'">' . $this->escapeHtml($post->getName()) . '</a>';
$fieldset->addField('post_name', 'note', ['text' => $postText, 'label' => __('Post'), 'name' => 'post_name']);
if ($comment->getEntityId() > 0) {
$customer = $this->_customerRepository->getById($comment->getEntityId());
$customerText = '<a href="'
. $this->getUrl(
'customer/index/edit',
['id' => $customer->getId(), 'active_tab' => 'review']
)
. '" onclick="this.target=\'blank\'">'
. $this->escapeHtml($customer->getFirstname() . ' ' . $customer->getLastname())
. '</a> <a href="mailto:%4">(' . $customer->getEmail() . ')</a>';
} else {
$customerText = 'Guest';
}
$fieldset->addField(
'customer_name',
'note',
['text' => $customerText, 'label' => __('Customer'), 'name' => 'customer_name']
);
$fieldset->addField('status', 'select', [
'label' => __('Status'),
'required' => true,
'name' => 'status',
'values' => $this->_commentStatus->toArray()
]);
$fieldset->addField('content', 'textarea', [
'label' => __('Content'),
'required' => true,
'name' => 'content',
'style' => 'height:24em;'
]);
$viewText = '';
foreach ($this->storeManager->getStores() as $store) {
if ($store->getId() === $comment->getStoreIds()) {
$viewText .= '<a href="' . $post->getUrl($store->getId()) . '#cmt-id-' . $comment->getId()
. '" onclick="this.target=\'blank\'">View in store ' . $store->getName() . '</a><br>';
}
}
$fieldset->addField(
'view_front',
'note',
['text' => $viewText, 'label' => __('View On Front End'), 'name' => 'view_front']
);
$form->addValues($comment->getData());
$this->setForm($form);
return parent::_prepareForm();
}
/**
* Prepare label for tab
*
* @return string
*/
public function getTabLabel()
{
return __('Comment');
}
/**
* 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\Comment\Edit;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Comment\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('comment_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Comment Information'));
}
}
+77
View File
@@ -0,0 +1,77 @@
<?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\Import;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Phrase;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Import
*/
class Edit extends Container
{
/**
* Internal constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->buttonList->remove('back');
$this->buttonList->remove('reset');
$this->buttonList->remove('save');
$this->buttonList->add(
'check-connection',
[
'label' => __('Check Connection'),
'class' => 'primary',
'data_attribute' => [
'mage-init' => [
'button' => [
'target' => '#edit_form',
]
]
],
'onclick' => 'mpBlogImport.initImportCheckConnection();'
],
-100
);
$this->_objectId = 'import_id';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_import';
}
/**
* Get header text
*
* @return Phrase
*/
public function getHeaderText()
{
return __('Import Setting');
}
}
@@ -0,0 +1,225 @@
<?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\Import\Edit;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Cms\Model\Wysiwyg\Config;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Store\Model\System\Store;
use Mageplaza\Blog\Helper\Image as ImageHelper;
use Mageplaza\Blog\Model\Config\Source\Import\Behaviour;
use Mageplaza\Blog\Model\Config\Source\Import\Type;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Import\Edit
*/
class Form extends Generic
{
/**
* @var Store
*/
public $systemStore;
/**
* @var Config
*/
public $wysiwygConfig;
/**
* @var Yesno
*/
public $booleanOptions;
/**
* @var ImageHelper
*/
protected $_imageHelper;
/**
* @var Type
*/
protected $_importType;
/**
* @var Behaviour
*/
protected $_importBehaviour;
/**
* Form constructor.
*
* @param Config $wysiwygConfig
* @param Store $systemStore
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param ImageHelper $imageHelper
* @param Type $importType
* @param Behaviour $importBehaviour
* @param Yesno $booleanOptions
* @param array $data
*/
public function __construct(
Config $wysiwygConfig,
Store $systemStore,
Context $context,
Registry $registry,
FormFactory $formFactory,
ImageHelper $imageHelper,
Type $importType,
Behaviour $importBehaviour,
Yesno $booleanOptions,
array $data = []
) {
$this->wysiwygConfig = $wysiwygConfig;
$this->systemStore = $systemStore;
$this->_imageHelper = $imageHelper;
$this->_importType = $importType;
$this->_importBehaviour = $importBehaviour;
$this->booleanOptions = $booleanOptions;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @inheritdoc
* @return $this
* @throws LocalizedException
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create([
'data' => [
'id' => 'edit_form',
'action' => '',
'method' => 'post',
'enctype' => 'multipart/form-data',
],
]);
$form->setFieldNameSuffix('import');
$fieldsets['base'] = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
$fieldsets['base']->addField('import_type', 'select', [
'name' => 'import_type',
'label' => __('Import Type'),
'title' => __('Import Type'),
'values' => $this->_importType->toOptionArray(),
'required' => true,
'onchange' => 'mpBlogImport.initImportFieldsSet()'
]);
$fieldsetList = $this->_importType->toOptionArray();
array_shift($fieldsetList);
foreach ($fieldsetList as $item) {
$fieldsets[$item["value"]] = $form->addFieldset($item["value"] . '_fieldset', [
'legend' => $item["label"]->getText() . __(' Import'),
'class' => 'no-display'
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_import_name', 'hidden', [
'name' => 'import_name',
'value' => $item["label"]->getText()
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_db_name', 'text', [
'name' => 'db_name',
'title' => __('Database Name'),
'label' => __('Database Name'),
'required' => true,
'class' => $item["value"],
'note' => __('Your SQL database name')
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_user_name', 'text', [
'name' => 'user_name',
'title' => __('Database User Name'),
'label' => __('Database User Name'),
'required' => true,
'class' => $item["value"],
'note' => __('Your SQL database User name')
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_db_password', 'text', [
'name' => 'db_password',
'title' => __('Database Password'),
'label' => __('Database Password'),
'class' => $item["value"],
'note' => __('Your SQL database Password')
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_db_host', 'text', [
'name' => 'db_host',
'title' => __('Database Host'),
'label' => __('Database Host'),
'required' => true,
'class' => $item["value"],
'value' => 'localhost',
'note' => __('Your SQL database Hostname')
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_table_prefix', 'text', [
'name' => 'table_prefix',
'title' => __('Table Prefix'),
'label' => __('Table Prefix'),
'class' => $item["value"],
'note' => __('Your table prefix name')
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_import_behaviour', 'select', [
'name' => 'import_behaviour',
'label' => __('Import Behaviour'),
'title' => __('Import Behaviour'),
'values' => $this->_importBehaviour->toOptionArray(),
'note' => __('This action is applied to all data'),
'onchange' => 'mpBlogImport.initExpandBehaviour();'
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_import_behaviour_expand', 'select', [
'name' => 'import_behaviour_expand',
'label' => __('Allow update content on existing URL-key'),
'title' => __('Allow update content on existing URL-key'),
'values' => $this->booleanOptions->toOptionArray(),
'note' => __('If <b>Yes</b>, content will be updated on posts with existing url-key. Select <b>No</b> to add a new post'),
'value' => 1,
]);
$fieldsets[$item["value"]]->addField($item["value"] . '_import_image_path', 'note', [
'name' => 'import_image_path',
'label' => __('Image Path Hint'),
'title' => __('Image Path Hint'),
'text' => '<div class="image-path"></div>',
]);
}
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
@@ -0,0 +1,107 @@
<?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\Import\Edit;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\View\Element\Messages;
use Mageplaza\Blog\Helper\Data as BlogHelper;
use Mageplaza\Blog\Model\Config\Source\Import\Type;
/**
* Class Import
* @package Mageplaza\Blog\Block\Adminhtml\Import\Edit
*/
class Import extends Template
{
/**
* @var BlogHelper
*/
public $blogHelper;
/**
* @var Type
*/
public $importType;
/**
* Before constructor.
*
* @param Context $context
* @param BlogHelper $blogHelper
* @param Type $importType
* @param array $data
*/
public function __construct(
Context $context,
BlogHelper $blogHelper,
Type $importType,
array $data = []
) {
$this->blogHelper = $blogHelper;
$this->importType = $importType;
parent::__construct($context, $data);
}
/**
* @return string
*/
public function getTypeSelector()
{
$types = [];
foreach ($this->importType->toOptionArray() as $item) {
$types[] = $item['value'];
}
array_shift($types);
return BlogHelper::jsonEncode($types);
}
/**
* @param $priority
* @param $message
*
* @return string
*/
public function getMessagesHtml($priority, $message)
{
/** @var $messagesBlock Messages */
$messagesBlock = $this->_layout->createBlock(Messages::class);
$messagesBlock->{$priority}(__($message));
return $messagesBlock->toHtml();
}
/**
* @return string
*/
public function getImportButtonHtml()
{
$importUrl = $this->getUrl('mageplaza_blog/import/import');
$html = '&nbsp;&nbsp;<button id="word-press-import" href="' . $importUrl .
'" class="" type="button" onclick="mpBlogImport.importAction();">' .
'<span><span><span>Import</span></span></span></button>';
return $html;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?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;
use Magento\Backend\Block\Widget\Grid\Container;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml
*/
class Post extends Container
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
$this->_controller = 'adminhtml_post';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_headerText = __('Posts');
$this->_headerText = __('Posts');
$this->_addButtonLabel = __('Create New Post');
parent::_construct();
}
}
+242
View File
@@ -0,0 +1,242 @@
<?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\Post;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Post;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Post
*/
class Edit extends Container
{
/**
* Core registry
*
* @var Registry
*/
public $coreRegistry;
/**
* constructor
*
* @param Registry $coreRegistry
* @param Context $context
* @param array $data
*/
public function __construct(
Registry $coreRegistry,
Context $context,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
parent::__construct($context, $data);
}
/**
* Initialize Post edit block
*
* @return void
*/
protected function _construct()
{
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_post';
parent::_construct();
if (!$this->getRequest()->getParam('history')) {
$post = $this->coreRegistry->registry('mageplaza_blog_post');
$this->buttonList->remove('save');
$this->buttonList->add(
'save',
[
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'save',
'target' => '#edit_form'
]
]
],
'class_name' => \Magento\Ui\Component\Control\Container::SPLIT_BUTTON,
'options' => $this->getOptions($post),
],
-100
);
$this->buttonList->add(
'save-and-continue',
[
'label' => __('Save and Continue Edit'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'saveAndContinueEdit',
'target' => '#edit_form'
]
]
]
],
-100
);
if ($post->getId() && !$this->_request->getParam('duplicate')) {
$this->buttonList->add(
'duplicate',
[
'label' => __('Duplicate'),
'class' => 'duplicate',
'onclick' => sprintf("location.href = '%s';", $this->getDuplicateUrl()),
],
-101
);
} else {
$this->buttonList->remove('delete');
}
}
}
/**
* Retrieve options
*
* @param Post $post
*
* @return array
*/
protected function getOptions($post)
{
if ($post->getId() && !$this->_request->getParam('duplicate')) {
$options[] = [
'id_hard' => 'save_and_draft',
'label' => __('Save as Draft'),
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'save',
'target' => '#edit_form',
'eventData' => [
'action' => ['args' => ['action' => 'draft']]
],
]
]
]
];
}
$options[] = [
'id_hard' => 'save_and_history',
'label' => __(' Save & add History'),
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'save',
'target' => '#edit_form',
'eventData' => [
'action' => ['args' => ['action' => 'add']]
],
]
]
]
];
return $options;
}
/**
* Retrieve text for header element depending on loaded Post
*
* @return string
*/
public function getHeaderText()
{
/** @var Post $post */
$post = $this->coreRegistry->registry('mageplaza_blog_post');
if ($this->getRequest()->getParam('history')) {
return __("Edit History Post '%1'", $this->escapeHtml($post->getName()));
}
if ($post->getId() && $post->getDuplicate()) {
return __("Edit Post '%1'", $this->escapeHtml($post->getName()));
}
return __('New Post');
}
/**
* Get form action URL
*
* @return string
*/
public function getFormActionUrl()
{
/** @var Post $post */
$post = $this->coreRegistry->registry('mageplaza_blog_post');
if ($post->getId()) {
if ($post->getDuplicate()) {
$ar = [];
} else {
$ar = ['id' => $post->getId()];
}
if ($this->getRequest()->getParam('history')) {
$ar['post_id'] = $this->getRequest()->getParam('post_id');
}
return $this->getUrl('*/*/save', $ar);
}
return parent::getFormActionUrl();
}
/**
* @return string
*/
protected function getDuplicateUrl()
{
$post = $this->coreRegistry->registry('mageplaza_blog_post');
return $this->getUrl('*/*/duplicate', ['id' => $post->getId(), 'duplicate' => true]);
}
/**
* @return string
*/
protected function getSaveDraftUrl()
{
return $this->getUrl('*/*/save', ['action' => 'draft']);
}
/**
* @return string
*/
protected function getSaveAddHistoryUrl()
{
return $this->getUrl('*/*/save', ['action' => 'add']);
}
}
+51
View File
@@ -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\Post\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Post\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,353 @@
<?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\Post\Edit\Tab;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Backend\Helper\Data;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Registry;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History\Action;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History\Author;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History\Categories;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History\Store;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History\Tags;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History\Topics;
use Mageplaza\Blog\Model\AuthorFactory;
use Mageplaza\Blog\Model\ResourceModel\PostHistory\Collection;
use Mageplaza\Blog\Model\Tag;
/**
* Class Product
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab
*/
class History extends Extended implements TabInterface
{
/**
* @var Registry
*/
public $coreRegistry;
/**
* @var Collection
*/
protected $historyCollection;
/**
* @var \Mageplaza\Blog\Helper\Data
*/
protected $_helperData;
/**
* Product constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param Data $backendHelper
* @param Collection $historyCollection
* @param \Mageplaza\Blog\Helper\Data $_helperData
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Data $backendHelper,
Collection $historyCollection,
\Mageplaza\Blog\Helper\Data $_helperData,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
$this->historyCollection = $historyCollection;
$this->_helperData = $_helperData;
parent::__construct($context, $backendHelper, $data);
}
/**
* Set grid params
* @throws FileSystemException
*/
public function _construct()
{
parent::_construct();
$this->setId('history_id');
$this->setDefaultSort('history_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(false);
$this->setUseAjax(true);
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->historyCollection;
$id = $this->getRequest()->getParam('id', 0);
$collection->addFieldToFilter('post_id', $id);
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return $this
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn('history_id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'history_id',
'type' => 'number',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]);
$this->addColumn('name', [
'header' => __('Name'),
'index' => 'name',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]);
$this->addColumn('short_description', [
'header' => __('Short Description'),
'index' => 'short_description',
'header_css_class' => 'col-short-description',
'column_css_class' => 'col-short-description'
]);
$this->addColumn('store_ids', [
'header' => __('Store View'),
'index' => 'store_ids',
'renderer' => Store::class,
'filter' => false,
'header_css_class' => 'col-store-ids',
'column_css_class' => 'col-store-ids'
]);
$this->addColumn('category_ids', [
'header' => __('Categories'),
'index' => 'category_ids',
'filter' => false,
'renderer' => Categories::class,
'header_css_class' => 'col-category-ids',
'column_css_class' => 'col-category-ids'
]);
$this->addColumn('topic_ids', [
'header' => __('Topics'),
'index' => 'topic_ids',
'filter' => false,
'renderer' => Topics::class,
'header_css_class' => 'col-topic-ids',
'column_css_class' => 'col-topic-ids'
]);
$this->addColumn('tag_ids', [
'header' => __('Tags'),
'index' => 'tag_ids',
'filter' => false,
'renderer' => Tags::class,
'header_css_class' => 'col-tag-ids',
'column_css_class' => 'col-tag-ids'
]);
$this->addColumn('modifier_id', [
'header' => __('Modified by'),
'index' => 'modifier_id',
'type' => 'options',
'options' => $this->_getModifierOptions(),
'renderer' => Author::class,
'filter_condition_callback' => [$this, '_filterByModifierId'],
'header_css_class' => 'col-modifier-id',
'column_css_class' => 'col-modifier-id'
]);
$this->addColumn('updated_at', [
'header' => __('Modified At'),
'index' => 'updated_at',
'header_css_class' => 'col-updated-at',
'column_css_class' => 'col-updated-at',
'type' => 'datetime',
'filter_condition_callback' => [$this, '_filterByUpdatedAt'],
]);
$this->addColumn(
'action',
[
'header' => __('Action'),
'index' => 'template_id',
'sortable' => false,
'filter' => false,
'no_link' => true,
'renderer' => Action::class,
'header_css_class' => 'col-actions',
'column_css_class' => 'col-actions'
]
);
return $this;
}
/**
* @param Tag|Object $item
*
* @return string
*/
public function getRowUrl($item)
{
return '#';
}
/**
* get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/historyGrid', ['id' => $this->getPost()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Post
*/
public function getPost()
{
return $this->coreRegistry->registry('mageplaza_blog_post');
}
/**
* @return string
*/
public function getTabLabel()
{
return __('Edit History');
}
/**
* @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/post/history', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
/**
* Get Modifiers as Author of Post
*
* @return array
*/
private function _getModifierOptions()
{
/** @var AuthorFactory $authors */
$authors = $this->_helperData->getFactoryByType('author');
$authors = $authors->create()->getCollection()->addFieldToSelect(['user_id', 'name'])->getItems();
$options = [];
foreach ($authors as $author) {
$options[$author->getUserId()] = $author->getName();
}
return $options;
}
/**
* @param Collection $collection
* @param \Magento\Backend\Block\Widget\Grid\Column\Extended $column
*
* @return $this
*/
public function _filterByModifierId(
Collection $collection,
\Magento\Backend\Block\Widget\Grid\Column\Extended $column
) {
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$collection->addFieldToFilter('modifier_id', $value);
return $this;
}
/**
* @param Collection $collection
* @param \Magento\Backend\Block\Widget\Grid\Column\Extended $column
*
* @return $this
*/
public function _filterByUpdatedAt(
Collection $collection,
\Magento\Backend\Block\Widget\Grid\Column\Extended $column
) {
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$formValue = $value['from'] ?? '';
$toValue = $value['to'] ?? '';
if ($formValue && $toValue) {
$updateFilter = ['from' => $formValue, 'to' => $toValue];
} elseif ($formValue) {
$updateFilter = ['from' => $formValue];
} else {
$updateFilter = ['to' => $toValue];
}
$collection->addFieldToFilter('updated_at', $updateFilter);
return $this;
}
}
@@ -0,0 +1,403 @@
<?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\Post\Edit\Tab;
use DateTimeZone;
use Exception;
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\Backend\Model\Auth\Session;
use Magento\Cms\Model\Page\Source\PageLayout as BasePageLayout;
use Magento\Cms\Model\Wysiwyg\Config;
use Magento\Config\Model\Config\Source\Design\Robots;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Framework\Data\Form;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Store\Model\System\Store;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\Category;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\Tag;
use Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\Topic;
use Mageplaza\Blog\Helper\Image;
use Mageplaza\Blog\Model\Config\Source\Author;
use Mageplaza\Blog\Model\Config\Source\AuthorStatus;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab
*/
class Post extends Generic implements TabInterface
{
/**
* Wysiwyg config
*
* @var Config
*/
public $wysiwygConfig;
/**
* Country options
*
* @var Yesno
*/
public $booleanOptions;
/**
* @var Robots
*/
public $metaRobotsOptions;
/**
* @var Store
*/
public $systemStore;
/**
* @var Session
*/
protected $authSession;
/**
* @var Image
*/
protected $imageHelper;
/**
* @var DateTime
*/
protected $_date;
/**
* @var BasePageLayout
*/
protected $_layoutOptions;
/**
* @var Author
*/
protected $_author;
/**
* @var AuthorStatus
*/
protected $_status;
/**
* Post constructor.
*
* @param Context $context
* @param Registry $registry
* @param Session $authSession
* @param DateTime $dateTime
* @param BasePageLayout $layoutOption
* @param FormFactory $formFactory
* @param Config $wysiwygConfig
* @param Yesno $booleanOptions
* @param Robots $metaRobotsOptions
* @param Store $systemStore
* @param Image $imageHelper
* @param Author $author
* @param AuthorStatus $status
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
Session $authSession,
DateTime $dateTime,
BasePageLayout $layoutOption,
FormFactory $formFactory,
Config $wysiwygConfig,
Yesno $booleanOptions,
Robots $metaRobotsOptions,
Store $systemStore,
Image $imageHelper,
Author $author,
AuthorStatus $status,
array $data = []
) {
$this->wysiwygConfig = $wysiwygConfig;
$this->booleanOptions = $booleanOptions;
$this->metaRobotsOptions = $metaRobotsOptions;
$this->systemStore = $systemStore;
$this->authSession = $authSession;
$this->_date = $dateTime;
$this->_layoutOptions = $layoutOption;
$this->imageHelper = $imageHelper;
$this->_author = $author;
$this->_status = $status;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @inheritdoc
* @throws Exception
*/
protected function _prepareForm()
{
/** @var \Mageplaza\Blog\Model\Post $post */
$post = $this->_coreRegistry->registry('mageplaza_blog_post');
/** @var Form $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('post_');
$form->setFieldNameSuffix('post');
$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Post Information'),
'class' => 'fieldset-wide'
]);
if ($this->_request->getParam('duplicate')) {
$fieldset->addField('duplicate', 'hidden', [
'name' => 'duplicate',
'value' => 1
]);
}
$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('author_id', 'select', [
'name' => 'author_id',
'label' => __('Author'),
'title' => __('Author'),
'required' => true,
'values' => $this->_author->toOptionArray()
]);
$fieldset->addField('enabled', 'select', [
'name' => 'enabled',
'label' => __('Status'),
'title' => __('Status'),
'values' => $this->_status->toOptionArray()
]);
if (!$post->hasData('enabled')) {
$post->setEnabled(1);
}
$fieldset->addField('short_description', 'textarea', [
'name' => 'short_description',
'label' => __('Short Description'),
'title' => __('Short Description')
]);
$fieldset->addField('post_content', 'editor', [
'name' => 'post_content',
'label' => __('Content'),
'title' => __('Content'),
'config' => $this->wysiwygConfig->getConfig([
'add_variables' => false,
'add_widgets' => true,
'add_directives' => true
])
]);
if ($this->_storeManager->isSingleStoreMode()) {
$fieldset->addField('store_ids', 'hidden', [
'name' => 'store_ids',
'value' => $this->_storeManager->getStore()->getId()
]);
} else {
/** @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 (!$post->hasData('store_ids')) {
$post->setStoreIds(0);
}
}
$fieldset->addField('image', \Mageplaza\Blog\Block\Adminhtml\Renderer\Image::class, [
'name' => 'image',
'label' => __('Image'),
'title' => __('Image'),
'path' => $this->imageHelper->getBaseMediaPath(Image::TEMPLATE_MEDIA_TYPE_POST),
'note' => __('The appropriate size is 265px * 250px.')
]);
$fieldset->addField('categories_ids', Category::class, [
'name' => 'categories_ids',
'label' => __('Categories'),
'title' => __('Categories'),
]);
if (!$post->getCategoriesIds()) {
$post->setCategoriesIds($post->getCategoryIds());
}
$fieldset->addField('topics_ids', Topic::class, [
'name' => 'topics_ids',
'label' => __('Topics'),
'title' => __('Topics'),
]);
if (!$post->getTopicsIds()) {
$post->setTopicsIds($post->getTopicIds());
}
$fieldset->addField('tags_ids', Tag::class, [
'name' => 'tags_ids',
'label' => __('Tags'),
'title' => __('Tags'),
]);
if (!$post->getTagsIds()) {
$post->setTagsIds($post->getTagIds());
}
$fieldset->addField('in_rss', 'select', [
'name' => 'in_rss',
'label' => __('In RSS'),
'title' => __('In RSS'),
'values' => $this->booleanOptions->toOptionArray(),
]);
$fieldset->addField('allow_comment', 'select', [
'name' => 'allow_comment',
'label' => __('Allow Comment'),
'title' => __('Allow Comment'),
'values' => $this->booleanOptions->toOptionArray(),
]);
$fieldset->addField(
'publish_date',
'date',
[
'name' => 'publish_date',
'label' => __('Publish Date'),
'title' => __('Publish Date'),
'date_format' => 'yyyy-MM-dd',
'timezone' => false,
'time_format' => 'hh:mm:ss'
]
);
$this->_eventManager->dispatch('after_adminhtml_blog_post_info_tab', ['fieldset' => $fieldset]);
$seoFieldset = $form->addFieldset('seo_fieldset', [
'legend' => __('Search Engine Optimization'),
'class' => 'fieldset-wide'
]);
$seoFieldset->addField('meta_title', 'text', [
'name' => 'meta_title',
'label' => __('Meta Title'),
'title' => __('Meta Title'),
'note' => __('If empty, the post name will be used.')
]);
$seoFieldset->addField('meta_keywords', 'textarea', [
'name' => 'meta_keywords',
'label' => __('Meta Keywords'),
'title' => __('Meta Keywords'),
'note' => __('Enter comma-separated keywords.')
]);
$seoFieldset->addField('meta_description', 'textarea', [
'name' => 'meta_description',
'label' => __('Meta Description'),
'title' => __('Meta Description'),
'note' => __('If empty, the global blog meta description will be used.')
]);
$designFieldset = $form->addFieldset('design_fieldset', [
'legend' => __('Design'),
'class' => 'fieldset-wide'
]);
$designFieldset->addField('layout', 'select', [
'name' => 'layout',
'label' => __('Layout'),
'title' => __('Layout'),
'values' => $this->_layoutOptions->toOptionArray()
]);
if (!$post->getId()) {
$post->addData([
'allow_comment' => 1
]);
}
/** Get the public_date from database */
if ($post->getData('publish_date')) {
$publicDateTime = new \DateTime($post->getData('publish_date'), new DateTimeZone('UTC'));
$publicDateTime->setTimezone(new DateTimeZone($this->_localeDate->getConfigTimezone()));
$publicDateTime = $publicDateTime->format('m/d/Y H:i:s');
$post->setData('publish_date', $publicDateTime);
}
$form->addValues($post->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 __('Post');
}
/**
* 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,316 @@
<?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\Post\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\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Tag;
/**
* Class Product
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab
*/
class Product extends Extended implements TabInterface
{
/**
* @var CollectionFactory
*/
public $productCollectionFactory;
/**
* @var Registry
*/
public $coreRegistry;
/**
* @var RequestInterface
*/
protected $request;
/**
* Product constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param Data $backendHelper
* @param RequestInterface $request
* @param CollectionFactory $productCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Data $backendHelper,
RequestInterface $request,
CollectionFactory $productCollectionFactory,
array $data = []
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->coreRegistry = $coreRegistry;
$this->request = $request;
parent::__construct($context, $backendHelper, $data);
}
/**
* Set grid params
*/
public function _construct()
{
parent::_construct();
$this->setId('product_grid');
$this->setDefaultSort('position');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(false);
$this->setUseAjax(true);
if ($this->getPost()->getId()) {
$this->setDefaultFilter(['in_products' => 1]);
}
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->productCollectionFactory->create();
$collection->clear();
$collection->getSelect()->joinLeft(
['mp_p' => $collection->getTable('mageplaza_blog_post_product')],
'e.entity_id = mp_p.entity_id',
['position']
)->group('e.entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return $this
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn('in_products', [
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_product',
'values' => $this->_getSelectedProducts(),
'align' => 'center',
'index' => 'entity_id'
]);
$this->addColumn('entity_id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'entity_id',
'type' => 'number',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]);
$this->addColumn('title', [
'header' => __('Sku'),
'index' => 'sku',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]);
if ($this->request->getParam('post_id') || $this->getPost()->getId()) {
$this->addColumn('position', [
'header' => __('Position'),
'name' => 'position',
'width' => 60,
'type' => 'number',
'validate_class' => 'validate-number',
'index' => 'position',
'editable' => true,
'edit_only' => true,
]);
} else {
$this->addColumn('position', [
'header' => __('Position'),
'name' => 'position',
'width' => 60,
'type' => 'number',
'validate_class' => 'validate-number',
'index' => 'position',
'editable' => true,
'filter' => false,
'edit_only' => true,
]);
}
return $this;
}
/**
* Retrieve selected Tags
*
* @return array
*/
protected function _getSelectedProducts()
{
$products = $this->getRequest()->getPost('post_products', null);
if (!is_array($products)) {
$products = $this->getPost()->getProductsPosition();
return array_keys($products);
}
return $products;
}
/**
* Retrieve selected Tags
*
* @return array
*/
public function getSelectedProducts()
{
$selected = $this->getPost()->getProductsPosition();
if (!is_array($selected)) {
$selected = [];
} else {
foreach ($selected as $key => $value) {
$selected[$key] = ['position' => $value];
}
}
return $selected;
}
/**
* @param Tag|Object $item
*
* @return string
*/
public function getRowUrl($item)
{
return '#';
}
/**
* get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/productsGrid', ['post_id' => $this->getPost()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Post
*/
public function getPost()
{
return $this->coreRegistry->registry('mageplaza_blog_post');
}
/**
* @param Column $column
*
* @return $this
* @throws LocalizedException
*/
protected function _addColumnFilterToCollection($column)
{
if ($column->getId() === 'in_products') {
$productIds = $this->_getSelectedProducts();
if (empty($productIds)) {
$productIds = 0;
}
if ($column->getFilter()->getValue()) {
$this->getCollection()->addFieldToFilter('entity_id', ['in' => $productIds]);
} else {
if ($productIds) {
$this->getCollection()->addFieldToFilter('entity_id', ['nin' => $productIds]);
}
}
} else {
parent::_addColumnFilterToCollection($column);
}
return $this;
}
/**
* @return string
*/
public function getTabLabel()
{
return __('Products');
}
/**
* @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/post/products', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
}
@@ -0,0 +1,284 @@
<?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\Post\Edit\Tab\Renderer;
use Magento\Catalog\Model\Category as CategoryModel;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Data\Form\Element\CollectionFactory;
use Magento\Framework\Data\Form\Element\Factory;
use Magento\Framework\Data\Form\Element\Multiselect;
use Magento\Framework\Escaper;
use Magento\Framework\UrlInterface;
use Mageplaza\Blog\Model\ResourceModel\Category\Collection;
use Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory as BlogCategoryCollectionFactory;
/**
* Class Category
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Category extends Multiselect
{
/**
* @var BlogCategoryCollectionFactory
*/
public $collectionFactory;
/**
* @var AuthorizationInterface
*/
public $authorization;
/**
* @var UrlInterface
*/
protected $_urlBuilder;
/**
* Category constructor.
*
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param BlogCategoryCollectionFactory $collectionFactory
* @param AuthorizationInterface $authorization
* @param UrlInterface $urlBuilder
* @param array $data
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
BlogCategoryCollectionFactory $collectionFactory,
AuthorizationInterface $authorization,
UrlInterface $urlBuilder,
array $data = []
) {
$this->collectionFactory = $collectionFactory;
$this->authorization = $authorization;
$this->_urlBuilder = $urlBuilder;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
}
/**
* @inheritdoc
*/
public function getElementHtml()
{
$html = '<div class="admin__field-control admin__control-grouped">';
$html .= '<div id="blog-category-select" class="admin__field"
data-bind="scope:\'blogCategory\'" data-index="index">';
$html .= '<!-- ko foreach: elems() -->';
$html .= '<input name="post[categories_ids]" data-bind="value: value" style="display: none"/>';
$html .= '<!-- ko template: elementTmpl --><!-- /ko -->';
$html .= '<!-- /ko -->';
$html .= '</div>';
$html .= '<div class="admin__field admin__field-group-additional admin__field-small"
data-bind="scope:\'create_category_button\'">';
$html .= '<div class="admin__field-control">';
$html .= '<!-- ko template: elementTmpl --><!-- /ko -->';
$html .= '</div></div></div>';
$html .= '<!-- ko scope: \'create_category_modal\' -->
<!-- ko template: getTemplate() --><!-- /ko --><!-- /ko -->';
$html .= $this->getAfterElementHtml();
return $html;
}
/**
* Get no display
*
* @return bool
*/
public function getNoDisplay()
{
$isNotAllowed = !$this->authorization->isAllowed('Mageplaza_Blog::category');
return $this->getData('no_display') || $isNotAllowed;
}
/**
* @return mixed
*/
public function getCategoriesTree()
{
/* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */
$collection = $this->collectionFactory->create();
$categoryById = [
CategoryModel::TREE_ROOT_ID => [
'value' => CategoryModel::TREE_ROOT_ID,
'optgroup' => null,
],
];
foreach ($collection as $category) {
foreach ([$category->getId(), $category->getParentId()] as $categoryId) {
if (!isset($categoryById[$categoryId])) {
$categoryById[$categoryId] = ['value' => $categoryId];
}
}
$categoryById[$category->getId()]['is_active'] = 1;
$categoryById[$category->getId()]['label'] = $category->getName();
$categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];
}
return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
}
/**
* Get values for select
*
* @return array
*/
public function getValues()
{
$values = $this->getValue();
if (!is_array($values)) {
$values = explode(',', $values);
}
if (!count($values)) {
return [];
}
/* @var $collection Collection */
$collection = $this->collectionFactory->create()
->addIdFilter($values);
$options = [];
foreach ($collection as $category) {
$options[] = $category->getId();
}
return $options;
}
/**
* Attach Blog Category suggest widget initialization
*
* @return string
*/
public function getAfterElementHtml()
{
$html = '<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"blogCategory": {
"component": "uiComponent",
"children": {
"blog_select_category": {
"component": "Mageplaza_Blog/js/components/new-category",
"config": {
"filterOptions": true,
"disableLabel": true,
"chipsEnabled": true,
"levelsVisibility": "1",
"elementTmpl": "ui/grid/filters/elements/ui-select",
"options": ' . json_encode($this->getCategoriesTree()) . ',
"value": ' . json_encode($this->getValues()) . ',
"listens": {
"index=create_category:responseData": "setParsed",
"newOption": "toggleOptionSelected"
},
"config": {
"dataScope": "blog_select_category",
"sortOrder": 10
}
}
}
}
},
"create_category_button": {
"title": "' . __('New Category') . '",
"formElement": "container",
"additionalClasses": "admin__field-small",
"componentType": "container",
"component": "Magento_Ui/js/form/components/button",
"template": "ui/form/components/button/container",
"actions": [
{
"targetName": "create_category_modal",
"actionName": "toggleModal"
},
{
"targetName": "create_category_modal.create_category",
"actionName": "render"
},
{
"targetName": "create_category_modal.create_category",
"actionName": "resetForm"
}
],
"additionalForGroup": true,
"provider": false,
"source": "product_details",
"displayArea": "insideGroup"
},
"create_category_modal": {
"config": {
"isTemplate": false,
"componentType": "container",
"component": "Magento_Ui/js/modal/modal-component",
"options": {
"title": "' . __('New Category') . '",
"type": "slide"
},
"imports": {
"state": "!index=create_category:responseStatus"
}
},
"children": {
"create_category": {
"label": "",
"componentType": "container",
"component": "Magento_Ui/js/form/components/insert-form",
"dataScope": "",
"update_url": "' . $this->_urlBuilder->getUrl('mui/index/render') . '",
"render_url": "' .
$this->_urlBuilder->getUrl(
'mui/index/render_handle',
['handle' => 'mageplaza_blog_category_create', 'buttons' => 1]
) . '",
"autoRender": false,
"ns": "blog_new_category_form",
"externalProvider": "blog_new_category_form.new_category_form_data_source",
"toolbarContainer": "${ $.parentName }",
"formSubmitType": "ajax"
}
}
}
}
}
}
}
</script>';
return $html;
}
}
@@ -0,0 +1,112 @@
<?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\Post\Edit\Tab\Renderer\History;
use Exception;
use Magento\Backend\Block\Context;
use Magento\Framework\DataObject;
use Magento\Framework\Json\EncoderInterface;
use Magento\Store\Model\StoreManagerInterface;
/**
* Class Action
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Action extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Action
{
/**
* @var StoreManagerInterface
*/
protected $_storeManager;
/**
* Action constructor.
*
* @param Context $context
* @param StoreManagerInterface $storeManager
* @param EncoderInterface $jsonEncoder
* @param array $data
*/
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
EncoderInterface $jsonEncoder,
array $data = []
) {
$this->_storeManager = $storeManager;
parent::__construct($context, $jsonEncoder, $data);
}
/**
* @param DataObject $row
*
* @return string
*/
public function render(DataObject $row)
{
$actions[] = [
'url' =>
$this->getUrl('*/history/edit', [
'id' => $row->getId(),
'post_id' => $row->getPostId(),
'history' => true
]),
'popup' => false,
'caption' => __('Edit'),
];
try {
$actions[] = [
'url' => $this->_storeManager->getStore()->getBaseUrl()
. 'mpblog/post/preview?id=' . $row->getPostId() . '&historyId=' . $row->getId(),
'popup' => true,
'caption' => __('Preview'),
];
} catch (Exception $exception) {
$actions[] = [];
}
$actions[] = [
'url' =>
$this->getUrl('*/history/restore', [
'id' => $row->getId(),
'post_id' => $row->getPostId()
]),
'popup' => false,
'caption' => __('Restore'),
'confirm' => 'Are you sure you want to do this?'
];
$actions[] = [
'url' =>
$this->getUrl('*/history/delete', [
'id' => $row->getId(),
'post_id' => $row->getPostId()
]),
'popup' => false,
'caption' => __('Delete'),
'confirm' => 'Are you sure you want to do this?'
];
$this->getColumn()->setActions($actions);
return parent::render($row);
}
}
@@ -0,0 +1,71 @@
<?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\Post\Edit\Tab\Renderer\History;
use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Text;
use Magento\Framework\DataObject;
use Mageplaza\Blog\Helper\Data;
/**
* Class Action
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Author extends Text
{
/**
* @var Data
*/
protected $_helperData;
/**
* Categories constructor.
*
* @param Context $context
* @param Data $_helperData
* @param array $data
*/
public function __construct(
Context $context,
Data $_helperData,
array $data = []
) {
$this->_helperData = $_helperData;
parent::__construct($context, $data);
}
/**
* @param DataObject $row
*
* @return string
*/
public function render(DataObject $row)
{
if (!empty($row->getData($this->getColumn()->getIndex()))) {
$userId = $row->getData($this->getColumn()->getIndex());
$author = $this->_helperData->getFactoryByType('author')->create()->load($userId);
$row->setData($this->getColumn()->getIndex(), $author->getName());
}
return parent::render($row);
}
}
@@ -0,0 +1,75 @@
<?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\Post\Edit\Tab\Renderer\History;
use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Text;
use Magento\Framework\DataObject;
use Mageplaza\Blog\Helper\Data;
/**
* Class Action
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Categories extends Text
{
/**
* @var Data
*/
protected $_helperData;
/**
* Categories constructor.
*
* @param Context $context
* @param Data $_helperData
* @param array $data
*/
public function __construct(
Context $context,
Data $_helperData,
array $data = []
) {
$this->_helperData = $_helperData;
parent::__construct($context, $data);
}
/**
* @param DataObject $row
*
* @return string
*/
public function render(DataObject $row)
{
if (!empty($row->getData($this->getColumn()->getIndex()))) {
$text = '';
$CategoryIds = explode(',', $row->getData($this->getColumn()->getIndex()) ?? '');
foreach ($CategoryIds as $categoryId) {
$category = $this->_helperData->getFactoryByType('category')->create()->load($categoryId);
$text .= $category->getName() . ',';
}
$row->setData($this->getColumn()->getIndex(), trim($text, ','));
}
return parent::render($row);
}
}
@@ -0,0 +1,111 @@
<?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_LayeredNavigationUltimate
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer\History;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Framework\DataObject;
use Magento\Framework\Escaper;
use Magento\Store\Model\System\Store as SystemStore;
/**
* Class Name
* @package Mageplaza\LayeredNavigationUltimate\Block\Adminhtml\Grid\Renderer
*/
class Store extends AbstractRenderer
{
/**
* @var Escaper
*/
protected $escaper;
/**
* System store
*
* @var SystemStore
*/
protected $systemStore;
/**
* Store constructor.
*
* @param SystemStore $systemStore
* @param Escaper $escaper
*/
public function __construct(
SystemStore $systemStore,
Escaper $escaper
) {
$this->systemStore = $systemStore;
$this->escaper = $escaper;
}
/**
* Renders grid column
*
* @param DataObject $row
*
* @return string
*/
public function render(DataObject $row)
{
if ($row) {
$store = '';
$store .= $this->prepareItem($row->getData());
return $store;
}
return '';
}
/**
* @param array $item
* @return \Magento\Framework\Phrase|string
*/
protected function prepareItem(array $item)
{
$content = '';
$origStores = [];
$items = explode(",", $item['store_ids']);
foreach ($items as $storeId) {
$origStores[] = $storeId;
}
if (in_array(0, $origStores)) {
return __('All Store Views');
}
$data = $this->systemStore->getStoresStructure(false, $origStores);
foreach ($data as $website) {
$content .= "<b>" . $website['label'] . "</b><br/>";
foreach ($website['children'] as $group) {
$content .= str_repeat('&nbsp;', 3) . "<b>" . $this->escaper->escapeHtml($group['label']) . "</b><br/>";
foreach ($group['children'] as $store) {
$content .= str_repeat('&nbsp;', 6) . $this->escaper->escapeHtml($store['label']) . "<br/>";
}
}
}
return $content;
}
}
@@ -0,0 +1,75 @@
<?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\Post\Edit\Tab\Renderer\History;
use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Text;
use Magento\Framework\DataObject;
use Mageplaza\Blog\Helper\Data;
/**
* Class Action
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Tags extends Text
{
/**
* @var Data
*/
protected $_helperData;
/**
* Categories constructor.
*
* @param Context $context
* @param Data $_helperData
* @param array $data
*/
public function __construct(
Context $context,
Data $_helperData,
array $data = []
) {
$this->_helperData = $_helperData;
parent::__construct($context, $data);
}
/**
* @param DataObject $row
*
* @return string
*/
public function render(DataObject $row)
{
if (!empty($row->getData($this->getColumn()->getIndex()))) {
$text = '';
$tagIds = explode(',', $row->getData($this->getColumn()->getIndex()));
foreach ($tagIds as $tagId) {
$tag = $this->_helperData->getFactoryByType('tag')->create()->load($tagId);
$text .= $tag->getName() . ',';
}
$row->setData($this->getColumn()->getIndex(), trim($text, ','));
}
return parent::render($row);
}
}
@@ -0,0 +1,75 @@
<?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\Post\Edit\Tab\Renderer\History;
use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Text;
use Magento\Framework\DataObject;
use Mageplaza\Blog\Helper\Data;
/**
* Class Action
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Topics extends Text
{
/**
* @var Data
*/
protected $_helperData;
/**
* Categories constructor.
*
* @param Context $context
* @param Data $_helperData
* @param array $data
*/
public function __construct(
Context $context,
Data $_helperData,
array $data = []
) {
$this->_helperData = $_helperData;
parent::__construct($context, $data);
}
/**
* @param DataObject $row
*
* @return string
*/
public function render(DataObject $row)
{
if (!empty($row->getData($this->getColumn()->getIndex()))) {
$text = '';
$topicIds = explode(',', $row->getData($this->getColumn()->getIndex()));
foreach ($topicIds as $topicId) {
$topic = $this->_helperData->getFactoryByType('topic')->create()->load($topicId);
$text .= $topic->getName() . ',';
}
$row->setData($this->getColumn()->getIndex(), trim($text, ','));
}
return parent::render($row);
}
}
@@ -0,0 +1,274 @@
<?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\Post\Edit\Tab\Renderer;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Data\Form\Element\CollectionFactory;
use Magento\Framework\Data\Form\Element\Factory;
use Magento\Framework\Data\Form\Element\Multiselect;
use Magento\Framework\Escaper;
use Magento\Framework\UrlInterface;
use Mageplaza\Blog\Model\ResourceModel\Tag\Collection;
use Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory as BlogTagCollectionFactory;
/**
* Class Tag
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Tag extends Multiselect
{
/**
* @var BlogTagCollectionFactory
*/
public $collectionFactory;
/**
* Authorization
*
* @var AuthorizationInterface
*/
public $authorization;
/**
* @var UrlInterface
*/
protected $_urlBuilder;
/**
* Tag constructor.
*
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param BlogTagCollectionFactory $collectionFactory
* @param AuthorizationInterface $authorization
* @param UrlInterface $urlBuilder
* @param array $data
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
BlogTagCollectionFactory $collectionFactory,
AuthorizationInterface $authorization,
UrlInterface $urlBuilder,
array $data = []
) {
$this->collectionFactory = $collectionFactory;
$this->authorization = $authorization;
$this->_urlBuilder = $urlBuilder;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
}
/**
* @inheritdoc
*/
public function getElementHtml()
{
$html = '<div class="admin__field-control admin__control-grouped">';
$html .= '<div id="blog-tag-select" class="admin__field" data-bind="scope:\'blogTag\'" data-index="index">';
$html .= '<!-- ko foreach: elems() -->';
$html .= '<input name="post[tags_ids]" data-bind="value: value" style="display: none"/>';
$html .= '<!-- ko template: elementTmpl --><!-- /ko -->';
$html .= '<!-- /ko -->';
$html .= '</div>';
$html .= '<div class="admin__field admin__field-group-additional admin__field-small"'
. 'data-bind="scope:\'create_tag_button\'">';
$html .= '<div class="admin__field-control">';
$html .= '<!-- ko template: elementTmpl --><!-- /ko -->';
$html .= '</div></div></div>';
$html .= '<!-- ko scope: \'create_tag_modal\' --><!-- ko template: getTemplate() --><!-- /ko --><!-- /ko -->';
$html .= $this->getAfterElementHtml();
return $html;
}
/**
* Get no display
*
* @return bool
*/
public function getNoDisplay()
{
$isNotAllowed = !$this->authorization->isAllowed('Mageplaza_Blog::tag');
return $this->getData('no_display') || $isNotAllowed;
}
/**
* @return mixed
*/
public function getTagsCollection()
{
/* @var $collection Collection */
$collection = $this->collectionFactory->create();
$tagById = [];
foreach ($collection as $tag) {
$tagById[$tag->getId()]['value'] = $tag->getId();
$tagById[$tag->getId()]['is_active'] = 1;
$tagById[$tag->getId()]['label'] = $tag->getName();
}
return $tagById;
}
/**
* Get values for select
*
* @return array
*/
public function getValues()
{
$values = $this->getValue();
if (!is_array($values)) {
$values = explode(',', $values);
}
if (!count($values)) {
return [];
}
/* @var $collection Collection */
$collection = $this->collectionFactory->create()
->addIdFilter($values);
$options = [];
foreach ($collection as $tag) {
$options[] = $tag->getId();
}
return $options;
}
/**
* Attach Blog Tag suggest widget initialization
*
* @return string
*/
public function getAfterElementHtml()
{
$html = '<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"blogTag": {
"component": "uiComponent",
"children": {
"blog_select_tag": {
"component": "Mageplaza_Blog/js/components/new-category",
"config": {
"filterOptions": true,
"disableLabel": true,
"chipsEnabled": true,
"levelsVisibility": "1",
"elementTmpl": "ui/grid/filters/elements/ui-select",
"options": ' . json_encode($this->getTagsCollection()) . ',
"value": ' . json_encode($this->getValues()) . ',
"listens": {
"index=create_tag:responseData": "setParsed",
"newOption": "toggleOptionSelected"
},
"config": {
"dataScope": "blog_select_tag",
"sortOrder": 10
}
}
}
}
},
"create_tag_button": {
"title": "' . __('New Tag') . '",
"formElement": "container",
"additionalClasses": "admin__field-small",
"componentType": "container",
"component": "Magento_Ui/js/form/components/button",
"template": "ui/form/components/button/container",
"actions": [
{
"targetName": "create_tag_modal",
"actionName": "toggleModal"
},
{
"targetName": "create_tag_modal.create_tag",
"actionName": "render"
},
{
"targetName": "create_tag_modal.create_tag",
"actionName": "resetForm"
}
],
"additionalForGroup": true,
"provider": false,
"source": "product_details",
"displayArea": "insideGroup"
},
"create_tag_modal": {
"config": {
"isTemplate": false,
"componentType": "container",
"component": "Magento_Ui/js/modal/modal-component",
"options": {
"title": "' . __('New Tag') . '",
"type": "slide"
},
"imports": {
"state": "!index=create_tag:responseStatus"
}
},
"children": {
"create_tag": {
"label": "",
"componentType": "container",
"component": "Magento_Ui/js/form/components/insert-form",
"dataScope": "",
"update_url": "' . $this->_urlBuilder->getUrl('mui/index/render') . '",
"render_url": "' .
$this->_urlBuilder->getUrl(
'mui/index/render_handle',
[
'handle' => 'mageplaza_blog_tag_create',
'buttons' => 1
]
) . '",
"autoRender": false,
"ns": "blog_new_tag_form",
"externalProvider": "blog_new_tag_form.new_tag_form_data_source",
"toolbarContainer": "${ $.parentName }",
"formSubmitType": "ajax"
}
}
}
}
}
}
}
</script>';
return $html;
}
}
@@ -0,0 +1,274 @@
<?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\Post\Edit\Tab\Renderer;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\Data\Form\Element\CollectionFactory;
use Magento\Framework\Data\Form\Element\Factory;
use Magento\Framework\Data\Form\Element\Multiselect;
use Magento\Framework\Escaper;
use Magento\Framework\UrlInterface;
use Mageplaza\Blog\Model\ResourceModel\Topic\Collection;
use Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory as BlogTopicCollectionFactory;
/**
* Class Topic
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab\Renderer
*/
class Topic extends Multiselect
{
/**
* @var BlogTopicCollectionFactory
*/
public $collectionFactory;
/**
* Authorization
*
* @var AuthorizationInterface
*/
public $authorization;
/**
* @var UrlInterface
*/
protected $_urlBuilder;
/**
* Topic constructor.
*
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param BlogTopicCollectionFactory $collectionFactory
* @param AuthorizationInterface $authorization
* @param UrlInterface $urlBuilder
* @param array $data
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
BlogTopicCollectionFactory $collectionFactory,
AuthorizationInterface $authorization,
UrlInterface $urlBuilder,
array $data = []
) {
$this->collectionFactory = $collectionFactory;
$this->authorization = $authorization;
$this->_urlBuilder = $urlBuilder;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
}
/**
* @inheritdoc
*/
public function getElementHtml()
{
$html = '<div class="admin__field-control admin__control-grouped">';
$html .= '<div id="blog-topic-select" class="admin__field" data-bind="scope:\'blogTopic\'" data-index="index">';
$html .= '<!-- ko foreach: elems() -->';
$html .= '<input name="post[topics_ids]" data-bind="value: value" style="display: none"/>';
$html .= '<!-- ko template: elementTmpl --><!-- /ko -->';
$html .= '<!-- /ko -->';
$html .= '</div>';
$html .= '<div class="admin__field admin__field-group-additional admin__field-small"'
. ' data-bind="scope:\'create_topic_button\'">';
$html .= '<div class="admin__field-control">';
$html .= '<!-- ko template: elementTmpl --><!-- /ko -->';
$html .= '</div></div></div>';
$html .= '<!-- ko scope: \'create_topic_modal\' --><!-- ko template: getTemplate() --><!-- /ko --><!-- /ko -->';
$html .= $this->getAfterElementHtml();
return $html;
}
/**
* Get no display
*
* @return bool
*/
public function getNoDisplay()
{
$isNotAllowed = !$this->authorization->isAllowed('Mageplaza_Blog::topic');
return $this->getData('no_display') || $isNotAllowed;
}
/**
* @return mixed
*/
public function getTopicsCollection()
{
/* @var $collection Collection */
$collection = $this->collectionFactory->create();
$topicById = [];
foreach ($collection as $topic) {
$topicById[$topic->getId()]['value'] = $topic->getId();
$topicById[$topic->getId()]['is_active'] = 1;
$topicById[$topic->getId()]['label'] = $topic->getName();
}
return $topicById;
}
/**
* Get values for select
*
* @return array
*/
public function getValues()
{
$values = $this->getValue();
if (!is_array($values)) {
$values = explode(',', $values);
}
if (!count($values)) {
return [];
}
/* @var $collection Collection */
$collection = $this->collectionFactory->create()
->addIdFilter($values);
$options = [];
foreach ($collection as $topic) {
$options[] = $topic->getId();
}
return $options;
}
/**
* Attach Blog Topic suggest widget initialization
*
* @return string
*/
public function getAfterElementHtml()
{
$html = '<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"blogTopic": {
"component": "uiComponent",
"children": {
"blog_select_topic": {
"component": "Mageplaza_Blog/js/components/new-category",
"config": {
"filterOptions": true,
"disableLabel": true,
"chipsEnabled": true,
"levelsVisibility": "1",
"elementTmpl": "ui/grid/filters/elements/ui-select",
"options": ' . json_encode($this->getTopicsCollection()) . ',
"value": ' . json_encode($this->getValues()) . ',
"listens": {
"index=create_topic:responseData": "setParsed",
"newOption": "toggleOptionSelected"
},
"config": {
"dataScope": "blog_select_topic",
"sortOrder": 10
}
}
}
}
},
"create_topic_button": {
"title": "' . __('New Topic') . '",
"formElement": "container",
"additionalClasses": "admin__field-small",
"componentType": "container",
"component": "Magento_Ui/js/form/components/button",
"template": "ui/form/components/button/container",
"actions": [
{
"targetName": "create_topic_modal",
"actionName": "toggleModal"
},
{
"targetName": "create_topic_modal.create_topic",
"actionName": "render"
},
{
"targetName": "create_topic_modal.create_topic",
"actionName": "resetForm"
}
],
"additionalForGroup": true,
"provider": false,
"source": "product_details",
"displayArea": "insideGroup"
},
"create_topic_modal": {
"config": {
"isTemplate": false,
"componentType": "container",
"component": "Magento_Ui/js/modal/modal-component",
"options": {
"title": "' . __('New Topic') . '",
"type": "slide"
},
"imports": {
"state": "!index=create_topic:responseStatus"
}
},
"children": {
"create_topic": {
"label": "",
"componentType": "container",
"component": "Magento_Ui/js/form/components/insert-form",
"dataScope": "",
"update_url": "' . $this->_urlBuilder->getUrl('mui/index/render') . '",
"render_url": "' .
$this->_urlBuilder->getUrl(
'mui/index/render_handle',
[
'handle' => 'mageplaza_blog_topic_create',
'buttons' => 1
]
) . '",
"autoRender": false,
"ns": "blog_new_topic_form",
"externalProvider": "blog_new_topic_form.new_topic_form_data_source",
"toolbarContainer": "${ $.parentName }",
"formSubmitType": "ajax"
}
}
}
}
}
}
}
</script>';
return $html;
}
}
+43
View File
@@ -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\Post\Edit;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Post\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('post_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Post Information'));
}
}
+62
View File
@@ -0,0 +1,62 @@
<?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_Core
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Renderer;
/**
* Renderer image for admin form
* Add media path to url
*
* Class Image
* @package Mageplaza\Core\Block\Adminhtml\Renderer
*/
class Image extends \Mageplaza\Core\Block\Adminhtml\Renderer\Image
{
/**
* @return string
*/
protected function _getDeleteCheckbox()
{
$html = '';
if ($this->getValue()) {
$label = __('Delete Image');
$html .= '<span class="delete-image">';
$html .= '<input style="margin: auto;" type="checkbox"' .
' name="' .
$this->getName() .
'[delete]" value="1" class="checkbox"' .
' id="' .
$this->getHtmlId() .
'_delete"' .
($this->getDisabled() ? ' disabled="disabled"' : '') .
'/>';
$html .= '<label for="' . $this->getHtmlId() .
'_delete"' . ($this->getDisabled() ? ' class="disabled"' : '') . '> ' .
$label .
'</label>';
$html .= $this->_getHiddenInput();
$html .= '</span>';
}
$html .= '<style>#author_image_image, #post_image_image{ position: relative;top: 6px }</style>';
return $html;
}
}
+46
View File
@@ -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;
use Magento\Backend\Block\Widget\Grid\Container;
/**
* Class Tag
* @package Mageplaza\Blog\Block\Adminhtml
*/
class Tag extends Container
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
$this->_controller = 'adminhtml_tag';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_headerText = __('Tags');
$this->_addButtonLabel = __('Create New Tag');
parent::_construct();
}
}
+102
View File
@@ -0,0 +1,102 @@
<?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\Tag;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Tag;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Tag
*/
class Edit extends Container
{
/**
* @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 Tag edit block
*
* @return void
*/
protected function _construct()
{
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_tag';
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 Tag
*
* @return string
*/
public function getHeaderText()
{
/** @var Tag $tag */
$tag = $this->coreRegistry->registry('mageplaza_blog_tag');
if ($tag->getId()) {
return __("Edit Tag '%1'", $this->escapeHtml($tag->getName()));
}
return __('New Tag');
}
}
@@ -0,0 +1,48 @@
<?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\Tag\Edit\Button;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
/**
* Button "Create Tag" in "New Category" slide-out panel of a product page
* Class CreateTag
* @package Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Button
*/
class CreateTag implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Create Tag'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 10
];
}
}
+52
View File
@@ -0,0 +1,52 @@
<?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\Tag\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Tag\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,300 @@
<?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\Tag\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;
use Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Tab
*/
class Post extends Extended implements TabInterface
{
/**
* Post collection factory
*
* @var CollectionFactory
*/
public $postCollectionFactory;
/**
* Registry
*
* @var Registry
*/
public $coreRegistry;
/**
* Post factory
*
* @var PostFactory
*/
public $postFactory;
/**
* Post constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param Data $backendHelper
* @param PostFactory $postFactory
* @param CollectionFactory $postCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Data $backendHelper,
PostFactory $postFactory,
CollectionFactory $postCollectionFactory,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
$this->postFactory = $postFactory;
$this->postCollectionFactory = $postCollectionFactory;
parent::__construct($context, $backendHelper, $data);
}
/**
* Set grid params
*/
public function _construct()
{
parent::_construct();
$this->setId('post_grid');
$this->setDefaultSort('position');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(false);
$this->setUseAjax(true);
if ($this->getTag()->getId()) {
$this->setDefaultFilter(['in_posts' => 1]);
}
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->postCollectionFactory->create();
$collection->getSelect()->joinLeft(
['related' => $collection->getTable('mageplaza_blog_post_tag')],
'related.post_id=main_table.post_id AND related.tag_id=' . (int) $this->getRequest()->getParam('id', 0),
['position']
);
$collection->addFilterToMap('post_id', 'main_table.post_id');
$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('tag_posts', null);
if (!is_array($posts)) {
$posts = $this->getTag()->getPostsPosition();
return array_keys($posts);
}
return $posts;
}
/**
* Retrieve selected Posts
* @return array
*/
public function getSelectedPosts()
{
$selected = $this->getTag()->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->getTag()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Tag
*/
public function getTag()
{
return $this->coreRegistry->registry('mageplaza_blog_tag');
}
/**
* @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/tag/posts', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
}
@@ -0,0 +1,222 @@
<?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\Tag\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 Tag
* @package Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Tab
*/
class Tag extends Generic implements TabInterface
{
/**
* Wysiwyg config
*
* @var Config
*/
public $wysiwygConfig;
/**
* Country options
*
* @var Yesno
*/
public $booleanOptions;
/**
* @var Enabledisable
*/
protected $enableDisable;
/**
* @var Store
*/
public $systemStore;
/**
* @var Robots
*/
public $metaRobots;
/**
* Tag constructor.
*
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Config $wysiwygConfig
* @param Yesno $booleanOptions
* @param Enabledisable $enableDisable
* @param Store $systemStore
* @param Robots $metaRobotsOptions
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Config $wysiwygConfig,
Yesno $booleanOptions,
Enabledisable $enableDisable,
Store $systemStore,
Robots $metaRobotsOptions,
array $data = []
) {
$this->wysiwygConfig = $wysiwygConfig;
$this->booleanOptions = $booleanOptions;
$this->enableDisable = $enableDisable;
$this->systemStore = $systemStore;
$this->metaRobots = $metaRobotsOptions;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @inheritdoc
*/
protected function _prepareForm()
{
/** @var \Mageplaza\Blog\Model\Tag $tag */
$tag = $this->_coreRegistry->registry('mageplaza_blog_tag');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('tag_');
$form->setFieldNameSuffix('tag');
$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Tag Information'),
'class' => 'fieldset-wide'
]);
if ($tag->getId()) {
$fieldset->addField('tag_id', 'hidden', ['name' => 'tag_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 (!$tag->hasData('enabled')) {
$tag->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 (!$tag->hasData('store_ids')) {
$tag->setStoreIds(0);
}
} else {
$fieldset->addField('store_ids', 'hidden', [
'name' => 'store_ids',
'value' => $this->_storeManager->getStore()->getId()
]);
}
$form->addValues($tag->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 __('Tag');
}
/**
* 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;
}
}
+42
View File
@@ -0,0 +1,42 @@
<?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\Tag\Edit;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Tag\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('tag_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Tag Information'));
}
}
+46
View File
@@ -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;
use Magento\Backend\Block\Widget\Grid\Container;
/**
* Class Topic
* @package Mageplaza\Blog\Block\Adminhtml
*/
class Topic extends Container
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
$this->_controller = 'adminhtml_topic';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_headerText = __('Topics');
$this->_addButtonLabel = __('Create New Topic');
parent::_construct();
}
}
+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'));
}
}
+48
View File
@@ -0,0 +1,48 @@
<?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\Widget;
use Magento\Backend\Block\Widget\Grid\Column;
use Magento\Framework\Data\Form\Element\AbstractElement;
/**
* Class Number
* @package Mageplaza\Blog\Block\Adminhtml\Widget
*/
class Number extends Column
{
/**
* @param AbstractElement $element
*
* @return AbstractElement
*/
public function prepareElementHtml(AbstractElement $element)
{
$html = '<input type="text" name="' . $element->getName() . '" id="' . $element->getId()
. '" class=" input-text admin__control-text required-entry _required validate-digits" value="'
. $element->getValue() . '">';
$element->setData('value', '');
$element->setData('after_element_html', $html);
return $element;
}
}