jhekasoft / html-shortcode
This package is abandoned and no longer maintained.
No replacement package was suggested.
There is no license information available for the latest version (dev-master) of this package.
ZF2 module that allows render view helpers using HTML-code.
dev-master
2013-06-16 20:22 UTC
Requires
- php: >=5.3.3
- zendframework/zend-version: 2.*
This package is not auto-updated.
Last update: 2020-01-19 15:59:44 UTC
README
Module for Zend Framework 2 that allows render view helpers using HTML-code. You can use this module with editors like TinyMCE and CKEditor.
Installation
php composer.phar require jhekasoft/html-shortcode:dev-master
In application.config.php
add the following key to your modules
:
'modules' => array( //... 'HtmlShortcode', ),
Usage
At controller:
//... use HMShortCode\Filter\ShortCodeFilter; class IndexController { public function showAction() { //... $shortCodeFilter = new ShortCodeFilter(); $shortCodeFilter->setServiceLocator($this->getServiceLocator()); $item->text = $shortCodeFilter->filter($item->text); return array( 'item' => $item, ); } }
At entity:
//... use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorInterface; use HtmlShortcode\Filter\ShortcodeFilter; class Pages implements InputFilterAwareInterface, ServiceLocatorAwareInterface { public function exchangeArray($data) { $this->text = (isset($data['text'])) ? $data['text'] : null; // ShortCode filter $shortcodeFilter = new ShortcodeFilter(); $shortcodeFilter->setServiceLocator($this->getServiceLocator()); $this->filtered_text = $shortcodeFilter->filter($this->text); } public function setServiceLocator(ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; return $this; } public function getServiceLocator() { return $this->serviceLocator; } }
On bootstrap (except edit action):
//... public function onBootstrap($e) { $app = $e->getApplication(); $em = $app->getEventManager(); $em->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, function($e) { $match = $e->getRouteMatch(); $action = $match->getParam('action'); if ('edit' != $action) { $sm = $e->getApplication()->getServiceManager(); $view = $sm->get('ViewRenderer'); $filters = $view->getFilterChain(); $widgetFilter = new ShortCodeFilter(); $widgetFilter->setServiceLocator($sm); $filters->attach($widgetFilter, 50); $view->setFilterChain($filters); } }); }
HTML-code
Samples:
<span class="htmlshortcode" data-helper="soundBlock" data-params="[value1]"></div> <div class="htmlshortcode" data-helper="soundBlock" data-params="[value2]"></div> <span class="htmlshortcode" data-helper="soundBlock" data-params='[value3][{"size":"small"}]'></span>
Second parameter in last example is in JSON format.
The examples above are equivalent this php-code in view-script:
echo $this->soundBlock('value1'); echo $this->soundBlock('value2'); echo $this->soundBlock('value3', array("size" => "small"));