- Issue created by @gianfrasoft
- 🇮🇹Italy gianfrasoft
I found the problem.
When creating User I didn't set any role so profiles associated to the user were not accessable.
Always receive access denied when trying to access to profile view, edit or delete pages. Even if I'm the profile owner or the site administrator. Permissions are correct.
I programmaticly create a user and his profile:
User::create();
$user->setUsername($username);
$user->setEmail($email);
$user->set('name', $name);
$user->save();
$profile = Profile::create([
'type' => 'type_name',
'uid' => $user->id(),
// Aggiungi i campi del profilo qui.
'field_other' => $other,
]);
$profile->save();
In file: \src\ProfileAccessControlHandler.php
this code:
if ($result->isAllowed()) {
/** @var \Drupal\profile\Entity\ProfileInterface $entity */
$owner = $entity->getOwner();
if ($owner) {
$result = $result->andIf($this->checkRoleAccess($owner, $entity->bundle()));
}
}
prevent my admin user to access the profile. If I remove it, everything seems to work perfectly.
Any help?
Active
1.0
Code
I found the problem.
When creating User I didn't set any role so profiles associated to the user were not accessable.