BootIq - CMS API vendor for Nette
, (*1)
, (*2)
Installation
For installation of Boot!Q CMS API vendor for Nette, use composer, (*3)
composer require bootiq/cms-api-vendor-nette
Configuration
Add Boot!Q CMS API vendor for Nette to your extensions:, (*4)
extensions:
- BootIq\CmsApiVendor\Nette\DI\CmsApiVendorExtension
Register adapter for communication by defining biq_cms_adapter to services configuration:, (*5)
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):, (*6)
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:, (*7)
/**
* @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:, (*8)
{block content}
Congratulations!
<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., (*9)
/**
* @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:, (*10)
/**
* @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:, (*11)
/**
* @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;
}