Skip to content

Commit

Permalink
[plg_user_profile] Misc fixes (#20412)
Browse files Browse the repository at this point in the history
* Update profile.xml

* Update profile.xml

* Update profile.php

* Update tos.php
  • Loading branch information
SharkyKZ authored and Michael Babker committed May 23, 2018
1 parent 5e423b6 commit 39620fc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 23 deletions.
38 changes: 22 additions & 16 deletions plugins/user/profile/field/tos.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function getLabel()
JHtml::_('behavior.modal');

// Build the class for the label.
$class = !empty($this->description) ? 'hasTooltip' : '';
$class = !empty($this->description) ? 'hasPopover' : '';
$class = $class . ' required';
$class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;

Expand All @@ -69,16 +69,17 @@ protected function getLabel()
// If a description is specified, use it to build a tooltip.
if (!empty($this->description))
{
$label .= ' title="'
. htmlspecialchars(
trim($text, ':') . '<br />' . ($this->translateDescription ? JText::_($this->description) : $this->description),
ENT_COMPAT, 'UTF-8'
) . '"';
$label .= ' title="' . htmlspecialchars(trim($text, ':'), ENT_COMPAT, 'UTF-8') . '"';
$label .= ' data-content="' . htmlspecialchars(
$this->translateDescription ? JText::_($this->description) : $this->description,
ENT_COMPAT,
'UTF-8'
) . '"';
}

$tosarticle = $this->element['article'] > 0 ? (int) $this->element['article'] : 0;
$tosArticle = $this->element['article'] > 0 ? (int) $this->element['article'] : 0;

if ($tosarticle)
if ($tosArticle)
{
JLoader::register('ContentHelperRoute', JPATH_BASE . '/components/com_content/helpers/route.php');

Expand All @@ -90,27 +91,32 @@ protected function getLabel()
$query = $db->getQuery(true);
$query->select('id, alias, catid, language')
->from('#__content')
->where('id = ' . $tosarticle);
->where('id = ' . $tosArticle);
$db->setQuery($query);
$article = $db->loadObject();

if (JLanguageAssociations::isEnabled())
{
$tosassociated = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $tosarticle);
$tosAssociated = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $tosArticle);
}

$current_lang = JFactory::getLanguage()->getTag();
$currentLang = JFactory::getLanguage()->getTag();

if (isset($tosassociated) && $current_lang !== $article->language && array_key_exists($current_lang, $tosassociated))
if (isset($tosAssociated) && $currentLang !== $article->language && array_key_exists($currentLang, $tosAssociated))
{
$url = ContentHelperRoute::getArticleRoute($tosassociated[$current_lang]->id, $tosassociated[$current_lang]->catid);
$link = JHtml::_('link', JRoute::_($url . '&tmpl=component&lang=' . $tosassociated[$current_lang]->language), $text, $attribs);
$url = ContentHelperRoute::getArticleRoute(
$tosAssociated[$currentLang]->id,
$tosAssociated[$currentLang]->catid,
$tosAssociated[$currentLang]->language
);

$link = JHtml::_('link', JRoute::_($url . '&tmpl=component'), $text, $attribs);
}
else
{
$slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
$url = ContentHelperRoute::getArticleRoute($slug, $article->catid);
$link = JHtml::_('link', JRoute::_($url . '&tmpl=component&lang=' . $article->language), $text, $attribs);
$url = ContentHelperRoute::getArticleRoute($slug, $article->catid, $article->language);
$link = JHtml::_('link', JRoute::_($url . '&tmpl=component'), $text, $attribs);
}
}
else
Expand Down
14 changes: 7 additions & 7 deletions plugins/user/profile/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,19 @@ public function onContentPrepareForm(JForm $form, $data)
$form->setFieldAttribute('tos', 'description', 'PLG_USER_PROFILE_FIELD_TOS_DESC_SITE', 'profile');
}

$tosarticle = $this->params->get('register_tos_article');
$tosenabled = $this->params->get('register-require_tos', 0);
$tosArticle = $this->params->get('register_tos_article');
$tosEnabled = $this->params->get('register-require_tos', 0);

// We need to be in the registration form and field needs to be enabled
if ($name !== 'com_users.registration' || !$tosenabled)
if ($name !== 'com_users.registration' || !$tosEnabled)
{
// We only want the TOS in the registration form
$form->removeField('tos', 'profile');
}
else
{
// Push the TOS article ID into the TOS field.
$form->setFieldAttribute('tos', 'article', $tosarticle, 'profile');
$form->setFieldAttribute('tos', 'article', $tosArticle, 'profile');
}

foreach ($fields as $field)
Expand Down Expand Up @@ -381,11 +381,11 @@ public function onUserBeforeSave($user, $isnew, $data)
// Check that the tos is checked if required ie only in registration from frontend.
$task = JFactory::getApplication()->input->getCmd('task');
$option = JFactory::getApplication()->input->getCmd('option');
$tosarticle = $this->params->get('register_tos_article');
$tosenabled = ($this->params->get('register-require_tos', 0) == 2);
$tosArticle = $this->params->get('register_tos_article');
$tosEnabled = ($this->params->get('register-require_tos', 0) == 2);

// Check that the tos is checked.
if ($task === 'register' && $tosenabled && $tosarticle && $option === 'com_users' && !$data['profile']['tos'])
if ($task === 'register' && $tosEnabled && $tosArticle && $option === 'com_users' && !$data['profile']['tos'])
{
throw new InvalidArgumentException(JText::_('PLG_USER_PROFILE_FIELD_TOS_DESC_SITE'));
}
Expand Down
46 changes: 46 additions & 0 deletions plugins/user/profile/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL"
description="PLG_USER_PROFILE_FIELD_ADDRESS1_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -44,6 +46,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_ADDRESS2_LABEL"
description="PLG_USER_PROFILE_FIELD_ADDRESS2_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -55,6 +59,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_CITY_LABEL"
description="PLG_USER_PROFILE_FIELD_CITY_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -66,6 +72,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_REGION_LABEL"
description="PLG_USER_PROFILE_FIELD_REGION_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -77,6 +85,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_COUNTRY_LABEL"
description="PLG_USER_PROFILE_FIELD_COUNTRY_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -88,6 +98,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_POSTAL_CODE_LABEL"
description="PLG_USER_PROFILE_FIELD_POSTAL_CODE_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -99,6 +111,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_PHONE_LABEL"
description="PLG_USER_PROFILE_FIELD_PHONE_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -110,6 +124,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_WEB_SITE_LABEL"
description="PLG_USER_PROFILE_FIELD_WEB_SITE_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -121,6 +137,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_LABEL"
description="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -132,6 +150,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_ABOUT_ME_LABEL"
description="PLG_USER_PROFILE_FIELD_ABOUT_ME_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -144,6 +164,7 @@
label="PLG_USER_PROFILE_FIELD_TOS_LABEL"
description="PLG_USER_PROFILE_FIELD_TOS_DESC"
default="0"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="0">JDISABLED</option>
Expand All @@ -158,13 +179,16 @@
new="true"
edit="true"
clear="true"
filter="integer"
/>

<field
name="register-require_dob"
type="list"
label="PLG_USER_PROFILE_FIELD_DOB_LABEL"
description="PLG_USER_PROFILE_FIELD_DOB_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -189,6 +213,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL"
description="PLG_USER_PROFILE_FIELD_ADDRESS1_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -200,6 +226,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_ADDRESS2_LABEL"
description="PLG_USER_PROFILE_FIELD_ADDRESS2_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -211,6 +239,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_CITY_LABEL"
description="PLG_USER_PROFILE_FIELD_CITY_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -222,6 +252,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_REGION_LABEL"
description="PLG_USER_PROFILE_FIELD_REGION_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -233,6 +265,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_COUNTRY_LABEL"
description="PLG_USER_PROFILE_FIELD_COUNTRY_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -244,6 +278,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_POSTAL_CODE_LABEL"
description="PLG_USER_PROFILE_FIELD_POSTAL_CODE_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -255,6 +291,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_PHONE_LABEL"
description="PLG_USER_PROFILE_FIELD_PHONE_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -266,6 +304,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_WEB_SITE_LABEL"
description="PLG_USER_PROFILE_FIELD_WEB_SITE_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -277,6 +317,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_LABEL"
description="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -288,6 +330,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_ABOUT_ME_LABEL"
description="PLG_USER_PROFILE_FIELD_ABOUT_ME_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand All @@ -299,6 +343,8 @@
type="list"
label="PLG_USER_PROFILE_FIELD_DOB_LABEL"
description="PLG_USER_PROFILE_FIELD_DOB_DESC"
default="1"
filter="integer"
>
<option value="2">JOPTION_REQUIRED</option>
<option value="1">JOPTION_OPTIONAL</option>
Expand Down
1 change: 1 addition & 0 deletions plugins/user/profile/profiles/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
label="PLG_USER_PROFILE_FIELD_TOS_LABEL"
description="PLG_USER_PROFILE_FIELD_TOS_DESC"
default="0"
filter="integer"
>
<option value="1">PLG_USER_PROFILE_OPTION_AGREE</option>
<option value="0">JNO</option>
Expand Down

0 comments on commit 39620fc

Please sign in to comment.