Skip to content

Commit

Permalink
create defautl blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestaSafe committed Mar 11, 2024
1 parent e4fd5ca commit b46c22e
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 25 deletions.
48 changes: 48 additions & 0 deletions classes/prettyblocks/blocks/CategoryDescriptionBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Copyright (c) Since 2020 PrestaSafe and contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@prestasafe.com so we can send you a copy immediately.
*
* @author PrestaSafe <contact@prestasafe.com>
* @copyright Since 2020 PrestaSafe and contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaSafe
*/

use PrestaSafe\PrettyBlocks\Interfaces\BlockInterface;

class CategoryDescriptionBlock implements BlockInterface
{
private $module;

public function __construct($module)
{
$this->module = $module;
}

public function registerBlocks(): array
{
return [
'name' => $this->module->l('Category description block'),
'description' => $this->module->l('Render category description in a block'),
'code' => 'prettyblocks_category_description',
'tab' => 'product',
'icon' => 'DocumentTextIcon',
'need_reload' => false,
'insert_default_values' => true,
'templates' => [
'default' => 'module:' . $this->module->name . '/views/templates/blocks/category/category_description_block.tpl',
],
];
}
}
48 changes: 48 additions & 0 deletions classes/prettyblocks/blocks/CmsContentBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Copyright (c) Since 2020 PrestaSafe and contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@prestasafe.com so we can send you a copy immediately.
*
* @author PrestaSafe <contact@prestasafe.com>
* @copyright Since 2020 PrestaSafe and contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaSafe
*/

use PrestaSafe\PrettyBlocks\Interfaces\BlockInterface;

class CmsContentBlock implements BlockInterface
{
private $module;

public function __construct($module)
{
$this->module = $module;
}

public function registerBlocks(): array
{
return [
'name' => $this->module->l('Cms content block'),
'description' => $this->module->l('Render CMS description in a block'),
'code' => 'prettyblocks_cms_content',
'tab' => 'product',
'icon' => 'DocumentTextIcon',
'need_reload' => false,
'insert_default_values' => true,
'templates' => [
'default' => 'module:' . $this->module->name . '/views/templates/blocks/cms/cms_content_block.tpl',
],
];
}
}
13 changes: 2 additions & 11 deletions classes/prettyblocks/blocks/ProductDescriptionBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,12 @@ public function registerBlocks(): array
'description' => $this->module->l('Render product description in a block'),
'code' => 'prettyblocks_product_description',
'tab' => 'product',
'icon' => 'CommandLineIcon',
'icon' => 'DocumentTextIcon',
'need_reload' => false,
'insert_default_values' => true,
'templates' => [
'default' => 'module:' . $this->module->name . '/views/templates/blocks/products/product_description_block.tpl',
],
'config' => [
'fields' => [
'code' => [
'type' => 'textarea',
'label' => $this->module->l('Smarty code'),
'default' => '',
],
],
],
]
];
}
}
13 changes: 2 additions & 11 deletions classes/prettyblocks/blocks/ProductDescriptionShortBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,12 @@ public function registerBlocks(): array
'description' => $this->module->l('Render product description short in a block'),
'code' => 'prettyblocks_product_description_short',
'tab' => 'product',
'icon' => 'CommandLineIcon',
'icon' => 'DocumentTextIcon',
'need_reload' => false,
'insert_default_values' => true,
'templates' => [
'default' => 'module:' . $this->module->name . '/views/templates/blocks/products/product_description_short_block.tpl',
],
'config' => [
'fields' => [
'code' => [
'type' => 'textarea',
'label' => $this->module->l('Smarty code'),
'default' => '',
],
],
],
]
];
}
}
48 changes: 48 additions & 0 deletions classes/prettyblocks/blocks/TinySlider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Copyright (c) Since 2020 PrestaSafe and contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@prestasafe.com so we can send you a copy immediately.
*
* @author PrestaSafe <contact@prestasafe.com>
* @copyright Since 2020 PrestaSafe and contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaSafe
*/

use PrestaSafe\PrettyBlocks\Interfaces\BlockInterface;

class TinySlider implements BlockInterface
{
private $module;

public function __construct($module)
{
$this->module = $module;
}

public function registerBlocks(): array
{
return [
'name' => $this->module->l('Tiny Slider'),
'description' => $this->module->l('Render a simple and nice slider'),
'code' => 'prettyblocks_tiny_slider',
'tab' => 'sliders',
'icon' => 'RectangleStackIcon',
'need_reload' => false,
'insert_default_values' => true,
'templates' => [
'default' => 'module:' . $this->module->name . '/views/templates/blocks/tinyslider/default.tpl',
],
];
}
}
51 changes: 48 additions & 3 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,47 @@ private function _addDynamicZones()
$this->context->smarty->assign('product', $product);
}
}

if ($this->context->controller->php_self == 'category') {
// categories
if (isset($smartyVars['category'])) {
$category = $smartyVars['category'];
$zone_name = 'category_description_' . $smartyVars['category']['id'];
// si no blocks on this zone, feed product description
if (!HelperBuilder::zoneHasBlock($zone_name)) {
$this->registerBlockToZone($zone_name, 'prettyblocks_category_description');
}
$description = $this->renderZone(
[
'zone_name' => $zone_name,
'priority' => true,
'alias' => 'Description catégorie',
]
);
$category['description'] = $description;
$this->context->smarty->assign('category', $category);
}
}
// cms
if ($this->context->controller->php_self == 'cms') {
if (isset($smartyVars['cms'])) {
$cms = $smartyVars['cms'];
$zone_name = 'cms_description_' . $smartyVars['cms']['id'];
// si no blocks on this zone, feed product description
if (!HelperBuilder::zoneHasBlock($zone_name)) {
$this->registerBlockToZone($zone_name, 'prettyblocks_cms_content');
}
$description = $this->renderZone(
[
'zone_name' => $zone_name,
'priority' => true,
'alias' => 'Description CMS',
]
);
$cms['content'] = $description;
$this->context->smarty->assign('cms', $cms);
}
}
}

public function hookdisplayHeader($params)
Expand Down Expand Up @@ -416,10 +457,14 @@ public function hookActionRegisterThemeSettings()
*/
public function hookActionRegisterBlock($params)
{
return HelperBuilder::renderBlocks([
// new SmartyRender($this),
$defaultsBlocks = [
new ProductDescriptionBlock($this),
new ProductDescriptionShortBlock($this),
]);
new CmsContentBlock($this),
new CategoryDescriptionBlock($this),
];
// https://preview.keenthemes.com/html/keen/docs/general/tiny-slider/overview
$defaultsBlocks[] = new TinySlider($this);
return HelperBuilder::renderBlocks($defaultsBlocks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{if isset($category) && isset($category.description)}
{$category.description nofilter}
{/if}
3 changes: 3 additions & 0 deletions views/templates/blocks/cms/cms_content_block.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{if isset($cms) && isset($cms.content)}
{$cms.content nofilter}
{/if}
1 change: 1 addition & 0 deletions views/templates/blocks/tinyslider/default.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Helloo slider

0 comments on commit b46c22e

Please sign in to comment.