Topic-icon Error - Joomla\Registry\Registry::loadArray(): Argument #1 ($array) must be of t

Hello.  I upgraded for J4 and reinstalled JFBC.  The Google Plugin is activated.  When I log in, I get this message:  Joomla\Registry\Registry::loadArray(): Argument #1 ($array) must be of type array, stdClass given, called in /home/whutnext/public_html/site/plugins/jfbconnect/provider_google/profile/google.php on line 70
Attachments:
Support Specialist
Could you try making a small change to your code?

In /home/whutnext/public_html/site/plugins/jfbconnect/provider_google/profile/google.php, around line 67, change
$data = json_decode($body);
                if (is_object($data))
                {
                    $profile->loadArray($data);

                    if (isset($data->given_name) && $data->given_name != '')
                        $profile->set('first_name', $data->given_name);
                    else
                    {
                        // No given name, need to return something so Joomla doesn't choke
                        // In this case, we're just using their email handle (before the @) as their name. Not ideal, but it lets them register
                        $profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
                        // If a name isn't set, then the 'name' field from Google is the email address.
                        // Can't use this as the full name or we'll have irate users.
                        $profile->set('full_name', $profile->get('first_name') . ' ' . $profile->get('last_name'));
                    }
                }
to
$data = json_decode($body, true);
                $profile->loadObject($data);

                if (isset($data->given_name) && $data->given_name != '')
                    $profile->set('first_name', $data->given_name);
                else
                {
                    // No given name, need to return something so Joomla doesn't choke
                    // In this case, we're just using their email handle (before the @) as their name. Not ideal, but it lets them register
                    $profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
                    // If a name isn't set, then the 'name' field from Google is the email address.
                    // Can't use this as the full name or we'll have irate users.
                    $profile->set('full_name', $profile->get('first_name') . ' ' . $profile->get('last_name'));
                }
I pasted the code and now site load with error. Here is the link. I'll leave it there for a bit, but the error is this:

syntax error, unexpected 'return' (T_RETURN), expecting function (T_FUNCTION) or const (T_CONST)
Support Specialist
That error sounds like the number of squiggly braces does not match { and } and was copy/pasted wrong.

Here's the entire function that should be there now. Just replace what's there with this.
public function fetchProfile($socialId, $fields)
    {
        if (!is_array($fields))
            $fields = array($fields);
        $profile = new JFBConnectProfileDataGoogle();
        if (!empty($fields))
        {
            if ($this->provider->client->isAuthenticated())
            {
                //Get OAuth2 fields first
                $url = 'https://www.googleapis.com/oauth2/v2/userinfo';
                $data = $this->provider->client->query($url);
                $body = JFBConnectUtilities::getResponseBody($data);
                $data = json_decode($body, true);
                $profile->loadObject($data);

                if (isset($data->given_name) && $data->given_name != '')
                    $profile->set('first_name', $data->given_name);
                else
                {
                    // No given name, need to return something so Joomla doesn't choke
                    // In this case, we're just using their email handle (before the @) as their name. Not ideal, but it lets them register
                    $profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
                    // If a name isn't set, then the 'name' field from Google is the email address.
                    // Can't use this as the full name or we'll have irate users.
                    $profile->set('full_name', $profile->get('first_name') . ' ' . $profile->get('last_name'));
                }

            }
        }
        return $profile;
    }
Site loaded, but new error on google login:
Call to undefined method Joomla\CMS\Router\SiteRouter::getMode()
Support Specialist
Can you turn on Debug System in your Global Config to see the callstack of where that error is coming from?
Call stack#FunctionLocation1()JROOT/components/com_jfbconnect/libraries/utilities.php:2132JFBConnectUtilities::getLinkWithItemId()JROOT/components/com_jfbconnect/libraries/utilities.php:1963JFBConnectUtilities::getLinkFromMenuItem()JROOT/components/com_jfbconnect/models/loginregister.php:1564JFBConnectModelLoginRegister->getLoginRedirect()JROOT/components/com_jfbconnect/controllers/login.php:1885JFBConnectControllerLogin->login()JROOT/components/com_jfbconnect/controllers/authenticate.php:956JFBConnectControllerAuthenticate->doLogin()JROOT/components/com_jfbconnect/controllers/authenticate.php:757JFBConnectControllerAuthenticate->callback()JROOT/libraries/src/MVC/Controller/BaseController.php:7308Joomla\CMS\MVC\Controller\BaseController->execute()JROOT/components/com_jfbconnect/jfbconnect.php:319require_once()JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:6910Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher\{closure}()JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:7111Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch()JROOT/libraries/src/Component/ComponentHelper.php:38912Joomla\CMS\Component\ComponentHelper::renderComponent()JROOT/libraries/src/Application/SiteApplication.php:20613Joomla\CMS\Application\SiteApplication->dispatch()JROOT/libraries/src/Application/SiteApplication.php:24514Joomla\CMS\Application\SiteApplication->doExecute()JROOT/libraries/src/Application/CMSApplication.php:27815Joomla\CMS\Application\CMSApplication->execute()JROOT/includes/app.php:6316require_once()JROOT/index.php:32
if you try to log in with google, you will see the error
Support Specialist
Thanks. That made it easy to reproduce on my test site.

Another code change (I'll be putting out a bug fix release this week with these changes).

In /components/com_jfbconnect/libraries/utilities.php around line 206, replace
static function getLinkWithItemId($link, $itemId)
    {
        $app = Factory::getApplication();
        $router = $app->getRouter();

        if ($link)
        {
            if ($router->getMode() == JROUTER_MODE_SEF)
                $url = 'index.php?Itemid=' . $itemId;
            else
                $url = $link . '&Itemid=' . $itemId;
        }
        else
            $url = '';

        return $url;
    }
with
    static function getLinkWithItemId($link, $itemId)
    {
        $app = Factory::getApplication();
        $router = $app->getRouter();

        if ($link)
        {
            $isSef = JVERSION < 4.0 ? $router->getMode() == JROUTER_MODE_SEF : $app->get('sef');
            if ($isSef)
                $url = 'index.php?Itemid=' . $itemId;
            else
                $url = $link . '&Itemid=' . $itemId;
        }
        else
            $url = '';

        return $url;
    }
Fixed! Thanks. Now see "Google Profile Successfully Connected"

Appreciate the quick support.

Brian
Social Stream
Hide. Seek. Play!

Countdown Hide & Seek Game

Countdown, the new hide & seek toy, is available now! Designed and developed by the founders of SourceCoast, it's the perfect toy to get your kids moving at all ages.

Learn More About the Hide and Seek Toy