Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 911a2c2b authored by Nicolas's avatar Nicolas
Browse files

Développement du module

parent cb508ab6
No related branches found
Tags 1.0.0
No related merge requests found
Pipeline #478 failed
Showing
with 1796 additions and 0 deletions
# Created by https://www.gitignore.io/api/macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# End of https://www.gitignore.io/api/macos
<?php
namespace NicolasBejean\ContentManager\Api;
/**
* Interface ContentManagerRepositoryInterface
*
* @category PHP
* @package NicolasBejean\ContentManager\Api
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
interface ContentManagerRepositoryInterface
{
/**
* Save Content Manager
*
* @param \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface $contentManager
* @return \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function save(Data\ContentManagerInterface $contentManager);
/**
* Get Content Manager by ID
*
* @param int $id
* @return \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getById($id);
/**
* Get Content Manager by list
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \NicolasBejean\ContentManager\Api\Data\ContentManagerSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
/**
* Delete Content Manager
*
* @param \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface $contentManager
* @return bool true on success
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function delete(Data\ContentManagerInterface $contentManager);
/**
* Delete Content Manager by ID
*
* @param int $id
* @return bool true on success
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function deleteById($id);
}
<?php
namespace NicolasBejean\ContentManager\Api\Data;
/**
* Interface ContentManagerInterface
*
* @category PHP
* @package NicolasBejean\ContentManager\Api\Data
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
interface ContentManagerInterface
{
const ENTITY_ID = 'entity_id';
const TITLE = 'title';
const IDENTIFIER = 'identifier';
const CONTENT = 'content';
const IS_ACTIVE = 'is_active';
const CREATION_TIME = 'created_at';
const UPDATE_TIME = 'updated_at';
/**
* Get Content Manager ID
*
* @return mixed
*/
public function getId();
/**
* Get Content Manager Title
*
* @return mixed
*/
public function getTitle();
/**
* Get Content Manager Identifier
*
* @return mixed
*/
public function getIdentifier();
/**
* Get Content Manager Content
*
* @return mixed
*/
public function getContent();
/**
* Get Content Manager Creation Time
*
* @return mixed
*/
public function getCreationTime();
/**
* Get Content Manager Update Time
*
* @return mixed
*/
public function getUpdateTime();
/**
* Get Content Manager Is Active
*
* @return mixed
*/
public function isActive();
/**
* Set Content Manager ID
*
* @param $id
* @return mixed
*/
public function setId($id);
/**
* Set Content Manager Title
*
* @param $title
* @return mixed
*/
public function setTitle($title);
/**
* Set Content Manager Identifier
*
* @param $identifier
* @return mixed
*/
public function setIdentifier($identifier);
/**
* Set Content Manager Content
*
* @param $content
* @return mixed
*/
public function setContent($content);
/**
* Set Content Manager Creation Time
*
* @param $creationTime
* @return mixed
*/
public function setCreationTime($creationTime);
/**
* Set Content Manager Update Time
*
* @param $updateTime
* @return mixed
*/
public function setUpdateTime($updateTime);
/**
* Set Content Manager is Active
*
* @param $isActive
* @return mixed
*/
public function setIsActive($isActive);
}
<?php
namespace NicolasBejean\ContentManager\Api\Data;
use \Magento\Framework\Api\SearchResultsInterface;
/**
* Interface ContentManagerSearchResultsInterface
*
* @category PHP
* @package NicolasBejean\ContentManager\Api\Data
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
interface ContentManagerSearchResultsInterface extends SearchResultsInterface
{
/**
* Get Content Manager Items
*
* @return \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface[]
*/
public function getItems();
/**
* Set Content Manager Items
*
* @param \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface[] $items
* @return $this
*/
public function setItems(array $items);
}
<?php
namespace NicolasBejean\ContentManager\Api;
use \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface;
/**
* Interface GetContentManagerByIdentifierInterface
*
* @category PHP
* @package NicolasBejean\ContentManager\Api
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
interface GetContentManagerByIdentifierInterface
{
/**
* Load Content Manager data by given Item Identifier.
*
* @param string $identifier
* @param int $storeId
* @return ContentManagerInterface
*/
public function execute(string $identifier, int $storeId) : ContentManagerInterface;
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml;
use \Magento\Backend\Block\Widget\Grid\Container;
/**
* Class ContentManager
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class ContentManager extends Container
{
protected function _construct()
{
$this->_blockGroup = 'NicolasBejean_ContentManager';
$this->_controller = 'adminhtml_contentManager';
$this->_headerText = __('Content Manager');
$this->_addButtonLabel = __('Create New Content Manager');
parent::_construct();
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit;
use \Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
/**
* Class BackButton
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get Button Data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
'class' => 'back',
'sort_order' => 10
];
}
/**
* Get URL for back (reset) button
*
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/*/');
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit;
use \Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use \Exception;
/**
* Class DeleteButton
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class DeleteButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get Button Data
*
* @return array
* @throws Exception
*/
public function getButtonData()
{
$data = [];
if ($this->getContentManagerId()) {
$data = [
'label' => __('Delete Element'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\'' . __(
'Are you sure you want to do this?'
) . '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})',
'sort_order' => 20,
];
}
return $data;
}
/**
* URL to send delete requests to.
*
* @return string
* @throws Exception
*/
public function getDeleteUrl()
{
return $this->getUrl('*/*/delete', ['entity_id' => $this->getContentManagerId()]);
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit;
use \Magento\Backend\Block\Widget\Context;
use \Magento\Framework\Exception\LocalizedException;
use \Magento\Framework\Exception\NoSuchEntityException;
use \NicolasBejean\ContentManager\Api\ContentManagerRepositoryInterface;
/**
* Class GenericButton
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class GenericButton
{
/**
* @var Context
*/
protected $context;
/**
* @var ContentManagerRepositoryInterface
*/
protected $contentManagerRepository;
/**
* GenericButton constructor.
* @param Context $context
* @param ContentManagerRepositoryInterface $contentManagerRepository
*/
public function __construct(
Context $context,
ContentManagerRepositoryInterface $contentManagerRepository
) {
$this->context = $context;
$this->contentManagerRepository = $contentManagerRepository;
}
/**
* Get Content Manager ID
*
* @return int|null
* @throws LocalizedException
*/
public function getContentManagerId()
{
try {
return $this->contentManagerRepository->getById(
$this->context->getRequest()->getParam('entity_id')
)->getId();
} catch (NoSuchEntityException $e) {
} catch (LocalizedException $e) {
throw new LocalizedException(__('Content Manager with id "%1" does not exist.'));
}
return null;
}
/**
* Get URL by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->context->getUrlBuilder()->getUrl($route, $params);
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit;
use \Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use \Magento\Ui\Component\Control\Container;
/**
* Class SaveAndNewButton
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class SaveAndNewButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get Button Data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save and new'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'contentmanager_contentmanager_form.contentmanager_contentmanager_form',
'actionName' => 'save',
'params' => [
true,
[
'back' => 'new'
]
]
]
]
]
]
],
'class_name' => Container::DEFAULT_CONTROL,
];
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit;
use \Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use \Magento\Ui\Component\Control\Container;
/**
* Class SaveButton
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Edit
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* Get Button Data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'contentmanager_contentmanager_form.contentmanager_contentmanager_form',
'actionName' => 'save',
'params' => [
true,
[
'back' => 'continue'
]
]
]
]
]
]
],
'class_name' => Container::SPLIT_BUTTON,
'options' => $this->getOptions(),
];
}
/**
* Get Options
*
* @return array
*/
private function getOptions()
{
$options = [
[
'label' => __('Save & Duplicate'),
'id_hard' => 'save_and_duplicate',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'contentmanager_contentmanager_form.contentmanager_contentmanager_form',
'actionName' => 'save',
'params' => [
true,
[
'back' => 'duplicate'
]
]
]
]
]
]
]
],
[
'id_hard' => 'save_and_close',
'label' => __('Save & Close'),
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'contentmanager_contentmanager_form.contentmanager_contentmanager_form',
'actionName' => 'save',
'params' => [
true,
[
'back' => 'close'
]
]
]
]
]
]
]
]
];
return $options;
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Widget;
use \Magento\Backend\Block\Template\Context;
use \Magento\Backend\Block\Widget\Grid\Extended;
use \Magento\Backend\Helper\Data;
use \Magento\Framework\Data\Form\Element\AbstractElement;
use \Magento\Framework\Exception\LocalizedException;
use \Magento\Widget\Block\Adminhtml\Widget\Chooser as WidgetChooser;
use \NicolasBejean\ContentManager\Model\ContentManagerFactory;
use \NicolasBejean\ContentManager\Model\ResourceModel\ContentManager\CollectionFactory;
use \Exception;
/**
* Class Chooser for Content Manager
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Adminhtml\ContentManager\Widget
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class Chooser extends Extended
{
/**
* @var ContentManagerFactory
*/
protected $contentManagerFactory;
/**
* @var CollectionFactory
*/
protected $collectionFactory;
/**
* @param Context $context
* @param Data $backendHelper
* @param ContentManagerFactory $contentManagerFactory
* @param CollectionFactory $collectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Data $backendHelper,
ContentManagerFactory $contentManagerFactory,
CollectionFactory $collectionFactory,
array $data = []
) {
$this->contentManagerFactory = $contentManagerFactory;
$this->collectionFactory = $collectionFactory;
parent::__construct($context, $backendHelper, $data);
}
/**
* Content Manager construction, prepare grid params
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setDefaultSort('identifier');
$this->setDefaultDir('ASC');
$this->setUseAjax(true);
$this->setDefaultFilter(['chooser_enabled' => '1']);
}
/**
* Prepare chooser element HTML
*
* @param AbstractElement $element Form Element
* @return AbstractElement
* @throws LocalizedException
*/
public function prepareElementHtml(AbstractElement $element)
{
$uniqId = $this->mathRandom->getUniqueHash($element->getId());
$sourceUrl = $this->getUrl('nicolasbejeancontentmanager/contentmanager_widget/chooser', ['uniq_id' => $uniqId]);
/** @var WidgetChooser $chooser */
$chooser = $this->getLayout()->createBlock(
WidgetChooser::class
)->setElement(
$element
)->setConfig(
$this->getConfig()
)->setFieldsetId(
$this->getFieldsetId()
)->setSourceUrl(
$sourceUrl
)->setUniqId(
$uniqId
);
if ($element->getValue()) {
$contentManager = $this->contentManagerFactory->create()->load($element->getValue());
if ($contentManager->getId()) {
$chooser->setLabel($this->escapeHtml($contentManager->getTitle()));
}
}
$element->setData('after_element_html', $chooser->toHtml());
return $element;
}
/**
* Grid Row JS Callback
*
* @return string
*/
public function getRowClickCallback()
{
$chooserJsObject = $this->getId();
$js = '
function (grid, event) {
var trElement = Event.findElement(event, "tr");
var contentManagerId = trElement.down("td").innerHTML.replace(/^\s+|\s+$/g,"");
var contentManagerTitle = trElement.down("td").next().innerHTML;
' .
$chooserJsObject .
'.setElementValue(contentManagerId);
' .
$chooserJsObject .
'.setElementLabel(contentManagerTitle);
' .
$chooserJsObject .
'.close();
}
';
return $js;
}
/**
* Prepare Content Manager collection
*
* @return Extended
*/
protected function _prepareCollection()
{
$this->setCollection($this->collectionFactory->create());
return parent::_prepareCollection();
}
/**
* Prepare columns for image grid
*
* @return Extended
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn(
'chooser_id',
['header' => __('ID'), 'align' => 'right', 'index' => 'entity_id', 'width' => 50]
);
$this->addColumn(
'chooser_title',
['header' => __('Title'), 'align' => 'left', 'index' => 'title']
);
$this->addColumn(
'chooser_identifier',
['header' => __('Identifier'), 'align' => 'left', 'index' => 'identifier']
);
$this->addColumn(
'chooser_is_active',
[
'header' => __('Status'),
'index' => 'is_active',
'type' => 'options',
'options' => [0 => __('Disabled'), 1 => __('Enabled')]
]
);
return parent::_prepareColumns();
}
/**
* Get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('nicolasbejeancontentmanager/contentmanager_widget/chooser', ['_current' => true]);
}
}
<?php
namespace NicolasBejean\ContentManager\Block\Widget;
use \Magento\Framework\Filesystem;
use \Magento\Framework\UrlInterface;
use \Magento\Framework\App\Filesystem\DirectoryList;
use \Magento\Framework\Image\AdapterFactory as ImageAdapterFactory;
use \Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context;
use \Magento\Store\Model\ScopeInterface;
use \Magento\Store\Model\StoreManagerInterface;
use \Magento\Widget\Block\BlockInterface;
use \NicolasBejean\Base\Helper\ImageOptimizer;
use \NicolasBejean\ContentManager\Model\ContentManager as ContentManagerModel;
use \NicolasBejean\ContentManager\Model\ContentManagerRepository;
use \NicolasBejean\ContentManager\Model\ContentManagerFactory;
use \NicolasBejean\ContentManager\Model\Template\FilterProvider;
use \Exception;
use \Magento\Framework\Exception\LocalizedException;
use \Magento\Framework\Exception\NoSuchEntityException;
/**
* Class ContentManager for Widget
*
* @category PHP
* @package NicolasBejean\ContentManager\Block\Widget
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class ContentManager extends Template implements BlockInterface
{
/**
* @var string
*/
protected $_template = "widget/contentmanager/default.phtml";
/**
* @var FilterProvider
*/
protected $filterProvider;
/**
* Content Manager Factory
*
* @var ContentManagerFactory
*/
protected $contentManagerFactory;
/**
* @var ImageAdapterFactory
*/
protected $imageAdapterFactory;
/**
* Store manager
*
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* Filesystem instance
*
* @var Filesystem
*/
protected $filesystem;
/**
* @var array
*/
protected $resizeSettings = [];
/**
* @var array
*
* - constrainOnly[true]: Guarantee, that image picture will not be bigger, than it was. It is false by default.
* - keepAspectRatio[true]: Guarantee, that image picture width/height will not be distorted. It is true by default.
* - keepTransparency[true]: Guarantee, that image will not lose transparency if any. It is true by default.
* - keepFrame[false]: Guarantee, that image will have dimensions, set in $width/$height. Not applicable,
* if keepAspectRatio(false).
* - backgroundColor[null]: Default white
*/
protected $defaultSettings = [];
/**
* @var ImageOptimizer
*/
protected $imageOptimizer;
/**
* @var ContentManagerRepository
*/
private $contentManagerRepository;
/**
* @param Context $context
* @param FilterProvider $filterProvider
* @param ContentManagerFactory $contentManagerFactory
* @param ContentManagerRepository $contentManagerRepository
* @param CategoryRepository $categoryRepository
* @param ImageOptimizer $imageOptimizer
* @param ImageAdapterFactory $imageAdapterFactory
* @param array $data
*/
public function __construct(
Context $context,
FilterProvider $filterProvider,
ContentManagerFactory $contentManagerFactory,
ContentManagerRepository $contentManagerRepository,
ImageOptimizer $imageOptimizer,
ImageAdapterFactory $imageAdapterFactory,
array $data = []
) {
$this->storeManager = $context->getStoreManager();
$this->filesystem = $context->getFilesystem();
$this->filterProvider = $filterProvider;
$this->contentManagerFactory = $contentManagerFactory;
$this->contentManagerRepository = $contentManagerRepository;
$this->imageOptimizer = $imageOptimizer;
$this->imageAdapterFactory = $imageAdapterFactory;
parent::__construct($context, $data);
$this->defaultSettings = [
'constrainOnly' => $this->_scopeConfig->getValue('contentmanager/resize/constrain_only', ScopeInterface::SCOPE_STORE),
'keepAspectRatio' => $this->_scopeConfig->getValue('contentmanager/resize/keep_aspect_ratio', ScopeInterface::SCOPE_STORE),
'keepTransparency' => $this->_scopeConfig->getValue('contentmanager/resize/keep_transparency', ScopeInterface::SCOPE_STORE),
'keepFrame' => $this->_scopeConfig->getValue('contentmanager/resize/keep_frame', ScopeInterface::SCOPE_STORE),
'backgroundColor' => $this->_scopeConfig->getValue('contentmanager/resize/background_color', ScopeInterface::SCOPE_STORE),
'identifier' => $this->_scopeConfig->getValue('contentmanager/save/identifier', ScopeInterface::SCOPE_STORE),
'basename' => $this->_scopeConfig->getValue('contentmanager/save/basename', ScopeInterface::SCOPE_STORE),
'width' => $this->_scopeConfig->getValue('contentmanager/save/width', ScopeInterface::SCOPE_STORE),
'height' => $this->_scopeConfig->getValue('contentmanager/save/height', ScopeInterface::SCOPE_STORE),
'compression' => $this->_scopeConfig->getValue('contentmanager/save/compression', ScopeInterface::SCOPE_STORE)
];
}
/**
* Get Widget
*
* @return ContentManagerModel
*/
public function getWidget()
{
try {
/** @var ContentManagerModel $widget */
$widget = $this->contentManagerRepository->getById($this->getId());
return $widget;
} catch (LocalizedException $e) {
return null;
}
}
/**
* Récupère l'ID du slider
*/
public function getId()
{
return $this->getData('id');
}
/**
* Récupère le type de template du widget
*/
public function getTemplateType()
{
if ($this->getData('template_type') === '' || is_null($this->getData('template_type'))) {
return 'text';
}
return $this->getData('template_type');
}
/**
* Récupère la valeur pour l'ajout d'un titre
*/
public function getActiveTitle()
{
if ($this->getWidgetTitle() !== null) {
if ($this->getData('active_title') === 'true') {
return true;
}
return false;
}
return false;
}
/**
* Récupère le titre du widget
*/
public function getWidgetTitle()
{
return $this->getData('title');
}
/**
* Récupère la balise du titre du widget
*/
public function getWidgetTitleTag()
{
return $this->getData('title_tag');
}
/**
* Récupère le titre du Content Manager
*/
public function getActiveTitleElement()
{
if ($this->getData('active_title_element') === 'true') {
return true;
}
return false;
}
/**
* Récupère la balise pour le titre du Content Manager
*/
public function getWidgetTitleElementTag()
{
return $this->getData('title_element_tag');
}
/**
* Récupère la class CSS du titre du widget
*/
public function getWidgetTitleCSS()
{
return $this->getData('title_css_classes');
}
/**
* Récupère la valeur pour l'ajout d'un contenu en haut
*/
public function getActiveContentTop()
{
if ($this->getWidgetContentTop() !== null) {
if ($this->getData('active_content_top') === 'true') {
return true;
}
return false;
}
return false;
}
/**
* Récupère le contenu haut du widget
*/
public function getWidgetContentTop()
{
if (strlen($this->getData('content_top')) === 0) {
return false;
}
return $this->getData('content_top');
}
/**
* Récupère la valeur pour l'ajout d'un contenu en bas
*/
public function getActiveContentBottom()
{
if ($this->getWidgetContentBottom() !== null) {
if ($this->getData('active_content_bottom') === 'true') {
return true;
}
return false;
}
return false;
}
/**
* Récupère le contenu bas du widget
*/
public function getWidgetContentBottom()
{
if (strlen($this->getData('content_bottom')) === 0) {
return false;
}
return $this->getData('content_bottom');
}
/**
* Récupère la class CSS du contenu du widget
*/
public function getWidgetContentCSS()
{
if (strlen($this->getData('content_css_classes')) === 0) {
return false;
}
return $this->getData('content_css_classes');
}
/**
* Récupère la largeur de l'image du widget
*/
public function getWidth()
{
if (is_null($this->getData('width'))) {
return $this->defaultSettings['width'];
}
return $this->getData('width');
}
/**
* Récupère la hauteur de l'image du widget
*/
public function getHeight()
{
if (is_null($this->getData('height'))) {
return $this->defaultSettings['height'];
}
return $this->getData('height');
}
/**
* Récupère les classes CSS
*/
public function getCssClasses()
{
if (strlen($this->getData('css_classes')) === 0) {
return false;
}
return $this->getData('css_classes');
}
/**
* Récupère le CSS pour l'attribut style
*/
public function getExtraCss()
{
if (strlen($this->getData('extra_css')) === 0) {
return false;
}
return $this->getData('extra_css');
}
/**
* Récupère les attributs pour le data-bind
*/
public function getDataBind()
{
if (strlen($this->getData('data')) === 0) {
return false;
}
return $this->getData('data');
}
/**
* Récupère la valeur pour l'activation du wrapper
*/
public function getActiveWrapper()
{
if ($this->getData('active_wrapper') === 'true') {
return true;
}
return false;
}
/**
* Récupère les classes CSS complémentaires pour le wrapper
*/
public function getWrapperCssClasses()
{
if (strlen($this->getData('wrapper_css_classes')) === 0) {
return false;
}
return $this->getData('wrapper_css_classes');
}
/**
* Récupère la création du lien
*/
public function getActiveLink()
{
if ($this->getData('active_link') === 'true') {
return true;
}
return false;
}
/**
* Récupère le lien
*/
public function getLinkHref()
{
return $this->getData('link');
}
/**
* Récupère la cible du lien
*/
public function getLinkTarget()
{
return $this->getData('link_target');
}
/**
* Récupère le contenu du lien
*/
public function getLinkContent()
{
return $this->getData('link_content');
}
/**
* Prepare and set resize settings for image
*
* @param array $resizeSettings
*/
protected function initResizeSettings(array $resizeSettings)
{
// Init resize settings with default
$this->resizeSettings = $this->defaultSettings;
// Override resizeSettings only if key matches with existing settings
foreach ($resizeSettings as $key => $value) {
if (array_key_exists($key, $this->resizeSettings)) {
$this->resizeSettings[$key] = $value;
}
}
}
/**
* Permet d'optimiser les images
*
* @param $image
* @param null $width
* @param null $height
* @param array $settings
* @return string
* @throws NoSuchEntityException
*/
public function getResizeImage($image, $width = null, $height = null, array $settings = [])
{
/* Si c'est pas un fichier JPG, on retourne l'original */
if (substr($image, -3) != 'jpg') {
return $image;
}
$basename = str_replace('/media/catalog/category/', '', $image);
$settings['basename'] = $basename;
if ($image) {
if (is_string($image)) {
$isRelativeUrl = substr($image, 0, 1) === '/';
if ($isRelativeUrl) {
$image = ltrim($image, '/media/');
} else {
$image = 'mediamanager/image/' . $image;
}
}
}
$dirPath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$absolutePath = $dirPath->getAbsolutePath('') . $image;
if (!is_null($width)) {
$settings['width'] = (int)$width;
}
if (!is_null($height)) {
$settings['height'] = (int)$height;
}
if (!is_null($this->getData('quality'))) {
$settings['compression'] = (int)$this->getData('quality');
}
/* Initialise les options de redimensionnement */
$this->initResizeSettings($settings);
try {
return $this->imageOptimizer->getResizeImage($absolutePath, $dirPath->getAbsolutePath(''), $this->resizeSettings);
} catch (Exception $e) {
return $image;
}
}
/**
* Récupère la largeur de l'image du widget
*
* @param $imagePath
* @return int|mixed|null
*/
public function getResizedImageWidth($imagePath)
{
$dirPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB);
$absoluteImagePath = $dirPath->getAbsolutePath($imagePath);
return $this->imageOptimizer->getImageWidth($absoluteImagePath);
}
/**
* Récupère la hauteur de l'image du widget
*
* @param $imagePath
* @return int|mixed|null
*/
public function getResizedImageHeight($imagePath)
{
$dirPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB);
$absoluteImagePath = $dirPath->getAbsolutePath($imagePath);
return $this->imageOptimizer->getImageHeight($absoluteImagePath);
}
}
# Changelog
## [1.0.0] - 2020-05-11
### Added
- Développement du module
## Source
https://raw.githubusercontent.com/olivierlacan/keep-a-changelog/master/CHANGELOG.md
<?php
namespace NicolasBejean\ContentManager\Controller\Adminhtml;
use \Magento\Backend\App\Action;
use \Magento\Backend\App\Action\Context;
use \Magento\Backend\Model\View\Result\Page;
use \Magento\Framework\Registry;
/**
* Class ContentManager
*
* @category PHP
* @package NicolasBejean\ContentManager\Controller\Adminhtml
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
abstract class ContentManager extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'NicolasBejean_ContentManager::global';
/**
* Core registry
*
* @var Registry
*/
protected $coreRegistry;
/**
* @param Context $context
* @param Registry $coreRegistry
*/
public function __construct(Context $context, Registry $coreRegistry)
{
$this->coreRegistry = $coreRegistry;
parent::__construct($context);
}
/**
* Init page
*
* @param Page $resultPage
* @return Page
*/
protected function initPage($resultPage)
{
$resultPage->setActiveMenu('NicolasBejean_ContentManager::contentmanager')
->addBreadcrumb(__('Content Manager'), __('Content Manager'))
->addBreadcrumb(__('Content Manager'), __('Content Manager'));
return $resultPage;
}
}
<?php
namespace NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \Magento\Backend\Model\View\Result\Redirect;
use \Magento\Framework\Controller\ResultInterface;
use \NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \NicolasBejean\ContentManager\Model\ContentManager as ContentManagerModel;
use \Exception;
/**
* Class Delete
*
* @category PHP
* @package NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class Delete extends ContentManager
{
/**
* Delete action
*
* @return ResultInterface
*/
public function execute()
{
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
// check if we know what should be deleted
$id = $this->getRequest()->getParam('entity_id');
if ($id) {
try {
/** @var ContentManagerModel $model */
$model = $this->_objectManager->create(ContentManagerModel::class);
$model->load($id);
$model->delete();
// display success message
$this->messageManager->addSuccessMessage(__('You deleted the content manager.'));
// go to grid
return $resultRedirect->setPath('*/*/');
} catch (Exception $e) {
// display error message
$this->messageManager->addErrorMessage($e->getMessage());
// go back to edit form
return $resultRedirect->setPath('*/*/edit', ['entity_id' => $id]);
}
}
// display error message
$this->messageManager->addErrorMessage(__('We can\'t find an content manager to delete.'));
// go to grid
return $resultRedirect->setPath('*/*/');
}
}
<?php
namespace NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \Magento\Backend\App\Action\Context;
use \Magento\Backend\Model\View\Result\Page;
use \Magento\Backend\Model\View\Result\Redirect;
use \Magento\Framework\Controller\ResultInterface;
use \Magento\Framework\Registry;
use \Magento\Framework\View\Result\PageFactory;
use \NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \NicolasBejean\ContentManager\Model\ContentManager as ContentManagerModel;
/**
* Class Edit
*
* @category PHP
* @package NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class Edit extends ContentManager
{
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context, $coreRegistry);
}
/**
* Edit content manager
*
* @return ResultInterface
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute()
{
// 1. Get ID and create model
$id = $this->getRequest()->getParam('entity_id');
/** @var ContentManagerModel $model */
$model = $this->_objectManager->create(ContentManagerModel::class);
// 2. Initial checking
if ($id) {
$model->load($id);
if (!$model->getId()) {
$this->messageManager->addErrorMessage(__('This content manager no longer exists.'));
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
}
$this->coreRegistry->register('nicolasbejean_contentmanager_item', $model);
// 5. Build edit form
/** @var Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$this->initPage($resultPage)->addBreadcrumb(
$id ? __('Edit Content Manager') : __('New Content Manager'),
$id ? __('Edit Content Manager') : __('New Content Manager')
);
$resultPage->getConfig()->getTitle()->prepend(__('Content Manager'));
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getName() . ' (' . $model->getIdentifier() . ')' : __('New Content Manager'));
return $resultPage;
}
}
<?php
namespace NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \Magento\Backend\App\Action\Context;
use \Magento\Backend\Model\View\Result\Page;
use \Magento\Framework\App\Request\DataPersistorInterface;
use \Magento\Framework\Controller\ResultInterface;
use \Magento\Framework\Registry;
use \Magento\Framework\View\Result\PageFactory;
use \NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
/**
* Class Index
*
* @category PHP
* @package NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class Index extends ContentManager
{
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context, $coreRegistry);
}
/**
* Index action
*
* @return ResultInterface
*/
public function execute()
{
/** @var Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$this->initPage($resultPage)->getConfig()->getTitle()->prepend(__('Content Manager'));
$dataPersistor = $this->_objectManager->get(DataPersistorInterface::class);
$dataPersistor->clear('nicolasbejean_contentmanager_item');
return $resultPage;
}
}
<?php
namespace NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \Magento\Backend\App\Action;
use \Magento\Backend\App\Action\Context;
use \Magento\Framework\Controller\Result\Json;
use \Magento\Framework\Controller\ResultInterface;
use \NicolasBejean\ContentManager\Api\ContentManagerRepositoryInterface as ContentManagerRepository;
use \Magento\Framework\Controller\Result\JsonFactory;
use \NicolasBejean\ContentManager\Api\Data\ContentManagerInterface;
use \NicolasBejean\ContentManager\Model\ContentManager;
use \Exception;
/**
* Class InlineEdit
*
* @category PHP
* @package NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class InlineEdit extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'NicolasBejean_ContentManager::global';
/**
* @var ContentManagerRepository
*/
protected $contentManagerRepository;
/**
* @var JsonFactory
*/
protected $jsonFactory;
/**
* @param Context $context
* @param ContentManagerRepository $contentManagerRepository
* @param JsonFactory $jsonFactory
*/
public function __construct(
Context $context,
ContentManagerRepository $contentManagerRepository,
JsonFactory $jsonFactory
) {
$this->contentManagerRepository = $contentManagerRepository;
$this->jsonFactory = $jsonFactory;
parent::__construct($context);
}
/**
* @return ResultInterface
*/
public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->jsonFactory->create();
$error = false;
$messages = [];
if ($this->getRequest()->getParam('isAjax')) {
$postItems = $this->getRequest()->getParam('items', []);
if (!count($postItems)) {
$messages[] = __('Please correct the data sent.');
$error = true;
} else {
foreach (array_keys($postItems) as $id) {
/** @var ContentManager $contentManager */
$contentManager = $this->contentManagerRepository->getById($id);
try {
$contentManager->setData(array_merge($contentManager->getData(), $postItems[$id]));
$this->contentManagerRepository->save($contentManager);
} catch (Exception $e) {
$messages[] = $this->getErrorWithImageId(
$contentManager,
__($e->getMessage())
);
$error = true;
}
}
}
}
return $resultJson->setData([
'messages' => $messages,
'error' => $error
]);
}
/**
* Add Content Manager title to error message
*
* @param ContentManagerInterface $contentManager
* @param string $errorText
* @return string
*/
protected function getErrorWithImageId(ContentManagerInterface $contentManager, $errorText)
{
return '[Content Manager ID: ' . $contentManager->getId() . '] ' . $errorText;
}
}
<?php
namespace NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager;
use \Magento\Backend\App\Action;
use \Magento\Backend\Model\View\Result\Redirect;
use \Magento\Framework\App\ObjectManager;
use \Magento\Framework\Controller\ResultFactory;
use \Magento\Backend\App\Action\Context;
use \Magento\Framework\Exception\LocalizedException;
use \Magento\Ui\Component\MassAction\Filter;
use \NicolasBejean\ContentManager\Model\ContentManager as Model;
use \NicolasBejean\ContentManager\Model\ResourceModel\ContentManager as ResourceModel;
use \NicolasBejean\ContentManager\Model\ResourceModel\ContentManager\Collection;
use \NicolasBejean\ContentManager\Model\ResourceModel\ContentManager\CollectionFactory;
use \Exception;
/**
* Class MassDelete
*
* @category PHP
* @package NicolasBejean\ContentManager\Controller\Adminhtml\ContentManager
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://github.com/nicolasbejean/contentmanager/blob/master/licence.txt BSD Licence
* @link https://www.bejean.eu
*/
class MassDelete extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'NicolasBejean_ContentManager::global';
/**
* @var Filter
*/
protected $filter;
/**
* @var CollectionFactory
*/
protected $collectionFactory;
/**
* @param Context $context
* @param Filter $filter
* @param CollectionFactory $collectionFactory
*/
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory
)
{
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
}
/**
* Execute action
*
* @return Redirect
* @throws LocalizedException|Exception
*/
public function execute()
{
/** @var Collection $collection */
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
/** @var ResourceModel $resourceModel */
$resourceModel = ObjectManager::getInstance()->get(ResourceModel::class);
/** @var Model $item */
foreach ($collection as $item) {
$resourceModel->delete($item);
}
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment