Joomla 3.7 Custom User Fields - How to access through PHP & JFactory::getUser

1,531 views
Skip to first unread message

James Newton

unread,
Apr 8, 2017, 4:48:08 AM4/8/17
to Joomla! General Development
I've created a new custom user field (Joomla! 3.7.0-rc1). Its a media field holding named "logo" allowing users to upload a logo image.
I'm attempting to use that image elsewhere in the template and thought that I would be able to use ...

<?php
$user = JFactory::getUser();
echo $user->logo;
?>

...to access the new custom user field (named logo). I haven't been able to find any documentation yet on how we'll be able to access these custom fields in templates or other extensions once we've created them in the backend. Any help would be greatly appreciated.

Viper

unread,
Apr 9, 2017, 3:45:28 PM4/9/17
to Joomla! General Development
See
model - JForm::addFieldPath()
xml form - addfieldpath
template - JFormHelper::loadFieldType()

Same for rule classes(just change Field to Rule).

Bakual

unread,
Apr 12, 2017, 11:24:40 AM4/12/17
to Joomla! General Development
Just loading the user will not get you the associated custom fields. Those are assigned during the "onContentPrepare" event. So you would need to trigger that event with the right context to be able to use those added fields.
The documentation is still a work in progress.Tobias is doing a good job with it.

Tigran Sargsyan

unread,
May 3, 2017, 12:10:49 PM5/3/17
to Joomla! General Development
суббота, 8 апреля 2017 г., 11:48:08 UTC+3 пользователь James Newton написал:
0
down vote
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
print_r( FieldsHelper::getFields('com_users.user', ['id'=> JFactory::getUser()->id]));

Allon Moritz

unread,
May 4, 2017, 1:14:04 AM5/4/17
to joomla-de...@googlegroups.com
Do something like:
JDispatcher::getInstance()->trigger('onContentPrepare', array ('com_users.user', &JFactory::getUser(), new JRegistry(), 0));
print_r(JFactory::getUser()->jcfields);



--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send an email to joomla-dev-general@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Tigran Sargsyan

unread,
May 4, 2017, 4:09:39 AM5/4/17
to Joomla! General Development

Warning: Parameter 3 to PlgContentLoadmodule::onContentPrepare() expected to be a reference, value given in /libraries/joomla/event/event.php on line 70

Warning: Parameter 3 to PlgContentFields::onContentPrepare() expected to be a reference, value given in /libraries/joomla/event/event.php on line 70

Warning: Parameter 3 to PlgContentEmailcloak::onContentPrepare() expected to be a reference, value given in /libraries/joomla/event/event.php on line 70

Warning: Parameter 3 to PlgContentPagebreak::onContentPrepare() expected to be a reference, value given in /libraries/joomla/event/event.php on line 70


четверг, 4 мая 2017 г., 8:14:04 UTC+3 пользователь laoneo написал:
Do something like:
JDispatcher::getInstance()->trigger('onContentPrepare', array ('com_users.user', &JFactory::getUser(), new JRegistry(), 0));
print_r(JFactory::getUser()->jcfields);

On Wed, May 3, 2017 at 4:55 PM, Tigran Sargsyan <tigran.sar...@gmail.com> wrote:
суббота, 8 апреля 2017 г., 11:48:08 UTC+3 пользователь James Newton написал:
> I've created a new custom user field (Joomla! 3.7.0-rc1). Its a media field holding named "logo" allowing users to upload a logo image.
> I'm attempting to use that image elsewhere in the template and thought that I would be able to use ...
>
> <?php
> $user = JFactory::getUser();
> echo $user->logo;
> ?>
>
> ...to access the new custom user field (named logo). I haven't been able to find any documentation yet on how we'll be able to access these custom fields in templates or other extensions once we've created them in the backend. Any help would be greatly appreciated.


0
down vote
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
print_r(  FieldsHelper::getFields('com_users.user', ['id'=> JFactory::getUser()->id]));

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.

Mhlonishwa Njabulo Mkhize

unread,
May 26, 2017, 1:00:23 PM5/26/17
to Joomla! General Development
Does anybody have a solid clear answer for this?

Allon Moritz

unread,
May 27, 2017, 3:57:25 PM5/27/17
to joomla-de...@googlegroups.com
Short answer is that you need to trigger the onContentPrepare event on the user object and then you can access the fields $user->jcfields.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-dev-general@googlegroups.com.

Mhlonishwa Njabulo Mkhize

unread,
May 29, 2017, 7:14:09 AM5/29/17
to Joomla! General Development
Hi laoneo
Would you please show me how to trigger that event and how then to access the field?
Reply all
Reply to author
Forward
0 new messages