Created
April 6, 2023 16:26
-
-
Save rvalitov/497a72cb239106123e3afa6be7e21432 to your computer and use it in GitHub Desktop.
Community Builder Conditional: how to show a field only if a user looks his own profile in Joomla?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param FieldTable|TabTable $object | |
* @param string $reason | |
* @param int $userId | |
* @param null|bool $js | |
* @param null|bool $reset | |
* @return bool|int | |
*/ | |
private static function parseConditions( $object, $reason, $userId, &$js = null ) | |
//Function code goes here.... | |
//Leave all the code and find a part starting with this line: | |
case 'customusers': | |
if ( $andCondition->getString( 'user_users', 'displayed' ) === 'viewer' ) { | |
$fieldValue = Application::MyUser()->getUserId(); | |
} else { | |
$fieldValue = (int) $userId; | |
} | |
$operator = $andCondition->getInt( 'operator_users', 12 ); | |
$delimiter = $andCondition->getString( 'delimiter_users' ); | |
if ( ! $delimiter ) { | |
$delimiter = ','; | |
} | |
//You will see a line, that you need to comment out: | |
//$value = $cbUser->replaceUserVars( $andCondition->getString( 'field_users' ), true, false, array(), false ); | |
//Below is the new 4 lines of code that we need to add: | |
$field_users = $andCondition->getString( 'field_users' ); | |
if ($field_users === 'viewing_user') | |
$field_users = Application::MyUser()->getUserId(); | |
$value = $cbUser->replaceUserVars( $field_users, true, false, array(), false ); | |
//End of new added lines, the original code continues below. | |
break; |
Thank you so much! That's a perfect solution!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not necessary. Just use [cb:userdata field="user_id" user="#me" /] to substitute in the viewing users id. That parameter supports substitutions.