I have tried additional ways of doing this but to no avail. this is part of a project to have all the css for all components used on the site merged into a single css passing the values via theme manager. I intend to use it to write about 10 universal themes. I am using gantry 5, joomla 5.2 and the most recent updates to community builder. I also have available to me joomla component builder which we tried first but it all began to become to combersum. can you tell me what I am doing wrong? (YES I am being assisted by AI in this endevore)
Issue: Unable to Retrieve User ID in Community Builder Custom Fields (Not a Valid Input Error)I am attempting to retrieve the
user ID within a
Community Builder (CB) custom field but keep receiving the error:
"Theme Selector: Not a valid input" or
"Return value must be of type bool, null returned."What I've Tried:Below are the code attempts and configurations I've tried so far:
Attempt 1: Fetching User ID with cbUser (Direct Method)
Code:
$user = cbUser::getMyInstance();
$userId = $user->id;
return $userId;
Issue: "Not a valid input" – Potentially due to non-boolean return.
Attempt 2: Using Fallback to Ensure Boolean Return
Code:
$user = cbUser::getMyInstance();
$userId = $user->id ?? 0;
return ($userId > 0);
Issue: Same error message persists.
Attempt 3: Using Joomla Core
Instead of CBUser
Code:
$user = JFactory::getUser();
$userId = $user->id;
return ($userId > 0);
Issue: Still receiving "Not a valid input."
Attempt 4: Fetching CB User Parameter Directly
Code:
$user = cbUser::getMyInstance();
$userId = $user->getParam('id', 0);
return ($userId > 0);
Issue: Still produces an error.
Attempt 5: Using CB Query Field (SQL Attempt)
Code:
SELECT user_id
FROM #__comprofiler
WHERE user_id = '[user_id]'
LIMIT 1;
Issue: Syntax error occurred with placeholder handling.
Attempt 6: Returning User ID as a String
Code:
$user = cbUser::getMyInstance();
return (string) $user->id;
Issue: Same "Not a valid input."
Attempt 7: Boolean Return with Conditional Check
Code:
$user = cbUser::getMyInstance();
$userId = $user->id;
if (!empty($userId)) {
return true;
}
return false;
Issue: Same error, still indicating CB expects a different handling.
Attempt 8: Using CB Code Field for CSS Application
Code:
$user = cbUser::getMyInstance();
$theme = $user->getParam('cb_user_template_selector', '');
$doc = JFactory::getDocument();
$doc->addScriptDeclaration("
document.body.classList.add('" . htmlspecialchars($theme) . "');
");
return true;
Issue: Error continued.
Attempt 9: Created a Separate Table for User ID and Theme
Code:
CREATE TABLE `taqlx_user_themes` (
`user_id` INT(11) NOT NULL,
`theme` VARCHAR(100) NOT NULL,
PRIMARY KEY (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `taqlx_comprofiler` (`user_id`)
ON DELETE CASCADE
);
Issue: Error persisted when trying to fetch from this table as well.
Attempt 10: Switched from CB Code Field to CB Text Field
- Changed from CB Code Field to CB Text Field to avoid boolean errors.
- Result: The field displayed but still returned
Code:
"Not a valid input"
error when trying to fetch the value.
Database Check:
- I confirmed the data in the database using the following SQL:
Code:
SELECT user_id, cb_user_template_selector
FROM taqlx_comprofiler
WHERE cb_user_template_selector IS NOT NULL;
- The values are stored correctly in the table
.
Key Findings:
- The error "Not a valid input" appears to be linked to how CB Code Fields expect a boolean return (
or
).
- Even when switching to CB Query Fields and Text Fields, the issue persisted.
- The values are confirmed to be present in the database with correct formatting.
What I Need Help With:
- Does Community Builder restrict returning user data outside of its fields?
- How can I correctly retrieve the user ID in a CB Code Field?
- Is there a recommended way to use CB's internal methods or query handling to achieve this?
- Should I consider a plugin extension for this functionality?
Any guidance would be greatly appreciated! Thank you.