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();
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();
sorry folks, I know I am resurrecting a rather old thread....
what is em()? in my setup step (XF2.2) I get an undefined on it. I cannot quite figure out how to create it.
I'm trying to add a custom user field as part of the setup. I can do it through data but that's not polite
It always depends on the context. A lot of XenForo objects have quick access methods or properties for the app and entity manager available. If not, you can always get it via \XF::em() when you require it, as the post before your first gave as example.