Diem uses the Symfony Event Dispatcher intensively.
This allows services to be decoupled. This allows you to alter the way they work without extend them.
See the symfony documentation about how to use events
A good place to listen events is the application configuration class :
require_once(dm::getDir().'/dmFrontPlugin/lib/config/dmFrontApplicationConfiguration.php'); class frontConfiguration extends dmFrontApplicationConfiguration { public function configure() { // Register our listeners $this->dispatcher->connect('dm.refresh', array($this, 'listenToRefreshEvent')); } public function listenToRefreshEvent(sfEvent $e) { // do something when project has been successfully refreshed } }
Core events are notified in both admin and front applications.
fired by dmContext when it's fully loaded with a ready to go serviceContainer
parameters: none
fired by dmContext when application has been successfully executed
parameters: none
fired by dmBrowser when it is unable to configure itself from user agent because it is unknown
parameters: the user agent string
fired by dmI18n when a translation is missing. The listener can assign a translation to the event's return value to handle the situation
parameters: array('string' => the untranslated string, 'args' => array, 'catalogue' => the current catalogue )
fired by dmDoctrineRecord when it will be saved or deleted
parameters: array('type' => create|update|delete)
fired by dmCoreActions when user refreshed the site.
parameters: none
fired by dmCacheCleaner when all cache has been cleared
parameters: array(success => wether the cache has been cleared successfully )
fired by dmCacheCleaner when template cache has been cleared
parameters: none
fired by dmServiceContainerLoaderConfiguration when the service container has been configured, before it is dumped to php
parameters: array(container => the service container, config => array key=>value config from dmConfig)
fired by dmDataLoad before loading data
parameters: none
fired by dmDataLoad after loading data
parameters: none
fired by dmSetupTask before updating the project
parameters: array(clear-db => wether the db will be cleared)
fired by dmSetupTask after updating the project
parameters: array(clear-db => wether the db has been cleared)
fired by DmPage when a page record has been saved.
parameters: none
fired by dmContext when dumping a new service container. With this event you can modify the service container just before it's dumped to PHP.
parameters: none
value: sfServiceContainerBuilder the service container builder ready to be dumped
fired by dmJavascriptCompressor before minifying a javascript file. With this event you can enable/disable the minification by returning true or false.
parameters: array( path => the javascript path )
value: minifiable whether the asset is minifiable or not
fired by dmJavascriptCompressor before caching a javascript file. With this event you can enable/disable the caching by returning true or false.
parameters: array( path => the javascript path, options => the javascript options )
value: cachable whether the asset is cachable or not
fired by dmSearchPageDocument just before indexing a page. With this event you can filter and modify the field boost values.
parameters: array( page => the current page we are indexing )
value: array( field_name => boost_value )
For example, if we want to make the page body more important for all article/show pages:
apps/front/config/frontConfiguration.class.php
class frontConfiguration extends dmFrontApplicationConfiguration { public function configure() { // connect to the dm.search.filter_boost_values event $this->getEventDispatcher()->connect( 'dm.search.filter_boost_values', array($this, 'listenToSearchFilterBoostValues') ); } // listen to the dm.search.filter_boost_values event public function listenToSearchFilterBoostValues(sfEvent $event, array $boostValues) { if($event['page']->isModuleAction('article', 'show')) { $boostValues['body'] = $boostValues['body'] * 2; } return $boostValues; }
You can throw a dmSearchPageNotIndexableException to exclude the page from the search index.
public function listenToSearchFilterBoostValues(sfEvent $event, array $boostValues) { if($event['page']->isModuleAction('main', 'sitemap')) { throw new dmSearchPageNotIndexableException(); } return $boostValues; }
fired by dmDoctrineTable just before returing seo columns. With this event you can filter and modify the seo columns of a table. Seo columns appear in automatic seo interface.
parameters: none
value: array( seo_column )
Admin events are only notified in admin application.
fired by dmAdminHomepageManager just before displaying the windows. With this event you can filter and modify the windows.
$this->dispatcher->connect('dm.admin_homepage.filter_windows', array($this, 'listenToFilterWindowsEvent')); //--------------------------------------------------------------------- public function listenToFilterWindowsEvent(sfEvent $event, array $windows) { // add a myWindow in second column $windows[1]['myWindow'] = array($this, 'renderMyWindow'); // change the existing weekChart renderer $windows[0]['weekChart'] = array($this, 'renderWeekChart'); return $windows; } // --------------------------------------------------------------------- public function renderMyWindow(dmHelper $helper) { // render the window with the $helper }
fired by dmAdminMenu when it has been initialized. With this event you can modify the admin menu.
parameters: none
fired by dmAdminBreadcrumb before rendering links. With this event you can modify breadCrumb links just before rendering.
parameters: none
value: array of linkType => options
fired by dmSearchIndex when index has been written to disk
parameters: array(culture => index culture, name => index name, nb_documents => number of documents generated, time => population time in seconds)
fired by dmSitemap when sitemap has been written to disk
parameters: array(file => full server path, url => full web path)
fired by static dmConfig when a value has been changed
parameters: array(setting => DmSetting record, culture => culture value)
fired by an admin module edit action when a record will be edited or updated
parameters: array(object => dmDoctrineRecord instance)
fired by dmMediaLibraryControlMenu when it's built. With this event you can change the menu just before it is rendered.
parameters: array(folder => DmMediaFolder the current folder)
fired by dmContentChart before building the chart. With this event you can change the modules shown in the chart.
parameters: none
value: array of module names
Front events are only notified in front application.
fired by dmCoreLayoutHelper before rendering stylesheets. With this event you can modify stylesheets just before rendering.
parameters: none
value: array of stylesheets => options
fired by dmCoreLayoutHelper before rendering javascripts. With this event you can modify javascripts just before rendering.
parameters: none
value: array of javascripts => options
fired by dmCoreLayoutHelper before rendering metas. With this event you can modify metas just before rendering.
parameters: none
value: array of name => value
fired by dmTheme when it has finished creating its filesystem structure
parameters: none
fired by dmFrontContext when current page has changed
parameters: array('page' => DmPage record)
fired by dmWidgetNavigationBreadcrumb before rendering links. With this event you can modify breadCrumb links.
parameters: array( page => DmPage record, the current page )
value: array of module.action => dmLinkTag
fired by dmWidgetNavigationBreadcrumb before rendering page links. With this event you can modify breadCrumb pages.
parameters: array( page => DmPage record, the current page )
value: array of module.action => DmPage record
fired by dmPageNotFoundHandler with a notifyUntil before searching for a possible redirection.
Assign an url to the event's return value to redirect the request.
parameters: array(slug => the not found slug)
fired by dmPageNotFoundHandler with a notifyUntil after searching for a possible redirection, and found nothing.
Assign an url to the event's return value to redirect the request.
parameters: array(slug => the not found slug)
fired by dmFrontAddMenu when it has been initialized. With this event you can modify the front add menu.
parameters: none
fired by dmFrontInitFilter to decide whether or not the current page should be cached. This event is notified when a page is about to be cached or served from the cache. You can return false to skip the cache and render the page normally. At this step of the execution, you don't have access to the DmPage record, so you must use the context and the request uri to decide if you allow the page cache or not.
parameters: array(context => the symfony context)
value: (boolean) true if the current page can be cached, false otherwise.
fired by dmFrontActions to decide whether or not the access to the current page is denied. This event is fired before processing any page, with the value true if access is denied, and "false" if access is granted. If you listen this event, return true to deny access or false to grant it. If access is denied, the request is forwarded to the main/signin page.
parameters: array(page => the current page, context => the current symfony context)
value: (boolean) true if access is denied, false otherwise.
Questions and Feedback
If you need support or have a technical question, you can
The documentation is hosted on GitHub. Feel free to submit issues and patches!