Create user attribute on package install

Permalink 1 user found helpful
I'm trying to get my package to create a user attribute when it is created as it is required by the package in order to be fully integrated with the Concrete5 system.

I've tried adding it through SQL but i can't figure out how the concrete5 helper is used for user attributes.

Any ideas?

Thanks!

 
CrystalShardz replied on at Permalink Best Answer Reply
I managed to figure out how to add custom user attributes when installing a package. Use the function below (includes comments) and all will be good!
Place this function inside your package controller and inside your install() function (or update if you wish to have it there too) add:
$this->_addCustomUserAttributes();

private function _addCustomUserAttributes(){
      $data=array(
         'atID' => 1,               //set attribute type ID to 1 (Text type)
         'akCategoryID' => 2,         //Set attribute category ID to 2 (Users)
         'uakProfileEditRequired' => 1,   //Set attribute to be editable and required on users profile
         'uakProfileDisplay' => 1,      //Set to display in public profile
         'uakMemberListDisplay' => 1,   //Set to display in memberlist
         'uakRegisterEditRequired' => 1,   //Set to require on the registration form
         'akIsSearchableIndexed' => 1,   //Set to be searchable in the user keyword search
         'akIsSearchable' => 1,         //Set to be searchable in the Dashboard user search
         'akHandle' => 'realname',      //Set the handle of this attribute
         'akName' => 'Real Name',      //Set the label text when someone is asked to fill the field in
         'asID' => 0                  //Set the attribute set ID to 0 (no set)
      );
      $ak = UserAttributeKey::add(1, $data);