You are currently browsing documentation for Diem 5.0 - Switch to version5.1

Doctrine Behaviors

Add capabilities to your models

Diem provides natively some of the most popular Doctrine behaviors, also called extensions.
Some of them are slightly modified to make use of Diem features, and other ones are completely new and don't exist out of Diem.

DmBlameable

Fork of Blameable. Add user auditing capabilites to a model: tracks who created and last updated a model.

Differences with Blameable

  • CreatedBy & UpdatedBy are relations to the DmUser model
  • by default, the listener uses the authenticated DmUser.

Usage

Declaration:

config/schema.yml

Article:  
  actAs:  
    DmBlameable:  

Run doctrine migrations, then dm:setup to build models, forms and filters.

Show in admin list

To show the users in your admin module, add "created_by" and "updated_by" to the list display section:
apps/admin/modules/article/config/generator.yml

      list:  
        display:  
          - created_by  
          - updated_by  

This behavior is particularly usefull when used with the next one:

DmVersionable

Extends Versionable.

Differences with Versionable

  • fixed issue when used with Sortable behavior

Usage

Declaration:

config/schema.yml

Article:  
  actAs:  
    DmVersionable:  

Run doctrine migrations, then dm:setup to build models, forms and filters.

Browse versions, revert

Nothing more to do, a History button appeared in your model admin forms:

Click it and view all record versions, with graphical differences. Click "revert to revision x" to cancel changes and go back to an older version.

When used with DmBlameable, we know who created each version.

DmSortable

Fork of Sortable. Adds ability to sort your models. Move models up or down and move them before or after another record.

Differences with Sortable

  • uses the "is_active" field:
$record->getNext(); // returns the next record with is_active = true
$record->getNext(false); // returns the next record  
 
$record->getPrevious(); // returns the previous record with is_active = true  
$record->getPrevious(false); // returns the previous record  
  • added getNextQuery() and getPreviousQuery() methods
  • added "new" option to choose if new records are positioned at first or last position. Defaults to first.

Usage

Declaration

config/schema.yml

Article:  
  actAs:  
    DmSortable: { new: last } # new articles are moved to last position  

Run doctrine migrations, then dm:setup to build models, forms and filters.

Sort in admin

To enable sorting in your record admin module, add a "sortable" option in the list section:
apps/admin/modules/article/config/generator.yml

      list:  
        sortable: true  

A "Sort" button appears on the list page:

It leads to a sorting interface based on drag&drop.

DmGallery

Diem-only behavior. Allows to associate a undefined number of Medias to a record.

Usage

Declaration

config/doctrine/schema.yml

Article:  
  actAs:  
    DmGallery:  

Run doctrine migrations, then dm:setup to build models, forms and filters.

Preview in admin list

To display record images in its admin list, add the "dm_gallery" field to the generator list section:
apps/admin/modules/article/config/generator.yml

      list:  
        display:  
          - dm_gallery  

Modify in admin form

To allow writers to add images in the article gallery, add the "dm_gallery" field to the generator form section:
apps/admin/modules/article/config/generator.yml

      form:  
        display:  
          Gallery: [dm_gallery]  

As the Article model acts as a DmGallery, it has some new methods available:

// get a collection of medias related to the article, ordered by position
$medias = $article->getDmGallery();  
 
// get the number of medias related to the article  
$nbMedias = $article->getNbMedias();  
 
// get the first media related to the article  
$firstMedia = $article->getFirstMedia();  
 
// display all gallery medias  
foreach($article->getDmGallery() as $media)  
{  
  echo _media($media)->size(150, 150);  
}  

DmTaggable

Makes easy to add tags to a record.
This behavior is provided by dmTagPlugin.

DmCommentable

Makes easy to add comments to a record.
This behavior is provided by dmCommentPlugin.

Others

Here is a non exhaustive list of Doctrine behaviors known to work well with Diem:

Questions and Feedback

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

  • Get help with the Google Group
  • Get help with the Forum
  • Come and chat on the #diem IRC channel on freenode

The documentation is hosted on GitHub. Feel free to submit issues and patches!

Fork Diem on GitHub