Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Sep 8, 2011
1 parent 82e2c3c commit 5eef7fd
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 123 deletions.
29 changes: 16 additions & 13 deletions Resources/doc/reference/advance.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
Advance
=======

By default services who are injected to the admin service are
method name | Service Id
---------------------------------------------------------------------
model_manager | sonata.admin.manager.%manager-type%
form_contractor | sonata.admin.builder.%manager-type%_form
show_builder | sonata.admin.builder.%manager-type%_show
list_builder | sonata.admin.builder.%manager-type%_list
datagrid_builder | sonata.admin.builder.%manager-type%_datagrid
translator | translator
configuration_pool | sonata.admin.pool
router | router
validator | validator
security_handler | sonata.admin.security.handler
By default services who are injected to an admin instance are

======================== =============================================
method name Service Id
======================== =============================================
model_manager sonata.admin.manager.%manager-type%
form_contractor sonata.admin.builder.%manager-type%_form
show_builder sonata.admin.builder.%manager-type%_show
list_builder sonata.admin.builder.%manager-type%_list
datagrid_builder sonata.admin.builder.%manager-type%_datagrid
translator translator
configuration_pool sonata.admin.pool
router router
validator validator
security_handler sonata.admin.security.handler

Note: %manager-type% is replace by the manager type (orm, odm...)

If you want to modify the service who are going to be injected, add the following code to your
application's config file:

.. code-block:: yaml
# app/config/config.yml
admins:
sonata_admin: #method name, you can find the list in the table above
Expand Down
45 changes: 23 additions & 22 deletions Resources/doc/reference/conditional_validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@ object. The object can be use to check assertion against a model :

.. code-block:: php
<?php
$errorElement
->with('settings.url')
->assertNotNull(array())
->assertNotBlank()
->end()
->with('settings.title')
->assertNotNull(array())
->assertNotBlank()
->assertMinLength(array('limit' => 50))
->addViolation('ho yeah!')
->end();
if (/* complex rules */) {
$errorElement->with('value')->addViolation('Fail to check the complex rules')->end()
}
/* conditional validation */
if ($this->getSubject()->getState() == Post::STATUS_ONLINE) {
$errorElement
->with('settings.url')
->assertNotNull(array())
->assertNotBlank()
->end()
->with('settings.title')
->assertNotNull(array())
->assertNotBlank()
->assertMinLength(array('limit' => 50))
->addViolation('ho yeah!')
->with('enabled')
->assertNotNull()
->assertTrue()
->end();
if (/* complex rules */) {
$errorElement->with('value')->addViolation('Fail to check the complex rules')->end()
}
/* conditional validation */
if ($this->getSubject()->getState() == Post::STATUS_ONLINE) {
$errorElement
->with('enabled')
->assertNotNull()
->assertTrue()
->end();
}
}
.. note::

Expand Down
1 change: 1 addition & 0 deletions Resources/doc/reference/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ files:

.. code-block:: php
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/reference/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Update notes for early users
* ListMapper now have an ``addIdentifier`` method
* internal Sonata Form Types must be set as second argument of the FormMapper

Example :
.. code-block:: php
<?php
namespace Sonata\NewsBundle\Admin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,53 +152,6 @@ This interface will display too many fields as some of them are not relevant to
a general overview. Next We'll see how to specify the fields we want to use and
how we want to use them.

Tweak the PostAdmin class
-------------------------

You can specify which field you want displayed for each action (list, form and filter)

.. code-block:: php
<?php
namespace Sonata\NewsBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Knp\Menu\MenuItem;
use Application\Sonata\NewsBundle\Entity\Comment;
class PostAdmin extends Admin
{
protected $list = array(
'title' => array('identifier' => true),
'slug',
'enabled',
'comments_enabled',
);
protected $form = array(
'enabled',
'title',
'abstract',
'content',
'tags' => array('form_field_options' => array('expanded' => true)),
'comments_enabled',
'comments_default_status'
);
protected $filter = array(
'title',
'enabled',
'tags' => array('filter_field_options' => array('expanded' => true, 'multiple' => true))
);
}
Now the different CRUD interfaces will look nicer!

So same goes for the TagAdmin and CommentAdmin class.

Tweak the TagAdmin class
Expand All @@ -210,24 +163,63 @@ Tweak the TagAdmin class
namespace Sonata\NewsBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
class TagAdmin extends Admin
{
protected $list = array(
'name' => array('identifier' => true),
'slug',
'enabled',
);
protected $form = array(
'id',
'name',
'enabled'
);
protected $filter = array(
'name'
);
/**
* @param \Sonata\AdminBundle\Form\FormMapper $formMapper
* @return void
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('enabled', null, array('required' => false))
;
}
/**
* @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
* @return void
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
->add('posts')
;
}
/**
* @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
* @return void
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('slug')
->add('enabled')
;
}
/**
* @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
* @param $object
* @return void
*/
public function validate(ErrorElement $errorElement, $object)
{
$errorElement
->with('name')
->assertMaxLength(array('limit' => 32))
->end()
;
}
}
Tweak the CommentAdmin class
Expand All @@ -243,34 +235,77 @@ Tweak the CommentAdmin class
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\NewsBundle\Entity\Comment;
use Application\Sonata\NewsBundle\Entity\Comment;
class CommentAdmin extends Admin
{
protected $list = array(
'name' => array('identifier' => true),
'getStatusCode' => array('label' => 'status_code', 'type' => 'string', 'sortable' => 'status'),
'post',
'email',
'url',
'message',
);
protected $form = array(
'name',
'email',
'url',
'message',
);
protected $filter = array(
'name',
'email',
'message'
);
protected function configureFormFields(FormMapper $form)
protected $parentAssociationMapping = 'post';
/**
* @param \Sonata\AdminBundle\Form\FormMapper $formMapper
* @return void
*/
protected function configureFormFields(FormMapper $formMapper)
{
$form->add('status', array('choices' => Comment::getStatusList()), array('type' => 'choice'));
if(!$this->isChild()) {
$formMapper->add('post', 'sonata_type_model', array(), array('edit' => 'list'));
// $formMapper->add('post', 'sonata_type_admin', array(), array('edit' => 'inline'));
}
$formMapper
->add('name')
->add('email')
->add('url', null, array('required' => false))
->add('message')
->add('status', 'choice', array('choices' => Comment::getStatusList(), 'expanded' => true, 'multiple' => false))
;
}
/**
* @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
* @return void
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
->add('email')
->add('message')
;
}
/**
* @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
* @return void
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('getStatusCode', 'text', array('label' => 'status_code', 'sortable' => 'status'))
->add('post')
->add('email')
->add('url')
->add('message');
}
/**
* @return array
*/
public function getBatchActions()
{
$actions = parent::getBatchActions();
$actions['enabled'] = array(
'label' => $this->trans('batch_enable_comments'),
'ask_confirmation' => false,
);
$actions['disabled'] = array(
'label' => $this->trans('batch_disable_comments'),
'ask_confirmation' => false
);
return $actions;
}
}

0 comments on commit 5eef7fd

Please sign in to comment.