Hi everyone,
just a small question, maybe I don’t see the forest bc of the trees:
What I need is a CheckboxSetField in the cms backend, currently it works with the last names of some people, but there are more than just 1 with the same last name - so I am trying to convince the CheckboxSetField to not only show the lastname in every checkbox title, but as well the first name ( like [checkbox] Myers, Michael
Btw, ‘Sprecher’ class has a firstname and a lastname.
Any ideas on that?
Thanks in advance to all of you!
JonoM, thanks for your reply - I don’t really get it, you mean I should write a function that manipulates the Sprechers Dataobject in a way that the ‘Name’ would be ‘Name’ . ’ '. ‘Firstname’ and then push it into the checkboxsetfield function?
When deciding what to use as a title for a dataobject in the CMS, Silverstripe will call getTitle() on the dataobject. By default (from memory) this will return the value of the Title or Name database field id present, but you can override this method to return whatever you like.
It shouldn’t interfere with any saving, it’s only the ID that is used for this. When you pass DataObject::get('Sprecher') that would be reduced to a simple key/value array behind the scenes. See the API docs for an example: SilverStripe\Forms\CheckboxSetField | SilverStripe API
Edit: If you have a database field named Title on this dataobject, then yes, it would interfere with saving and you shouldn’t do this . But I’m assuming since you have FirstName and LastName that you don’t have a Title field.
Yes but I’m going from memory here best to give it a shot and see what happens! You can loop over DataObject::get('Sprecher') and create a custom array from it to pass to your CheckboxSetField constructor if the getTitle() approach doesn’t work.
One point is this will change the name in the CMS UI for these records when editing. If you don’t want that and you only want to change it for this situation you could do: