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.
Fork of Blameable. Add user auditing capabilites to a model: tracks who created and last updated a model.
config/schema.yml
Article:
actAs:
DmBlameable:
Run doctrine migrations, then dm:setup to build models, forms and filters.
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:
Extends Versionable.
config/schema.yml
Article:
actAs:
DmVersionable:
Run doctrine migrations, then dm:setup to build models, forms and filters.
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.
Fork of Sortable. Adds ability to sort your models. Move models up or down and move them before or after another record.
$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
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.
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.
Diem-only behavior. Allows to associate a undefined number of Medias to a record.
config/doctrine/schema.yml
Article:
actAs:
DmGallery:
Run doctrine migrations, then dm:setup to build models, forms and filters.
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
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); }
By default a DmGallery only accepts web images like jpg and png.
If you want to allow using other file types, you can change the form class:
config/doctrine/schema.yml
Article:
actAs:
DmGallery:
formClass: MyDmMediaForm
Then in this class, choose the allowed mime types:
lib/MyDmMediaForm.php
class MyDmMediaForm extends DmMediaForm { public function configure() { parent::configure(); // choose mime types allowed $this->setMimeTypeWhiteList(array( 'image/jpeg', 'image/png', 'video/x-flv' )); } }
In this example, both web images and FLV videos are accepted.
Makes easy to add tags to a record.
This behavior is provided by dmTagPlugin.
Makes easy to add comments to a record.
This behavior is provided by dmCommentPlugin.
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
The documentation is hosted on GitHub. Feel free to submit issues and patches!