I have a problem i've struggled with for a long time, and it's starting to really piss me off, so i hope you can help me.
The thing is i'm writing a custom script (not a module) that needs access to the drupal user object, and it's profile2 fields, so i found out i could use the bootstrapper for this purpose.
Loading fields from the users profile works just fine, but when i try to make changes programmatically (user_save function for example), it fails with the following error, which makes absolutely no sense to me:
Fatal error: Class 'Drupal\gmap\GmapDefaults' not found in (root directory)\sites\all\modules\gmap\gmap.module on line 32
A function that would return this error could be something like this:
function custom_add_role_to_user($user, $role_name) {
// For convenience, we'll allow user ids as well as full user objects.
// If the user doesn't already have the role, add the role to that user.
$key = array_search($role_name, $user->roles);
if ($key == FALSE) {
// Get the rid from the roles table.
$roles = user_roles(TRUE);
$rid = array_search($role_name, $roles);
if ($rid != FALSE) {
$new_role[$rid] = $role_name;
$all_roles = $user->roles + $new_role; // Add new role to existing roles.
user_save($user, array('roles' => $all_roles)); // <---- This function throws the above error...
}
}
}
If i don't call user_save(), everything works just fine, and until now i have been doing fine with direct sql queries, but i need to know why this doesn't work.
I've tried navigating to the GMap class to see what's actually going on at line 32 (Still not knowing why my simple script keeps referring to some random Google Map Module..?)
Here it is:
function gmap_defaults() {
include_once(drupal_get_path('module', 'gmap') . '/lib/Drupal/gmap/GmapDefaults.php');
return GmapDefaults::getInstance()->getDefaults();
}
So why is the bootstrapper calling this random module, and what is wrong with the module first of all???
It seems like it doesn't get to create the namespace required correctly. But i don't see where it goes wrong?
drupal_get_path returns the right path... I've tried to put a static path instead, to see if that made any difference... It didn't...
Thanks in advance for your help.