|
@@ -13,13 +13,11 @@ namespace Sonata\AdminBundle\Filter;
|
|
|
|
|
|
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
|
|
|
use Sonata\AdminBundle\Filter\FilterInterface;
|
|
|
-use Symfony\Component\Form\Configurable;
|
|
|
use Doctrine\ORM\QueryBuilder;
|
|
|
|
|
|
-abstract class Filter extends Configurable implements FilterInterface
|
|
|
+abstract class Filter implements FilterInterface
|
|
|
{
|
|
|
-
|
|
|
- protected $description = array();
|
|
|
+ protected $fieldDescription = array();
|
|
|
|
|
|
protected $name = null;
|
|
|
|
|
@@ -27,44 +25,52 @@ abstract class Filter extends Configurable implements FilterInterface
|
|
|
|
|
|
protected $value = null;
|
|
|
|
|
|
+ protected $options = array();
|
|
|
+
|
|
|
public function __construct(FieldDescriptionInterface $fieldDescription)
|
|
|
{
|
|
|
$this->name = $fieldDescription->getName();
|
|
|
- $this->description = $fieldDescription;
|
|
|
-
|
|
|
- parent::__construct($fieldDescription->getOption('filter_options', array()));
|
|
|
+ $this->fieldDescription = $fieldDescription;
|
|
|
+ $this->options = array_replace(
|
|
|
+ $this->getDefaultOptions(),
|
|
|
+ $this->fieldDescription->getOption('filter_options', array())
|
|
|
+ );
|
|
|
|
|
|
- $this->field = $this->getFormField();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * get the object description
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getDescription()
|
|
|
+ public function getName()
|
|
|
{
|
|
|
- return $this->description;
|
|
|
+ return $this->name;
|
|
|
}
|
|
|
|
|
|
- public function setName($name)
|
|
|
+ public function getField()
|
|
|
{
|
|
|
- $this->name = $name;
|
|
|
+ if (!$this->field) {
|
|
|
+ throw new \RuntimeException('No field attached');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->field;
|
|
|
}
|
|
|
|
|
|
- public function getName()
|
|
|
+ /**
|
|
|
+ * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
|
|
|
+ */
|
|
|
+ public function getFieldDescription()
|
|
|
{
|
|
|
- return $this->name;
|
|
|
+ return $this->fieldDescription;
|
|
|
}
|
|
|
|
|
|
- public function setField($field)
|
|
|
+ public function getDefaultOptions()
|
|
|
{
|
|
|
- $this->field = $field;
|
|
|
+ return array();
|
|
|
}
|
|
|
|
|
|
- public function getField()
|
|
|
+ public function getOption($name, $default = null)
|
|
|
{
|
|
|
- return $this->field;
|
|
|
- }
|
|
|
+ if (array_keys($this->options, $name)) {
|
|
|
+ return $this->options[$name];
|
|
|
+ }
|
|
|
|
|
|
+ return $default;
|
|
|
+ }
|
|
|
}
|