/** * {@inheritdoc} */ public function buildDatagrid() { if ($this->datagrid) { return; } $filterParameters = $this->getFilterParameters(); // transform _sort_by from a string to a FieldDescriptionInterface for the datagrid. if (isset($filterParameters['_sort_by']) && is_string($filterParameters['_sort_by'])) { if ($this->hasListFieldDescription($filterParameters['_sort_by'])) { $filterParameters['_sort_by'] = $this->getListFieldDescription($filterParameters['_sort_by']); } else { $filterParameters['_sort_by'] = $this->getModelManager()->getNewFieldDescriptionInstance($this->getClass(), $filterParameters['_sort_by'], array()); $this->getListBuilder()->buildField(null, $filterParameters['_sort_by'], $this); } } // initialize the datagrid $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $filterParameters); $this->datagrid->getPager()->setMaxPageLinks($this->maxPageLinks); $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); // build the datagrid filter $this->configureDatagridFilters($mapper); // ok, try to limit to add parent filter if ($this->isChild() && $this->getParentAssociationMapping() && !$mapper->has($this->getParentAssociationMapping())) { $mapper->add($this->getParentAssociationMapping(), null, array('show_filter' => false, 'label' => false, 'field_type' => 'sonata_type_model_hidden', 'field_options' => array('model_manager' => $this->getModelManager()), 'operator_type' => 'hidden'), null, null, array('admin_code' => $this->getParent()->getCode())); } foreach ($this->getExtensions() as $extension) { $extension->configureDatagridFilters($mapper); } }
/** * {@inheritdoc} */ public function buildDatagrid() { if ($this->datagrid) { return; } // initialize the datagrid $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $this->getFilterParameters()); $this->datagrid->getPager()->setMaxPerPage($this->maxPerPage); $this->datagrid->getPager()->setMaxPageLinks($this->maxPageLinks); $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); // build the datagrid filter $this->configureDatagridFilters($mapper); // ok, try to limit to add parent filter if ($this->isChild() && $this->getParentAssociationMapping() && !$mapper->has($this->getParentAssociationMapping())) { $mapper->add($this->getParentAssociationMapping(), null, array('field_type' => 'sonata_type_model_reference', 'field_options' => array('model_manager' => $this->getModelManager()), 'operator_type' => 'hidden')); } foreach ($this->getExtensions() as $extension) { $extension->configureDatagridFilters($mapper); } }
/** * build the filter FieldDescription array * * @return void */ public function buildDatagrid() { if ($this->datagrid) { return; } // ok, try to limit to add parent filter if ($this->getParentAssociationMapping()) { $fieldDescription = $this->getModelManager()->getParentFieldDescription($this->getParentAssociationMapping(), $this->getClass()); $this->filterFieldDescriptions[$this->getParentAssociationMapping()] = $fieldDescription; } foreach ($this->filterFieldDescriptions as $fieldDescription) { $this->getDatagridBuilder()->fixFieldDescription($this, $fieldDescription); } $parameters = $this->getFilterParameters(); // initialize the datagrid $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $parameters); $this->datagrid->getPager()->setMaxPerPage($this->maxPerPage); $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); // build the datagrid filter $this->configureDatagridFilters($mapper); }
/** * build the filter FieldDescription array * * @return void */ public function buildFilterFieldDescriptions() { if ($this->loaded['filter_fields']) { return; } $this->loaded['filter_fields'] = true; $this->filterFieldDescriptions = $this->getBaseFields($this->filter); // ok, try to limit to add parent filter if ($this->getParentAssociationMapping()) { $fieldDescription = $this->getModelManager()->getParentFieldDescription($this->getParentAssociationMapping(), $this->getClass()); $this->filterFieldDescriptions[$this->getParentAssociationMapping()] = $fieldDescription; } foreach ($this->filterFieldDescriptions as $fieldDescription) { $this->getDatagridBuilder()->fixFieldDescription($this, $fieldDescription); } $parameters = array(); // build the values array if ($this->hasRequest()) { $parameters = array_merge($this->getModelManager()->getDefaultSortValues($this->getClass()), $this->datagridValues, $this->request->query->all()); // always force the parent value if ($this->isChild() && $this->getParentAssociationMapping()) { $parameters[$this->getParentAssociationMapping()] = $this->request->get($this->getParent()->getIdParameter()); } } // initialize the datagrid $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $parameters); $this->datagrid->getPager()->setMaxPerPage($this->maxPerPage); $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); // build the datagrid filter $this->buildFilterFieldDescriptions(); $this->configureDatagridFilters($mapper); foreach ($this->getFilterFieldDescriptions() as $fieldDescription) { $mapper->add($fieldDescription); } }