Several warning and deprecated functions for PHP > 8.0

Created on 7 June 2023, almost 2 years ago

Problem/Motivation

Warning 1:

Warning: foreach() argument must be of type array|object, null given in Drupal\openid_connect\OpenIDConnectClaims->getScopes() (line 122 of /code/docroot/modules/contrib/openid_connect/src/OpenIDConnectClaims.php)
#0 /code/docroot/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'foreach() argum...', '/code/docroot/m...', 122)
#1 /code/docroot/modules/contrib/openid_connect/src/OpenIDConnectClaims.php(122): _drupal_error_handler(2, 'foreach() argum...', '/code/docroot/m...', 122)

Warning 2:

Warning: foreach() argument must be of type array|object, null given in Drupal\openid_connect\OpenIDConnect->saveUserinfo() (line 692 of /code/docroot/modules/contrib/openid_connect/src/OpenIDConnect.php)
#0 /code/docroot/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'foreach() argum...', '/code/docroot/m...', 692)
#1 /code/docroot/modules/contrib/openid_connect/src/OpenIDConnect.php(692): _drupal_error_handler(2, 'foreach() argum...', '/code/docroot/m...', 692)
#2 /code/docroot/modules/contrib/openid_connect/src/OpenIDConnect.php(352): Drupal\openid_connect\OpenIDConnect->saveUserinfo(Object(Drupal\user\Entity\User), Array)

Warning 3:

Message Warning: Trying to access array offset on value of type null in Drupal\openid_connect\Form\OpenIDConnectSettingsForm->buildForm() (line 202 of /code/docroot/modules/contrib/openid_connect/src/Form/OpenIDConnectSettingsForm.php)
#0 /code/docroot/core/includes/bootstrap.inc(158): _drupal_error_handler_real(2, 'Trying to acces...', '/code/docroot/m...', 202)
#1 /code/docroot/modules/contrib/openid_connect/src/Form/OpenIDConnectSettingsForm.php(202): _drupal_error_handler(2, 'Trying to acces...', '/code/docroot/m...', 202)

Warning 4:

Steps to reproduce

No special case, just using the module.

Proposed resolution

Warning 1:

public function getScopes(OpenIDConnectClientInterface $client = NULL): string {
// If a client was provided, get the scopes from it.
$scopes = !empty($client) ? $client->getClientScopes() : $this->defaultScopes;

$claims_info = $this->getClaims();
$claims = $this->configFactory->getEditable('openid_connect.settings')->get('userinfo_mappings');
if (is_array($claims)) {
foreach ($claims as $claim) {
if (isset($claims_info[$claim]) && !in_array($claims_info[$claim]['scope'], $scopes)) {
$scopes[] = $claims_info[$claim]['scope'];
}
}
}
return implode(' ', $scopes);
}

Warning 2:

// Map groups to Drupal roles.
if (isset($userinfo['groups'])) {
$role_mappings = $this->configFactory->get('openid_connect.settings')->get('role_mappings');

if (is_array($role_mappings) || is_object($role_mappings)) {
foreach ($role_mappings as $role => $mappings) {
if (!empty(array_intersect($mappings, $userinfo['groups']))) {
// User has a mapped role. Add it to their account.
$account->addRole($role);
}
else {
// User doesn't have a mapped role. Remove it from their account.
$account->removeRole($role);
}
}
}
}

Warning 3:

$form['userinfo_mappings'][$property_name] = [
'#type' => 'select',
'#title' => $property->getLabel(),
'#description' => $property->getDescription(),
'#options' => (array) $claims,
'#empty_value' => '',
'#empty_option' => $this->t('- No mapping -'),
'#default_value' => isset($mappings[$property_name]) ? $mappings[$property_name] : '', //fix, If it doesn't exist, it assigns an empty string as a default value.
];
}

Warning 4:

$redirect = Url::fromUri('internal:/' . ltrim($destination ?? '', '/'), ['language' => $language])->toString();

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇪🇸Spain eduardo.arana

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024