|
@@ -22,9 +22,12 @@ use Sonata\AdminBundle\Datagrid\ListMapper;
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper;
|
|
|
|
|
|
use Sonata\AdminBundle\Admin\Pool;
|
|
|
+
|
|
|
use Sonata\AdminBundle\Builder\FormContractorInterface;
|
|
|
use Sonata\AdminBundle\Builder\ListBuilderInterface;
|
|
|
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
|
|
|
+use Sonata\AdminBundle\Builder\ViewBuilderInterface;
|
|
|
+
|
|
|
use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
|
|
|
use Sonata\AdminBundle\Route\RouteCollection;
|
|
|
use Sonata\AdminBundle\Model\ModelManagerInterface;
|
|
@@ -50,12 +53,27 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
|
|
|
/**
|
|
|
* The list FieldDescription constructed from the $list property
|
|
|
- * and the the configureListField method
|
|
|
+ * and the configureListField method
|
|
|
*
|
|
|
* @var array
|
|
|
*/
|
|
|
protected $listFieldDescriptions = array();
|
|
|
|
|
|
+ /**
|
|
|
+ * The view field definitions (quick property definition)
|
|
|
+ *
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $view = array();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The view FieldDescription constructed from the $view property
|
|
|
+ * and the configureListField method
|
|
|
+ *
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $viewFieldDescriptions = array();
|
|
|
+
|
|
|
/**
|
|
|
* The form field definition (quick property definition)
|
|
|
*
|
|
@@ -121,6 +139,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
*/
|
|
|
protected $formGroups = false;
|
|
|
|
|
|
+ /**
|
|
|
+ * The view group disposition
|
|
|
+ *
|
|
|
+ * @var array|boolean
|
|
|
+ */
|
|
|
+ protected $viewGroups = false;
|
|
|
+
|
|
|
/**
|
|
|
* The label class name (used in the title/breadcrumb ...)
|
|
|
*
|
|
@@ -267,6 +292,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
*/
|
|
|
protected $listBuilder;
|
|
|
|
|
|
+ /**
|
|
|
+ * The related view builder
|
|
|
+ *
|
|
|
+ * @var \Sonata\AdminBundle\View\ViewBuilderInterface
|
|
|
+ */
|
|
|
+ protected $viewBuilder;
|
|
|
+
|
|
|
/**
|
|
|
* The related datagrid builder
|
|
|
*
|
|
@@ -311,6 +343,8 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
'form_groups' => false,
|
|
|
'list_fields' => false,
|
|
|
'filter_fields' => false,
|
|
|
+ 'view_fields' => false,
|
|
|
+ 'view_groups' => false,
|
|
|
'routes' => false,
|
|
|
'side_menu' => false,
|
|
|
);
|
|
@@ -344,6 +378,15 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param DatagridMapper
|
|
|
+ */
|
|
|
+ protected function configureViewFields(DatagridMapper $filter)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* configure the Admin routes
|
|
|
*
|
|
@@ -433,6 +476,29 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * build the view FieldDescription array
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ protected function buildViewFieldDescriptions()
|
|
|
+ {
|
|
|
+ if ($this->loaded['view_fields']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->loaded['view_fields'] = true;
|
|
|
+
|
|
|
+ $this->viewFieldDescriptions = $this->getBaseFields($this->view);
|
|
|
+
|
|
|
+ // normalize field
|
|
|
+ foreach ($this->viewFieldDescriptions as $fieldDescription) {
|
|
|
+ $this->getViewBuilder()->fixFieldDescription($this, $fieldDescription);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->viewFieldDescriptions;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* build the list FieldDescription array
|
|
|
*
|
|
@@ -744,6 +810,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
$collection->add('batch');
|
|
|
$collection->add('edit', $this->getRouterIdParameter().'/edit');
|
|
|
$collection->add('delete', $this->getRouterIdParameter().'/delete');
|
|
|
+ $collection->add('view', $this->getRouterIdParameter().'/view');
|
|
|
|
|
|
// add children urls
|
|
|
foreach ($this->getChildren() as $children) {
|
|
@@ -854,6 +921,16 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
return 'SonataAdminBundle:CRUD:edit.html.twig';
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the view template
|
|
|
+ *
|
|
|
+ * @return string the view template
|
|
|
+ */
|
|
|
+ public function getViewTemplate()
|
|
|
+ {
|
|
|
+ return 'SonataAdminBundle:CRUD:view.html.twig';
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns an instance of the related classname
|
|
|
*
|
|
@@ -968,6 +1045,33 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * build the view group array
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function buildViewGroups()
|
|
|
+ {
|
|
|
+ if ($this->loaded['view_groups']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->loaded['view_groups'] = true;
|
|
|
+
|
|
|
+ if (!$this->viewGroups) {
|
|
|
+ $this->viewGroups = array(
|
|
|
+ false => array('fields' => array_keys($this->getViewFieldDescriptions()))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // normalize array
|
|
|
+ foreach ($this->viewGroups as $name => $group) {
|
|
|
+ if (!isset($this->viewGroups[$name]['collapsed'])) {
|
|
|
+ $this->viewGroups[$name]['collapsed'] = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns a form depend on the given $object
|
|
|
*
|
|
@@ -1131,11 +1235,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
return $this->maxPerPage;
|
|
|
}
|
|
|
|
|
|
- public function setFormGroups($formGroups)
|
|
|
- {
|
|
|
- $this->formGroups = $formGroups;
|
|
|
- }
|
|
|
-
|
|
|
public function getFormGroups()
|
|
|
{
|
|
|
$this->buildFormGroups();
|
|
@@ -1143,6 +1242,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
return $this->formGroups;
|
|
|
}
|
|
|
|
|
|
+ public function getViewGroups()
|
|
|
+ {
|
|
|
+ $this->buildViewGroups();
|
|
|
+
|
|
|
+ return $this->viewGroups;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* set the parent FieldDescription
|
|
|
*
|
|
@@ -1266,6 +1372,65 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
unset($this->formFieldDescriptions[$name]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * build and return the collection of form FieldDescription
|
|
|
+ *
|
|
|
+ * @return array collection of form FieldDescription
|
|
|
+ */
|
|
|
+ public function getViewFieldDescriptions()
|
|
|
+ {
|
|
|
+ $this->buildViewFieldDescriptions();
|
|
|
+
|
|
|
+ return $this->viewFieldDescriptions;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns the form FieldDescription with the given $name
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
|
|
|
+ */
|
|
|
+ public function getViewFieldDescription($name)
|
|
|
+ {
|
|
|
+ return $this->hasViewFieldDescription($name) ? $this->viewFieldDescriptions[$name] : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns true if the admin has a FieldDescription with the given $name
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function hasViewFieldDescription($name)
|
|
|
+ {
|
|
|
+ $this->buildViewFieldDescriptions();
|
|
|
+
|
|
|
+ return array_key_exists($name, $this->viewFieldDescriptions);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * add a FieldDescription
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function addViewFieldDescription($name, FieldDescriptionInterface $fieldDescription)
|
|
|
+ {
|
|
|
+ $this->viewFieldDescriptions[$name] = $fieldDescription;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * remove a FieldDescription
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function removeViewFieldDescription($name)
|
|
|
+ {
|
|
|
+ unset($this->viewFieldDescriptions[$name]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns the collection of list FieldDescriptions
|
|
|
*
|
|
@@ -1770,6 +1935,23 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
return $this->listBuilder;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param \Sonata\AdminBundle\Builder\ViewBuilderInterface $viewBuilder
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function setViewBuilder(ViewBuilderInterface $viewBuilder)
|
|
|
+ {
|
|
|
+ $this->viewBuilder = $viewBuilder;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return \Sonata\AdminBundle\Builder\ViewBuilderInterface
|
|
|
+ */
|
|
|
+ public function getViewBuilder()
|
|
|
+ {
|
|
|
+ return $this->viewBuilder;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param Pool $configurationPool
|
|
|
* @return void
|
|
@@ -1854,6 +2036,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
|
|
|
'EDIT' => array('EDIT'),
|
|
|
'LIST' => array('LIST'),
|
|
|
'CREATE' => array('CREATE'),
|
|
|
+ 'VIEW' => array('VIEW'),
|
|
|
'DELETE' => array('DELETE'),
|
|
|
'OPERATOR' => array('OPERATOR')
|
|
|
);
|