|
1 | | -<?php |
2 | | -/** |
3 | | - * Venustheme |
4 | | - * |
5 | | - * NOTICE OF LICENSE |
6 | | - * |
7 | | - * This source file is subject to the Venustheme.com license that is |
8 | | - * available through the world-wide-web at this URL: |
9 | | - * http://www.venustheme.com/license-agreement.html |
10 | | - * |
11 | | - * DISCLAIMER |
12 | | - * |
13 | | - * Do not edit or add to this file if you wish to upgrade this extension to newer |
14 | | - * version in the future. |
15 | | - * |
16 | | - * @category Venustheme |
17 | | - * @package Ves_Blog |
18 | | - * @copyright Copyright (c) 2016 Venustheme (http://www.venustheme.com/) |
19 | | - * @license http://www.venustheme.com/LICENSE-1.0.html |
20 | | - */ |
21 | | -namespace Ves\Blog\Controller\Adminhtml\Author; |
22 | | - |
23 | | -use Magento\Backend\App\Action; |
24 | | - |
25 | | -class Edit extends \Magento\Backend\App\Action |
26 | | -{ |
27 | | - /** |
28 | | - * Core registry |
29 | | - * |
30 | | - * @var \Magento\Framework\Registry |
31 | | - */ |
32 | | - protected $_coreRegistry = null; |
33 | | - |
34 | | - /** |
35 | | - * @var \Magento\Framework\View\Result\PageFactory |
36 | | - */ |
37 | | - protected $resultPageFactory; |
38 | | - |
39 | | - /** |
40 | | - * @param Action\Context $context |
41 | | - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory |
42 | | - * @param \Magento\Backend\Model\Auth\Session $authSession |
43 | | - * @param \Magento\Framework\Registry $registry |
44 | | - */ |
45 | | - public function __construct( |
46 | | - Action\Context $context, |
47 | | - \Magento\Framework\View\Result\PageFactory $resultPageFactory, |
48 | | - \Magento\Backend\Model\Auth\Session $authSession, |
49 | | - \Magento\Framework\Registry $registry |
50 | | - ) { |
51 | | - $this->resultPageFactory = $resultPageFactory; |
52 | | - $this->authSession = $authSession; |
53 | | - $this->_coreRegistry = $registry; |
54 | | - parent::__construct($context); |
55 | | - } |
56 | | - |
57 | | - public function getCurrentUser() |
58 | | - { |
59 | | - return $this->authSession->getUser(); |
60 | | - } |
61 | | - |
62 | | - /** |
63 | | - * {@inheritdoc} |
64 | | - */ |
65 | | - protected function _isAllowed() |
66 | | - { |
67 | | - return $this->_authorization->isAllowed('Ves_Blog::author'); |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Init actions |
72 | | - * |
73 | | - * @return \Magento\Backend\Model\View\Result\Page |
74 | | - */ |
75 | | - protected function _initAction() |
76 | | - { |
77 | | - // load layout, set active menu and breadcrumbs |
78 | | - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ |
79 | | - $resultPage = $this->resultPageFactory->create(); |
80 | | - $resultPage->setActiveMenu('Ves_Blog::blog') |
81 | | - ->addBreadcrumb(__('Blog'), __('Blog')) |
82 | | - ->addBreadcrumb(__('My Profile'), __('My Profile')); |
83 | | - return $resultPage; |
84 | | - } |
85 | | - |
86 | | - /** |
87 | | - * Edit CMS page |
88 | | - * |
89 | | - * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect |
90 | | - * @SuppressWarnings(PHPMD.NPathComplexity) |
91 | | - */ |
92 | | - public function execute() |
93 | | - { |
94 | | - // 1. Get ID and create model |
95 | | - $author_id = $this->getRequest()->getParam('author_id'); |
96 | | - $id = $this->getCurrentUser()->getUserId(); |
97 | | - $model = $this->_objectManager->create('Ves\Blog\Model\Author'); |
98 | | - |
99 | | - // 2. Initial checking |
100 | | - if($author_id) { |
101 | | - $model->load($author_id); |
102 | | - }elseif ($id) { |
103 | | - $model->loadByUserId($id); |
104 | | - if (!$model->getId()) { |
105 | | - $data = $this->getCurrentUser()->getData(); |
106 | | - $data['nick_name'] = $data['firstname'] . ' ' . $data['lastname']; |
107 | | - $model->setData($data)->save(); |
108 | | - } |
109 | | - } |
110 | | - |
111 | | - // 3. Set entered data if was error when we do save |
112 | | - $data = $this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true); |
113 | | - if (!empty($data)) { |
114 | | - $model->setData($data); |
115 | | - } |
116 | | - |
117 | | - // 4. Register model to use later in blocks |
118 | | - $this->_coreRegistry->register('current_author', $model); |
119 | | - |
120 | | - |
121 | | - // 5. Build edit form |
122 | | - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ |
123 | | - $resultPage = $this->_initAction(); |
124 | | - $resultPage->getConfig()->getTitle()->prepend(__('Author: ' . $model->getNickName())); |
125 | | - |
126 | | - return $resultPage; |
127 | | - } |
128 | | -} |
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Venustheme |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Venustheme.com license that is |
| 8 | + * available through the world-wide-web at this URL: |
| 9 | + * http://www.venustheme.com/license-agreement.html |
| 10 | + * |
| 11 | + * DISCLAIMER |
| 12 | + * |
| 13 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 14 | + * version in the future. |
| 15 | + * |
| 16 | + * @category Venustheme |
| 17 | + * @package Ves_Blog |
| 18 | + * @copyright Copyright (c) 2016 Venustheme (http://www.venustheme.com/) |
| 19 | + * @license http://www.venustheme.com/LICENSE-1.0.html |
| 20 | + */ |
| 21 | +namespace Ves\Blog\Controller\Adminhtml\Author; |
| 22 | + |
| 23 | +use Magento\Backend\App\Action; |
| 24 | + |
| 25 | +class Edit extends \Magento\Backend\App\Action |
| 26 | +{ |
| 27 | + /** |
| 28 | + * Core registry |
| 29 | + * |
| 30 | + * @var \Magento\Framework\Registry |
| 31 | + */ |
| 32 | + protected $_coreRegistry = null; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var \Magento\Framework\View\Result\PageFactory |
| 36 | + */ |
| 37 | + protected $resultPageFactory; |
| 38 | + |
| 39 | + protected $authSession; |
| 40 | + |
| 41 | + /** |
| 42 | + * @param Action\Context $context |
| 43 | + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory |
| 44 | + * @param \Magento\Backend\Model\Auth\Session $authSession |
| 45 | + * @param \Magento\Framework\Registry $registry |
| 46 | + */ |
| 47 | + public function __construct( |
| 48 | + Action\Context $context, |
| 49 | + \Magento\Framework\View\Result\PageFactory $resultPageFactory, |
| 50 | + \Magento\Backend\Model\Auth\Session $authSession, |
| 51 | + \Magento\Framework\Registry $registry |
| 52 | + |
| 53 | + ) { |
| 54 | + $this->resultPageFactory = $resultPageFactory; |
| 55 | + $this->authSession = $authSession; |
| 56 | + $this->_coreRegistry = $registry; |
| 57 | + parent::__construct($context); |
| 58 | + } |
| 59 | + |
| 60 | + public function getCurrentUser() |
| 61 | + { |
| 62 | + return $this->authSession->getUser(); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * {@inheritdoc} |
| 67 | + */ |
| 68 | + protected function _isAllowed() |
| 69 | + { |
| 70 | + return $this->_authorization->isAllowed('Ves_Blog::author'); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Init actions |
| 75 | + * |
| 76 | + * @return \Magento\Backend\Model\View\Result\Page |
| 77 | + */ |
| 78 | + protected function _initAction() |
| 79 | + { |
| 80 | + // load layout, set active menu and breadcrumbs |
| 81 | + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ |
| 82 | + $resultPage = $this->resultPageFactory->create(); |
| 83 | + $resultPage->setActiveMenu('Ves_Blog::blog') |
| 84 | + ->addBreadcrumb(__('Blog'), __('Blog')) |
| 85 | + ->addBreadcrumb(__('My Profile'), __('My Profile')); |
| 86 | + return $resultPage; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Edit CMS page |
| 91 | + * |
| 92 | + * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect |
| 93 | + * @SuppressWarnings(PHPMD.NPathComplexity) |
| 94 | + */ |
| 95 | + public function execute() |
| 96 | + { |
| 97 | + // 1. Get ID and create model |
| 98 | + $author_id = $this->getRequest()->getParam('author_id'); |
| 99 | + $id = $this->getCurrentUser()->getUserId(); |
| 100 | + $model = $this->_objectManager->create('Ves\Blog\Model\Author'); |
| 101 | + |
| 102 | + // 2. Initial checking |
| 103 | + if($author_id) { |
| 104 | + $model->load($author_id); |
| 105 | + }elseif ($id) { |
| 106 | + $model->loadByUserId($id); |
| 107 | + if (!$model->getId()) { |
| 108 | + $data = $this->getCurrentUser()->getData(); |
| 109 | + $data['nick_name'] = $data['firstname'] . ' ' . $data['lastname']; |
| 110 | + $model->setData($data)->save(); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + // 3. Set entered data if was error when we do save |
| 115 | + $data = $this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true); |
| 116 | + if (!empty($data)) { |
| 117 | + $model->setData($data); |
| 118 | + } |
| 119 | + |
| 120 | + // 4. Register model to use later in blocks |
| 121 | + $this->_coreRegistry->register('current_author', $model); |
| 122 | + |
| 123 | + |
| 124 | + // 5. Build edit form |
| 125 | + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ |
| 126 | + $resultPage = $this->_initAction(); |
| 127 | + $resultPage->getConfig()->getTitle()->prepend(__('Author: ' . $model->getNickName())); |
| 128 | + |
| 129 | + return $resultPage; |
| 130 | + } |
| 131 | +} |
0 commit comments