Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
fix documentation about routes, , allow addroute without properties, …
Browse files Browse the repository at this point in the history
…rename admin class and add extra section to documentation
  • Loading branch information
kunicmarko20 committed Mar 23, 2018
1 parent ab1619e commit 528aa1b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
54 changes: 50 additions & 4 deletions README.md
Expand Up @@ -14,9 +14,9 @@ This bundle was greatly inspired by [IbrowsSonataAdminAnnotationBundle](https://
[![Latest Stable Version](https://poser.pugx.org/kunicmarko/sonata-annotation-bundle/v/stable)](https://packagist.org/packages/kunicmarko/sonata-annotation-bundle)
[![Latest Unstable Version](https://poser.pugx.org/kunicmarko/sonata-annotation-bundle/v/unstable)](https://packagist.org/packages/kunicmarko/sonata-annotation-bundle)

[![Build Status](https://travis-ci.org/kunicmarko20/SonataAnnotationBundle.svg?branch=master)](https://travis-ci.org/kunicmarko20/SonataAnnotationBundle)
[![Coverage Status](https://coveralls.io/repos/github/kunicmarko20/SonataAnnotationBundle/badge.svg?branch=master)](https://coveralls.io/github/kunicmarko20/SonataAnnotationBundle?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kunicmarko20/SonataAnnotationBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kunicmarko20/SonataAnnotationBundle/?branch=master)
[![Build Status](https://travis-ci.org/kunicmarko20/SonataAnnotationBundle.svg?branch=1.x)](https://travis-ci.org/kunicmarko20/SonataAnnotationBundle)
[![Coverage Status](https://coveralls.io/repos/github/kunicmarko20/SonataAnnotationBundle/badge.svg?branch=1.x)](https://coveralls.io/github/kunicmarko20/SonataAnnotationBundle?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kunicmarko20/SonataAnnotationBundle/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/kunicmarko20/SonataAnnotationBundle/?branch=master)

Documentation
-------------
Expand All @@ -39,6 +39,7 @@ Documentation
* [ListAction](#listaction)
* [DatagridValues](#datagridvalues)
* [ParentAssociationMapping](#parentassociationmapping)
* [Extending The Admin](#extending-the-admin)

## Installation

Expand Down Expand Up @@ -414,7 +415,7 @@ use App\Controller\YourCRUDController;
* controller=YourCRUDController::class
* )
*
* @Sonata\AddRoute(name="import", path="/import")
* @Sonata\AddRoute("import")
* @Sonata\AddRoute(name="send_mail", path="{id}/send_mail")
*
* @ORM\Table
Expand Down Expand Up @@ -607,3 +608,48 @@ class Category
private $parent;
}
```

### Extending The Admin

Sometimes you need to do something custom and this bundle can't help you with
that but you still want to use annotations for most of the other stuff. You can
extend our admin class `KunicMarko\SonataAnnotationBundle\Admin\AnnotationAdmin`
and overwrite the methods you need.

```php
<?php

namespace App\Admin;

use KunicMarko\SonataAnnotationBundle\Admin\AnnotationAdmin;

class YourAdmin extends AnnotationAdmin
{
//do what you want
}
```

And then in your entity you just provide that class

```php
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Admin\YourAdmin;

/**
* @Sonata\Admin(
* label="Category",
* admin=YourAdmin::class
* )
*
* @ORM\Table
* @ORM\Entity
*/
class Category
{
}
```
7 changes: 5 additions & 2 deletions src/Admin/Admin.php → src/Admin/AnnotationAdmin.php
Expand Up @@ -25,7 +25,7 @@
/**
* @author Marko Kunic <kunicmarko20@gmail.com>
*/
class Admin extends AbstractAdmin
class AnnotationAdmin extends AbstractAdmin
{
private $parentAssociationMappingLoaded = false;
private $datagridValuesLoaded = false;
Expand Down Expand Up @@ -59,7 +59,10 @@ protected function configureRoutes(RouteCollection $collection): void
[$addRoutes, $removeRoutes] = $this->get(RouteReader::class)->getRoutes($this->getReflectionClass());

foreach ($addRoutes as $route) {
$collection->add($route->name, $this->replaceIdParameterInRoutePath($route->path));
$collection->add(
$route->name,
$route->path ? $this->replaceIdParameterInRoutePath($route->path) : $route->name
);
}

foreach ($removeRoutes as $route) {
Expand Down
4 changes: 2 additions & 2 deletions src/Annotation/Admin.php
Expand Up @@ -4,7 +4,7 @@

namespace KunicMarko\SonataAnnotationBundle\Annotation;

use KunicMarko\SonataAnnotationBundle\Admin\Admin as AdminClass;
use KunicMarko\SonataAnnotationBundle\Admin\AnnotationAdmin;

/**
* @Annotation
Expand Down Expand Up @@ -67,7 +67,7 @@ class Admin implements AnnotationInterface
/**
* @var string
*/
public $admin = AdminClass::class;
public $admin = AnnotationAdmin::class;

/**
* @var string
Expand Down
1 change: 0 additions & 1 deletion src/Reader/AbstractReader.php
Expand Up @@ -4,7 +4,6 @@

namespace KunicMarko\SonataAnnotationBundle\Reader;

use Doctrine\Common\Annotations\Reader;
use Sonata\AdminBundle\Mapper\BaseMapper;

/**
Expand Down

0 comments on commit 528aa1b

Please sign in to comment.