Silverstripe Version:4.*
Question:
Within Admin → Security I added custom fields. And I want to add additional info (List of custom Apps for edited user) that would be represented best with a Html table. The problem with textarea is that it doesn’t support HTML elements (table, new line,…). The solution with TextareaField works but I cannot format it to what I need. I tried with GridField but I don’t know how to prepare the needed Object from the query. Is there an alternative (Something like HtmlField) I could use? Or a simple way to create an array to the object for GridField?
class MyMemberExtension extends DataExtension
{
private static $belongs_many_many = [
'LeftMenus' => LeftMenu::class,
];
public function updateCMSFields(FieldList $fields)
{
$fields->push(new TextField('VsMemberID', 'VS member ID'));
$fields->push(new TextField('NdaSignedDate', 'NDA Signed Date'));
$fields->push(
TextareaField::create(
'AllAppsForUser',
'VS apps for user',
$this->getAllAppsForUser()
// LeftMenu::get()
)->setReadOnly(true)
);
private function getAllAppsForUser()
{
$editedMemberId = $this->owner->ID;
$query = new SQLSelect();
$result = $query
->setFrom('LeftMenu')
->selectField('"LeftMenu"."AppName"', 'AppNames')
->selectField('"LeftMenu"."AppIND"', 'AppID')
->addInnerJoin('leftmenu_members', '"leftmenu_members"."LeftMenuID" = "LeftMenu"."ID"')
->addWhere(['leftmenu_members.MemberID' => $editedMemberId])
->execute();
$res = array();
$i = 0;
foreach ($result as $value) {
$res[$i] = $value['AppID'] . ' ' . $value['AppNames'];
$i++;
}
return implode('; ',$res);
}}