Jump to content

Role is NullPage although present


owzim
 Share

Recommended Posts

I successfully created a role with the API:

$role = new Role();
$role->name = 'some-role';
$role->save();

It's now there under access/roles/
 
But when I want to get the role via API, I get a NullPage:

$roles->get('some-role');
// or
$this->roles->get('some-role');

Please help!

Link to comment
Share on other sites

I was trying to prevent a new creation of the role via:

if(!$role = $this->roles->get('some-role')) {
	$role = new Role();
	$role->name = 'some-role';
	$role->save();
}

But $this->roles->get returns a NullPage instead of null. $this->fieldgroups->get, $this->templates->get and $this->fields->get return null when not present.

So in this case:

$role = $this->roles->get('some-role');
if(!$role || $role instanceof NullPage) {
	$role = new Role();
	$role->name = 'some-role';
	$role->save();
}

fixed it.

I think all collection like classes should either return null or NullPage and not mixed results, right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...