Excerpt | |||||
---|---|---|---|---|---|
|
Table of Contents |
---|
Description
...
Info |
---|
To learn more about SignalSlot in eZ Publish, please refer to the dedicated documentation page. |
This recipe will describe how to register a Slot for a dedicated Signal.
...
Code Block | ||||
---|---|---|---|---|
| ||||
namespace Acme\TestBundle\Slot; use eZ\Publish\Core\SignalSlot\Slot as BaseSlot; use eZ\Publish\APICore\RepositorySignalSlot\RepositorySignal; use eZ\Publish\SignalSlotAPI\SignalRepository\ContentService; class OnPublishSlot extends BaseSlot { /** * @var \eZ\Publish\API\Repository\ContentService */ private $contentService; public function __construct( ContentService $contentService ) { $this->contentService = $contentService; } public function receive( Signal $signal ) { if ( !$signal instanceof Signal\ContentService\PublishVersionSignal ) { return; } // Load published content $content = $this->contentService->loadContent( $signal->contentId, null, $signal->versionNo ); // Do stuff with it... } } |
...
eZ Publish comes with a generic slot that converts signals (including ones defined by user code) to regular event objects and expose them via the EventDispatcher. This makes it possible to implement a simple event listener/subscriber if you're more comfortable with this approach.
...