init
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user