Events

Using the symfony event system allows to customize the way Diem works

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

Working with 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  
  }  
}  

Events list

Core events

Core events are notified in both admin and front applications.

dm.context.loaded

fired by dmContext when it's fully loaded with a ready to go serviceContainer
parameters: none

dm.context.end

fired by dmContext when application has been successfully executed
parameters: none

dm.browser.unknown

fired by dmBrowser when it is unable to configure itself from user agent because it is unknown
parameters: the user agent string

dm.record.modification

fired by dmDoctrineRecord when it will be saved or deleted
parameters: array('type' => create|update|delete)

dm.refresh

fired by dmCoreActions when user refreshed the site.
parameters: none

dm.cache.clear

fired by dmCacheCleaner when all cache has been cleared
parameters: array(success => wether the cache has been cleared successfully )

dm.cache.clear_template

fired by dmCacheCleaner when template cache has been cleared
parameters: none

dm.service_container.configuration

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)

dm.data.before

fired by dmDataTask before loading data
parameters: none

dm.data.after

fired by dmDataService after loading data
parameters: none

Admin events

Admin events are only notified in admin application.

dm.admin.filter_menu

fired by dmAdminMenu when it has been loaded. With this event you can modify the menu array.
parameters: none
value: array the loaded menu

fired by dmAdminBreadcrumb before rendering links. With this event you can modify breadCrumb links just before rendering.
parameters: none
value: array of linkType => options

dm.search.populated

fired by dmSearchIndex when index has been written to disk
parameters: array(name => index name, nb_documents => number of documents generated, time => population time in seconds)

dm.sitemap.generated

fired by dmSitemap when sitemap has been written to disk
parameters: array(file => full server path, url => full web path)

dm.config.updated

fired by static dmConfig when a value has been changed
parameters: array(setting => DmSetting record, culture => culture value)

admin.edit_object

fired by an admin module edit action when a record will be edited or updated
parameters: array(object => dmDoctrineRecord instance)

Front events

Front events are only notified in front application.

dm.layout.filter_stylesheets

fired by dmCoreLayoutHelper before rendering stylesheets. With this event you can modify stylesheets just before rendering.
parameters: none
value: array of stylesheets => options

dm.layout.filter_javascripts

fired by dmCoreLayoutHelper before rendering javascripts. With this event you can modify javascripts just before rendering.
parameters: none
value: array of javascripts => options

dm.layout.filter_metas

fired by dmCoreLayoutHelper before rendering metas. With this event you can modify metas just before rendering.
parameters: none
value: array of name => value

dm.theme.created

fired by dmTheme when it has finished creating its filesystem structure
parameters: none

dm.context.change_page

fired by dmFrontContext when current page has changed
parameters: array('page' => DmPage record)

dm.bread_crumb.filter_pages

fired by dmWidgetNavigationBreadcrumb before rendering page links. With this event you can modify breadCrumb pages.
parameters: none
value: array of module.action => DmPage record

dm.page_not_found.before

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)

dm.page_not_found.after

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)

Questions and Feedback

If you need support or have a technical question, you can

  • Post to the google group
  • Come and chat on the #diem IRC channel on freenode