I just want to confirm that what is the correct syntax $this->setState('role', $role) or $this->setState('roles', $role). I think roles and role are different, In some line you used roles and in some you used role.

Second where i have to use the code below, mean to which file i have to do this