XF 2.0 Add custom user profile field on addon install

Jeremy P

Well-known member
Looks to be fairly similar, but using an entity instead of data-writer. I think something like this should work:

PHP:
$field = $this->em()->create('XF:UserField');
$field->field_id = 'fieldId';
// set other fields

$title = $field->getMasterPhrase(true);
$title->phrase_text = 'Title';
$field->addCascadedSave($title);

$description = $field->getMasterPhrase(false);
$description->phrase_text = 'Description';
$field->addCascadedSave($description);

$field->save();
 

Kevin

Well-known member
Looks to be fairly similar, but using an entity instead of data-writer. I think something like this should work:

PHP:
$field = $this->em()->create('XF:UserField');
$field->field_id = 'fieldId';
// set other fields

$title = $field->getMasterPhrase(true);
$title->phrase_text = 'Title';
$field->addCascadedSave($title);

$description = $field->getMasterPhrase(false);
$description->phrase_text = 'Description';
$field->addCascadedSave($description);

$field->save();
Thoughts on code to check if the field already exists?
 
Top