123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace Sonata\AdminBundle\Annotation;
- use JMS\DiExtraBundle\Annotation\MetadataProcessorInterface;
- use JMS\DiExtraBundle\Metadata\ClassMetadata;
- use Sonata\AdminBundle\Admin\AbstractAdmin as AdminClass;
- class Admin implements MetadataProcessorInterface
- {
-
- public $id;
-
- public $class;
-
- public $managerType = 'orm';
-
- public $pagerType;
-
- public $persistFilters;
-
- public $group;
-
- public $icon;
-
- public $label;
-
- public $baseControllerName = 'SonataAdminBundle:CRUD';
-
- public $translationDomain;
-
- public $showInDashboard = true;
-
- public $keepOpen = false;
-
- public $onTop = false;
-
- public function processMetadata(ClassMetadata $metadata)
- {
- $this->generateFallback($this->class);
- $this->validate();
- $tag = array(
- 'manager_type' => $this->managerType,
- 'group' => $this->group,
- 'label' => $this->label,
- 'show_in_dashboard' => $this->showInDashboard,
- 'icon' => $this->icon,
- 'pager_type' => $this->pagerType,
- 'persist_filters' => $this->persistFilters,
- 'keep_open' => $this->keepOpen,
- 'on_top' => $this->onTop,
- );
- $tag = array_filter($tag, function ($v) {
- return !is_null($v);
- });
- if (!empty($this->id)) {
- $metadata->id = $this->id;
- }
- $metadata->tags['sonata.admin'][] = $tag;
- $metadata->arguments = array($this->id, $this->class, $this->baseControllerName);
- if ($this->translationDomain) {
- $metadata->methodCalls[] = array('setTranslationDomain', array($this->translationDomain));
- }
- }
-
- private function validate()
- {
- if (!$this->showInDashboard) {
- return;
- }
- if (empty($this->group) || empty($this->label)) {
- throw new \LogicException(
- sprintf(
- 'Unable to generate admin group and label for class %s.',
- $this->class
- )
- );
- }
- }
-
- private function generateFallback($name)
- {
- if (empty($name)) {
- return;
- }
- if (preg_match(AdminClass::CLASS_REGEX, $name, $matches)) {
- if (empty($this->group)) {
- $this->group = $matches[3];
- }
- if (empty($this->label)) {
- $this->label = $matches[5];
- }
- }
- }
- }
|