Skip to content

Commit

Permalink
Remove "Options" suffix from annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jan 16, 2022
1 parent e16f82e commit dacab2a
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -24,8 +24,8 @@ Documentation
* [Configuration](#configuration)
* [How does it work](#how-does-it-work)
* [Annotation](#annotation)
* [AdminOptions](#adminoptions)
* [AdminExtensionOptions](#adminextensionoptions)
* [Admin](#admin)
* [AdminExtension](#adminextension)

## Installation

Expand Down Expand Up @@ -77,7 +77,7 @@ admin classes and if autoconfigure is enabled we take the class name. If you
defined a suffix in the config (by default it is `Admin`) we remove it to get
the name of the entity, so if you had `CategoryAdmin` we get `Category`.

After that we check if the `AdminOption` annotation is present, annotations
After that we check if the `Admin` annotation is present, annotations
have a higher priority than our guesses. If no annotation is defined or some of
the values that are mandatory are not present we still try to guess.

Expand Down Expand Up @@ -130,7 +130,7 @@ public function setSomeService(SomeService $someService)

## Annotation

### AdminOptions
### Admin

```php
<?php
Expand All @@ -143,7 +143,7 @@ use App\Entity\Category;
use Sonata\AdminBundle\Admin\AbstractAdmin;

/**
* @Sonata\AdminOptions(
* @Sonata\Admin(
* label="Category",
* managerType="orm",
* group="Category",
Expand Down Expand Up @@ -171,7 +171,7 @@ final class CategoryAdmin extends AbstractAdmin
}
```

### AdminExtensionOptions
### AdminExtension

```php
<?php
Expand All @@ -182,7 +182,7 @@ use Nucleos\SonataAutoConfigureBundle\Annotation as Sonata;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;

/**
* @Sonata\AdminExtensionOptions(
* @Sonata\AdminExtension(
* global=true
* )
*/
Expand All @@ -201,7 +201,7 @@ use Sonata\AdminBundle\Admin\AbstractAdminExtension;
use App\Admin\ActivityAdmin;

/**
* @Sonata\AdminExtensionOptions(
* @Sonata\AdminExtension(
* target={"app.admin.project", ActivityAdmin::class}
* )
*/
Expand Down
Expand Up @@ -17,7 +17,7 @@
* @Annotation
* @Target("CLASS")
*/
final class AdminOptions
final class Admin
{
/**
* @var string
Expand Down
Expand Up @@ -17,7 +17,7 @@
* @Annotation
* @Target("CLASS")
*/
final class AdminExtensionOptions
final class AdminExtension
{
/**
* @var bool
Expand Down
Expand Up @@ -16,7 +16,7 @@
use Doctrine\Common\Annotations\Reader;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Nucleos\SonataAutoConfigureBundle\Annotation\AdminOptions;
use Nucleos\SonataAutoConfigureBundle\Annotation\Admin;
use Nucleos\SonataAutoConfigureBundle\Exception\EntityNotFound;
use ReflectionClass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down Expand Up @@ -87,11 +87,11 @@ public function process(ContainerBuilder $container): void
$name = preg_replace("/{$adminSuffix}$/", '', $name);
}

/** @var AdminOptions $annotation */
/** @var Admin $annotation */
$annotation = $annotationReader->getClassAnnotation(
new ReflectionClass($adminClass),
AdminOptions::class
) ?? new AdminOptions();
Admin::class
) ?? new Admin();

$this->setDefaultValuesForAnnotation($inflector, $annotation, $name, $annotationDefaults);

Expand Down Expand Up @@ -127,7 +127,7 @@ public function process(ContainerBuilder $container): void
}
}

private function setDefaultValuesForAnnotation(Inflector $inflector, AdminOptions $annotation, string $name, array $defaults): void
private function setDefaultValuesForAnnotation(Inflector $inflector, Admin $annotation, string $name, array $defaults): void
{
if (!$annotation->label) {
$annotation->label = $inflector->capitalize(str_replace('_', ' ', $inflector->tableize($name)));
Expand Down
Expand Up @@ -14,7 +14,7 @@
namespace Nucleos\SonataAutoConfigureBundle\DependencyInjection\Compiler;

use Doctrine\Common\Annotations\Reader;
use Nucleos\SonataAutoConfigureBundle\Annotation\AdminExtensionOptions;
use Nucleos\SonataAutoConfigureBundle\Annotation\AdminExtension;
use ReflectionClass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -39,7 +39,7 @@ public function process(ContainerBuilder $container): void

$annotation = $annotationReader->getClassAnnotation(
new ReflectionClass($definitionClass),
AdminExtensionOptions::class
AdminExtension::class
);

if (!$annotation) {
Expand Down Expand Up @@ -70,12 +70,12 @@ public function process(ContainerBuilder $container): void
}
}

private function hasTargets(AdminExtensionOptions $annotation): bool
private function hasTargets(AdminExtension $annotation): bool
{
return \is_array($annotation->target) && \count($annotation->target) > 0;
}

private function getTagAttributes(string $target, AdminExtensionOptions $annotation): array
private function getTagAttributes(string $target, AdminExtension $annotation): array
{
$attributes['target'] = $target;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Admin/AnnotationAdmin.php
Expand Up @@ -17,7 +17,7 @@
use Nucleos\SonataAutoConfigureBundle\Tests\Fixtures\Entity\Category;

/**
* @Sonata\AdminOptions(
* @Sonata\Admin(
* label="This is a Label",
* entity=Category::class,
* group="not test",
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Admin/DisableAutowireEntityAdmin.php
Expand Up @@ -16,7 +16,7 @@
use Nucleos\SonataAutoConfigureBundle\Annotation as Sonata;

/**
* @Sonata\AdminOptions(autowireEntity=false, templates=null)
* @Sonata\Admin(autowireEntity=false, templates=null)
*/
class DisableAutowireEntityAdmin
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Admin/Extension/ExtensionWithoutOptions.php
Expand Up @@ -16,7 +16,7 @@
use Nucleos\SonataAutoConfigureBundle\Annotation as Sonata;

/**
* @Sonata\AdminExtensionOptions()
* @Sonata\AdminExtension()
*/
class ExtensionWithoutOptions
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Admin/Extension/GlobalExtension.php
Expand Up @@ -16,7 +16,7 @@
use Nucleos\SonataAutoConfigureBundle\Annotation as Sonata;

/**
* @Sonata\AdminExtensionOptions(
* @Sonata\AdminExtension(
* global=true
* )
*/
Expand Down
Expand Up @@ -16,7 +16,7 @@
use Nucleos\SonataAutoConfigureBundle\Annotation as Sonata;

/**
* @Sonata\AdminExtensionOptions(
* @Sonata\AdminExtension(
* target={"app.admin.category", "app.admin.media"}
* )
*/
Expand Down
Expand Up @@ -16,7 +16,7 @@
use Nucleos\SonataAutoConfigureBundle\Annotation as Sonata;

/**
* @Sonata\AdminExtensionOptions(
* @Sonata\AdminExtension(
* target={"app.admin.category"},
* priority=5
* )
Expand Down

0 comments on commit dacab2a

Please sign in to comment.