Custom field in MyMember extension -> updateCMSFields -> Text field current edited member and html disabled

Silverstripe Version: 4*

Question:
Sorry for the “wild” topic title. :slight_smile:
I’m adding a custom “info” field to member edit view. I want to populate it with a custom query.
I need to get the ID of the member I am currently viewing (not my ID).

silverstripe/admin/security/EditForm/field/Members/item/7/edit

Additionally I want to make this field “disabled”.

class MyMemberExtension extends DataExtension
{
    public function updateCMSFields(FieldList $fields)
    {
       // Can I make this field disabled? It won't save but just so there is no confusion
       $fields->push(new TextField('AllAppsForUser','List of users apps',$this->getAllAppsForUser()));
    }

    private function getAllAppsForUser() {
        // I need the ID of the member I am viewing for a query. I From url example that would be 7
        return $list;
    }
}

$this->owner returns the instance an extension is bound to, so I suppose $this->owner->ID is what you are looking for.

1 Like

Hi @ntd
This is exactly what I am looking for. Thnx.
Do you know if there is a way to make the field “not editable”?
BR

Give this a try:

$fields->push(
  TextField::create(
    'AllAppsForUser',
    'List of users apps',
    $this->getAllAppsForUser()
  )->setReadOnly(true)
);
1 Like

@Tim
Thank you, this is what I needed.