Problem
I'm trying to load the current entity object, in this case a profile2, profile page.
I've been using Is there a way to load the current entity object?, to try and solve this. Where am I going wrong?
So Far
I have the following code running in a custom form inside a block. The block appears on the profile page.
function mymodule_form() {
$node = menu_get_object('profile2', 1);
dpm($node);
}
The path of my page is: localhost/drupal5/profile-main/154
I have two kinds of profile 2, machine names main
and school
, however the following doesn't work either.
$node = menu_get_object('main', 1);
arg(0)
,arg(1)
,arg(2)
andarg(3)
respectively in that same function? It might just be you're picking the wrong part of the URL for the ID (yourmenu_get_object()
code looks right)$testarg = arg(1); dpm($testarg);
Add it threw back 154, so the correct number is going in, but I'm still getting nothing in $node. I guess the entity type must be wrong, but I've been digging through the module and I'm sure it's profile2. drupalcontrib.org/api/drupal/…profile2_load()
instead? If that doesn't work then the ID (154) probably relates to the user, not the profile, so you could useprofile2_load_by_user()
along withuser_load()
profile2_load
does work. But you guessed it and the UID is not equal to PID (because profiles are not created automatically) so I've usedprofile2_load_by_user
witharg(1)
, to get the correct entity. No idea whymenu_get_object
didn't work, nevermind. Thanks very much!