Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
magiccart committed Sep 27, 2023
1 parent dcc8e63 commit 2e1d89c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
45 changes: 45 additions & 0 deletions Block/System/Config/Form/Field/Snippet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @Author: Alex Dong
* @Date: 2023-09-27 14:42:40
* @Last Modified by: Alex Dong
* @Last Modified time: 2023-09-27 14:42:56
*/

namespace Magiccart\Shopbrand\Block\System\Config\Form\Field;

class Snippet extends \Magento\Config\Block\System\Config\Form\Field\Heading
{

/**
* Render element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return $this->_getElementHtml($element);
}

protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
// $html = $element->getElementHtml();
$html = '';
$value = $element->getData('value');
$shortcodeWidget = '{{widget type="Magiccart\Shopbrand\Block\Widget\Brand" template="brand.phtml"}}';
$shortcodeBlock = $this->_escaper->escapeHtml('<?= $block->getLayout()->createBlock(\'Magiccart\Shopbrand\Block\Widget\Brand\')->setTemplate(\'brand.phtml\')->toHtml();?>');
$html = '<ol class="shopbrand-snippet"><li>';
$html .= '<p>' . __('Add Widget name "Magiccart Shop Logo widget".') . '</p>';
$html .= '</li><li>';
$html .= '<span>' . __('Copy Short code add to CMS Page/Static Block.') . '</span>';
$html .= '<code style="display: block;background: #f5f5f5;padding: 15px; margin-top:15px">' . $shortcodeWidget . '</code>';
$html .= '</li><li>';
$html .= '<span>' . __('Template .phtml file. Open a .phtml file and insert where you want to display Brand Slider.') . '</span>';
$html .= '<code style="display: block;background: #f5f5f5;padding: 15px; margin-top:15px">' . $shortcodeBlock . '</code>';
$html .= '</li></ol>';

return $html;
}
}
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@
<source_model>Magiccart\Shopbrand\Model\System\Config\Col</source_model>
</field>
</group>
<group id="shortcode" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Short code</label>
<field id="snippet" translate="label comment" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Snippet</label>
<comment>Copy to code to page or block you want display Shopbrand</comment>
<frontend_model>Magiccart\Shopbrand\Block\System\Config\Form\Field\Snippet</frontend_model>
</field>
</group>
</section>
</system>
</config>
4 changes: 2 additions & 2 deletions etc/widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Magento/Widget/etc/widget.xsd">
<widget id="magiccart_brand" class="Magiccart\Shopbrand\Block\Widget\Brand">
<label translate="true">Brand Logo Widget</label>
<label translate="true">Magiccart Brand Logo Widget</label>
<description>Show Brands Logo</description>
<parameters>
<parameter name="template" xsi:type="select" required="true" visible="true">
Expand All @@ -26,7 +26,7 @@
</parameters>
</widget>
<widget id="magiccart_shopbrand" class="Magiccart\Shopbrand\Block\Widget\Shopbrand">
<label translate="true">Shop Brand Widget</label>
<label translate="true">Magiccart Shop Brand Widget</label>
<description>Show Brands Logo and Products</description>
<parameters>
<parameter name="template" xsi:type="select" required="true" visible="true">
Expand Down

0 comments on commit 2e1d89c

Please sign in to comment.