This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,578 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
namespace Ashsmith\Blog\Api\Data; | ||
|
||
use Magento\Framework\Api\SearchResultsInterface; | ||
|
||
/** | ||
* Interface for cms page search results. | ||
* @api | ||
*/ | ||
interface PostSearchResultsInterface extends SearchResultsInterface | ||
{ | ||
/** | ||
* Get pages list. | ||
* | ||
* @return \Ashsmith\Blog\Api\Data\PostInterface[] | ||
*/ | ||
public function getItems(); | ||
|
||
/** | ||
* Set pages list. | ||
* | ||
* @param \Ashsmith\Blog\Api\Data\PostInterface[] $items | ||
* @return $this | ||
*/ | ||
public function setItems(array $items); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace Ashsmith\Blog\Block\Adminhtml; | ||
|
||
class Post extends \Magento\Backend\Block\Widget\Grid\Container | ||
{ | ||
protected function _construct() | ||
{ | ||
$this->_controller = 'adminhtml_post'; | ||
$this->_blockGroup = 'Ashsmith_Blog'; | ||
$this->_headerText = __('Manage Blog Posts'); | ||
|
||
parent::_construct(); | ||
|
||
if ($this->_isAllowedAction('Ashsmith_Blog::save')) { | ||
$this->buttonList->update('add', 'label', __('Add New Post')); | ||
} else { | ||
$this->buttonList->remove('add'); | ||
} | ||
} | ||
|
||
protected function _isAllowedAction($resourceId) | ||
{ | ||
return $this->_authorization->isAllowed($resourceId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
namespace Ashsmith\Blog\Block\Adminhtml\Post; | ||
|
||
class Edit extends \Magento\Backend\Block\Widget\Form\Container | ||
{ | ||
/** | ||
* Core registry | ||
* | ||
* @var \Magento\Framework\Registry | ||
*/ | ||
protected $_coreRegistry = null; | ||
|
||
/** | ||
* @param \Magento\Backend\Block\Widget\Context $context | ||
* @param \Magento\Framework\Registry $registry | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Widget\Context $context, | ||
\Magento\Framework\Registry $registry, | ||
array $data = [] | ||
) { | ||
$this->_coreRegistry = $registry; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Initialize blog post edit block | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_objectId = 'post_id'; | ||
$this->_blockGroup = 'Ashsmith_Blog'; | ||
$this->_controller = 'adminhtml_post'; | ||
|
||
parent::_construct(); | ||
|
||
if ($this->_isAllowedAction('Ashsmith_Blog::save')) { | ||
$this->buttonList->update('save', 'label', __('Save Blog Post')); | ||
$this->buttonList->add( | ||
'saveandcontinue', | ||
[ | ||
'label' => __('Save and Continue Edit'), | ||
'class' => 'save', | ||
'data_attribute' => [ | ||
'mage-init' => [ | ||
'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'], | ||
], | ||
] | ||
], | ||
-100 | ||
); | ||
} else { | ||
$this->buttonList->remove('save'); | ||
} | ||
|
||
if ($this->_isAllowedAction('Ashsmith_Blog::post_delete')) { | ||
$this->buttonList->update('delete', 'label', __('Delete Post')); | ||
} else { | ||
$this->buttonList->remove('delete'); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve text for header element depending on loaded post | ||
* | ||
* @return \Magento\Framework\Phrase | ||
*/ | ||
public function getHeaderText() | ||
{ | ||
if ($this->_coreRegistry->registry('blog_post')->getId()) { | ||
return __("Edit Post '%1'", $this->escapeHtml($this->_coreRegistry->registry('blog_post')->getTitle())); | ||
} else { | ||
return __('New Post'); | ||
} | ||
} | ||
|
||
/** | ||
* Check permission for passed action | ||
* | ||
* @param string $resourceId | ||
* @return bool | ||
*/ | ||
protected function _isAllowedAction($resourceId) | ||
{ | ||
return $this->_authorization->isAllowed($resourceId); | ||
} | ||
|
||
/** | ||
* Getter of url for "Save and Continue" button | ||
* tab_id will be replaced by desired by JS later | ||
* | ||
* @return string | ||
*/ | ||
protected function _getSaveAndContinueUrl() | ||
{ | ||
return $this->getUrl('blog/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Ashsmith\Blog\Block\Adminhtml\Post\Edit; | ||
|
||
/** | ||
* Adminhtml cms block edit form | ||
*/ | ||
class Form extends \Magento\Backend\Block\Widget\Form\Generic | ||
{ | ||
|
||
/** | ||
* @var \Magento\Store\Model\System\Store | ||
*/ | ||
protected $_systemStore; | ||
|
||
/** | ||
* @param \Magento\Backend\Block\Template\Context $context | ||
* @param \Magento\Framework\Registry $registry | ||
* @param \Magento\Framework\Data\FormFactory $formFactory | ||
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig | ||
* @param \Magento\Store\Model\System\Store $systemStore | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
\Magento\Framework\Registry $registry, | ||
\Magento\Framework\Data\FormFactory $formFactory, | ||
\Magento\Store\Model\System\Store $systemStore, | ||
array $data = [] | ||
) { | ||
$this->_systemStore = $systemStore; | ||
parent::__construct($context, $registry, $formFactory, $data); | ||
} | ||
|
||
/** | ||
* Init form | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
$this->setId('post_form'); | ||
$this->setTitle(__('Post Information')); | ||
} | ||
|
||
/** | ||
* Prepare form | ||
* | ||
* @return $this | ||
*/ | ||
protected function _prepareForm() | ||
{ | ||
/** @var \Ashsmith\Blog\Model\Post $model */ | ||
$model = $this->_coreRegistry->registry('blog_post'); | ||
|
||
/** @var \Magento\Framework\Data\Form $form */ | ||
$form = $this->_formFactory->create( | ||
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']] | ||
); | ||
|
||
$form->setHtmlIdPrefix('post_'); | ||
|
||
$fieldset = $form->addFieldset( | ||
'base_fieldset', | ||
['legend' => __('General Information'), 'class' => 'fieldset-wide'] | ||
); | ||
|
||
if ($model->getPostId()) { | ||
$fieldset->addField('post_id', 'hidden', ['name' => 'post_id']); | ||
} | ||
|
||
$fieldset->addField( | ||
'title', | ||
'text', | ||
['name' => 'title', 'label' => __('Post Title'), 'title' => __('Post Title'), 'required' => true] | ||
); | ||
|
||
$fieldset->addField( | ||
'url_key', | ||
'text', | ||
[ | ||
'name' => 'url_key', | ||
'label' => __('URL Key'), | ||
'title' => __('URL Key'), | ||
'required' => true, | ||
'class' => 'validate-xml-identifier' | ||
] | ||
); | ||
|
||
$fieldset->addField( | ||
'is_active', | ||
'select', | ||
[ | ||
'label' => __('Status'), | ||
'title' => __('Status'), | ||
'name' => 'is_active', | ||
'required' => true, | ||
'options' => ['1' => __('Enabled'), '0' => __('Disabled')] | ||
] | ||
); | ||
if (!$model->getId()) { | ||
$model->setData('is_active', '1'); | ||
} | ||
|
||
$fieldset->addField( | ||
'content', | ||
'editor', | ||
[ | ||
'name' => 'content', | ||
'label' => __('Content'), | ||
'title' => __('Content'), | ||
'style' => 'height:36em', | ||
'required' => true | ||
] | ||
); | ||
|
||
$form->setValues($model->getData()); | ||
$form->setUseContainer(true); | ||
$this->setForm($form); | ||
|
||
return parent::_prepareForm(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.