Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.5.0-stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash Smith committed Aug 23, 2015
2 parents 5b8ed9a + 634543c commit 90101b7
Show file tree
Hide file tree
Showing 32 changed files with 1,578 additions and 36 deletions.
26 changes: 26 additions & 0 deletions Api/Data/PostSearchResultsInterface.php
@@ -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 removed Block/.gitkeep
Empty file.
25 changes: 25 additions & 0 deletions Block/Adminhtml/Post.php
@@ -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);
}
}
101 changes: 101 additions & 0 deletions Block/Adminhtml/Post/Edit.php
@@ -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}}']);
}
}
127 changes: 127 additions & 0 deletions Block/Adminhtml/Post/Edit/Form.php
@@ -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();
}
}
1 change: 1 addition & 0 deletions Block/PostList.php
Expand Up @@ -36,6 +36,7 @@ public function getPosts()
if (!$this->hasData('posts')) {
$posts = $this->_postCollectionFactory
->create()
->addFieldToFilter('is_active', array('eq' => 1))
->addOrder(
PostInterface::CREATION_TIME,
PostCollection::SORT_ORDER_DESC
Expand Down
3 changes: 0 additions & 3 deletions Block/PostView.php
@@ -1,9 +1,6 @@
<?php
namespace Ashsmith\Blog\Block;

use Ashsmith\Blog\Api\Data\PostInterface;
use Ashsmith\Blog\Model\Resource\Post\Collection as PostCollection;

class PostView extends \Magento\Framework\View\Element\Template implements
\Magento\Framework\Object\IdentityInterface
{
Expand Down
Empty file removed Controller/.gitkeep
Empty file.

0 comments on commit 90101b7

Please sign in to comment.