Skip to content

Commit

Permalink
Set "title field" at a meaningful point in TagField instantiation
Browse files Browse the repository at this point in the history
* Added parameter to SilverStripe\TagFieldTagField::__construct()
* Modified SilverStripe\TagFieldTagField::getOptions() to use assigned title field
* Modified SilverStripe\TagFieldTagField::getValue() to use assigned title field
  • Loading branch information
Jackson committed Apr 6, 2018
1 parent 7691fc2 commit 7a286d4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/TagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -254,10 +255,10 @@ protected function getOptions()
}

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();

Expand All @@ -283,10 +284,10 @@ public function setValue($value, $source = null)
$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)) {
Expand Down

0 comments on commit 7a286d4

Please # to comment.