From 7a286d432dcccc9a618829fcba6185418383e0dd Mon Sep 17 00:00:00 2001 From: Jackson Date: Fri, 6 Apr 2018 13:47:49 +1200 Subject: [PATCH 1/2] 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 --- src/TagField.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/TagField.php b/src/TagField.php index 96be219..45cf81e 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -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)) { From 1e40d07a98e04c2eb8b39a318420cca763b823e0 Mon Sep 17 00:00:00 2001 From: Jackson Date: Fri, 6 Apr 2018 14:18:14 +1200 Subject: [PATCH 2/2] Set "title field" at a meaningful point in TagField instantiation * Switch diet to dogfood --- src/TagField.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/TagField.php b/src/TagField.php index 45cf81e..409a9d9 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -65,6 +65,7 @@ class TagField extends DropdownField * @param string $title * @param null|DataList $source * @param null|DataList $value + * @param string $titleField */ public function __construct($name, $title = '', $source = [], $value = null, $titleField = 'Title') { @@ -255,10 +256,10 @@ class TagField extends DropdownField } if (is_array($values)) { - $values = DataList::create($dataClass)->filter($this->titleField, $values); + $values = DataList::create($dataClass)->filter($this->getTitleField(), $values); } - $ids = $values->column($this->titleField); + $ids = $values->column($this->getTitleField()); $titleField = $this->getTitleField(); @@ -284,10 +285,10 @@ class TagField extends DropdownField $name = $this->getName(); if ($source->hasMethod($name)) { - $value = $source->$name()->column($this->titleField); + $value = $source->$name()->column($this->getTitleField()); } } elseif ($value instanceof SS_List) { - $value = $value->column($this->titleField); + $value = $value->column($this->getTitleField()); } if (!is_array($value)) {