Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt
Note
titleVersion compatibility

This recipe is compatible with eZ Publish 5.2 / 2013.07

 

Table of Contents

Description

...

Info

To learn more about SignalSlot in eZ Publish, please refer to the dedicated documentation page.

Signals reference

This recipe will describe how to register a Slot for a dedicated Signal.

...

Code Block
languagephp
titleOnPublishSlot
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.

...