bootiq / cms-api-vendor-nette
B!Q CMS api vendor - nette implementation
Requires
- php: ^7.0
- bootiq/cms-api-vendor: ^00.01
- latte/latte: ^2.4
- nette/application: ^2.4
- nette/di: ^2.4
- nette/finder: ^2.4
- nette/utils: ^2.4
Requires (Dev)
- jakub-onderka/php-console-highlighter: ^0.3.2
- jakub-onderka/php-parallel-lint: ^0.9.2
- phpmd/phpmd: ^2.6
- phpstan/phpstan: ^0.8.5
- phpunit/phpunit: ^6.3
- sebastian/phpcpd: ^3.0
- slevomat/coding-standard: ^4.0
- squizlabs/php_codesniffer: ^3.1
This package is not auto-updated.
Last update: 2025-03-24 19:33:51 UTC
README
Installation
For installation of Boot!Q CMS API vendor for Nette, use composer
composer require bootiq/cms-api-vendor-nette
Configuration
Add Boot!Q CMS API vendor for Nette to your extensions:
extensions: - BootIq\CmsApiVendor\Nette\DI\CmsApiVendorExtension
Register adapter for communication by defining biq_cms_adapter to services configuration:
services: biq_cms_adapter: class: BootIq\CmsApiVendor\Adapter\GuzzleSecurityTokenAdapter(GuzzleHttp\Client(), BootIq\CmsApiVendor\Response\ResponseFactory(), %cms_api.urn%, %cms_api.publicId%, %cms_api.secret%)
Finally define parameters for configuration (name are used above in adapter definition):
parameters: cms_api: urn: "<cms.example.com/api>" publicId: "<public ID>" secret: "<secret>"
Usage
Inject PageControlFactory into your Presenter and create PageControl component. For example:
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); return $control; }
Now use PageControl component in your latte template:
{block content} <div id="banner"> <h1 n:block=title>Congratulations!</h1> </div> <div id="content"> <h2>You have successfully using Boot!Q CMS API vendor for Nette.</h2> <p> {control pageControl "/hello-workld-slug", false} </p> </div> {/block}
Modification
Fallbacks
If nothing is rendered, callback onNotRendered($mixed) is triggered. If one of the block is not rendered, callback onBlockNotRendered(Block $block, \Exception $exception) is triggered. Example of usage of our callback.
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); $control->onNotRendered[] = function ($exception) { // DO SOMETHING WITH EXCEPTION }; $control->onBlockNotRendered[] = function ($block, $exception) { // DO SOMETHING WITH BLOCK OR EXCEPTION }; return $control; }
Own BlockControl
If you want use your own BlockControl, simply create new Control which implements BootIq\CmsApiVendor\Nette\Control\Block\BlockControlInterface. Then register it to PageControl in createComponent method:
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); $myOwnBlockControl = new MyOwnBlockControl(); $control->addBlockControlByType($myOwnBlockControl, 'myOwnBlockType'); return $control; }
Logger
If you want log, what is going on in our PageControl simply set Logger to PageControl in createComponent method. Logger have to implement PSR-3 LoggerInterface. For example:
/** * @var PageControlFactory * @inject */ public $pageControlFactory; /** * @var LoggerInterface * @inject */ public $monologLogger; /** * @return PageControl */ public function createComponentPageControl(): PageControl { $control = $this->pageControlFactory->create(); $control->setLogger($this->monologLogger); return $control; }