Added query option to ModelType
This commit is contained in:
parent
0fbe363de6
commit
b71d71b963
|
@ -42,8 +42,12 @@ class ModelChoiceList extends ArrayChoiceList
|
||||||
* @var \Symfony\Component\Form\Util\PropertyPath
|
* @var \Symfony\Component\Form\Util\PropertyPath
|
||||||
*/
|
*/
|
||||||
private $propertyPath = null;
|
private $propertyPath = null;
|
||||||
|
/**
|
||||||
|
* Query
|
||||||
|
*/
|
||||||
|
private $query = null;
|
||||||
|
|
||||||
public function __construct($class, $property = null, $choices = array())
|
public function __construct($class, $property = null, $choices = array(), $queryObject = null)
|
||||||
{
|
{
|
||||||
$this->class = $class;
|
$this->class = $class;
|
||||||
|
|
||||||
|
@ -52,6 +56,7 @@ class ModelChoiceList extends ArrayChoiceList
|
||||||
|
|
||||||
$this->table = $query->getTableMap();
|
$this->table = $query->getTableMap();
|
||||||
$this->identifier = $this->table->getPrimaryKeys();
|
$this->identifier = $this->table->getPrimaryKeys();
|
||||||
|
$this->query = $queryObject ?: $query;
|
||||||
|
|
||||||
// The property option defines, which property (path) is used for
|
// The property option defines, which property (path) is used for
|
||||||
// displaying models as strings
|
// displaying models as strings
|
||||||
|
@ -88,8 +93,7 @@ class ModelChoiceList extends ArrayChoiceList
|
||||||
if ($this->choices) {
|
if ($this->choices) {
|
||||||
$models = $this->choices;
|
$models = $this->choices;
|
||||||
} else {
|
} else {
|
||||||
$queryClass = $this->class . 'Query';
|
$models = $this->query->find();
|
||||||
$models = $queryClass::create()->find();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->choices = array();
|
$this->choices = array();
|
||||||
|
|
|
@ -30,6 +30,7 @@ class ModelType extends AbstractType
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'class' => null,
|
'class' => null,
|
||||||
'property' => null,
|
'property' => null,
|
||||||
|
'query' => null,
|
||||||
'choices' => array(),
|
'choices' => array(),
|
||||||
'preferred_choices' => array(),
|
'preferred_choices' => array(),
|
||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
|
@ -42,7 +43,8 @@ class ModelType extends AbstractType
|
||||||
$defaultOptions['choice_list'] = new ModelChoiceList(
|
$defaultOptions['choice_list'] = new ModelChoiceList(
|
||||||
$options['class'],
|
$options['class'],
|
||||||
$options['property'],
|
$options['property'],
|
||||||
$options['choices']
|
$options['choices'],
|
||||||
|
$options['query']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue