Set "title field" at a meaningful point in TagField instantiation

* Added parameter to SilverStripe\TagFieldTagField::__construct()
* Modified SilverStripe\TagFieldTagField::getOptions() to use assigned title field
* Modified SilverStripe\TagFieldTagField::getValue() to use assigned title field
This commit is contained in:
Jackson 2018-04-06 13:47:49 +12:00
parent 7691fc27c6
commit 7a286d432d

View File

@ -66,9 +66,10 @@ class TagField extends DropdownField
* @param null|DataList $source
* @param null|DataList $value
*/
public function __construct($name, $title = '', $source = [], $value = null)
public function __construct($name, $title = '', $source = [], $value = null, $titleField = 'Title')
{
$this->setSourceList($source);
$this->setTitleField($titleField);
parent::__construct($name, $title, $source, $value);
}
@ -254,10 +255,10 @@ class TagField extends DropdownField
}
if (is_array($values)) {
$values = DataList::create($dataClass)->filter('Title', $values);
$values = DataList::create($dataClass)->filter($this->titleField, $values);
}
$ids = $values->column('Title');
$ids = $values->column($this->titleField);
$titleField = $this->getTitleField();
@ -283,10 +284,10 @@ class TagField extends DropdownField
$name = $this->getName();
if ($source->hasMethod($name)) {
$value = $source->$name()->column('Title');
$value = $source->$name()->column($this->titleField);
}
} elseif ($value instanceof SS_List) {
$value = $value->column('Title');
$value = $value->column($this->titleField);
}
if (!is_array($value)) {