I am currently trying to develop a website using SilverStripe with the silverstripe-multivaluefield module.
I managed to mostly figure out how to wrangle it to do what I wanted but I ran into an issue when I use the data from a MultiValueField to populate a MultiValueCheckboxField.
What I am trying to achieve is being able define categories for a set of objects (for example books able to be set to Fantasy or Action), these books are stored as data objects (SortableObject) and are related to a page (SortableObjectPage).
I first set the categories using a MultiValueTextField on the SortableObjectPage and store the values in MultiValueField.
$fields->addFieldToTab('Root.Main', new MultiValueTextField('Categories'), 'Metadata’);
And it is stored in the database like so
I then access the ‘Categories’ MultiValueField and use it to populate a MultiValueCheckboxField when creating a SortableObject
$parentCategories = $this->SortableObjectSection()->Categories->Value;
$categoriesField = new MultiValueCheckboxField('RelatedCategories', 'Related Categories', $parentCategories);
This is how it’s stored in the database
This is where my problem is, instead of storing the strings such as ‘Fantasy’ or ‘Action’ it simply stores a number (I think it’s the index of the category in the array used to populate the Checkboxes) as the string in the database, which means I can’t access the strings on the template I am trying to make.
I have also attached the two files that define SortableObjectSection and SortableObject as txt files but they are usually php files.