У меня есть некоторые индивидуальные действия в моих классах Admin. То, что я делаю, просто «настраивает» их внутри классов admin. Стандартная соната \ UserBundle \ Security \ EditableRolesBuilder называет общественную функцию класса Sonata BaseAdmin "getSecurityInformation":
foreach ($admin->getSecurityInformation() as $role => $permissions) {
$role = sprintf($baseRole, $role);
if ($isMaster) {
// if the user has the MASTER permission, allow to grant access the admin roles to other users
$roles[$role] = $role;
} elseif ($this->securityContext->isGranted($role)) {
// although the user has no MASTER permission, allow the currently logged in user to view the role
$rolesReadOnly[$role] = $role;
}
}
Вот где я смыться.Просто переписать эту функцию собственный класс администратора (я сделал это в моем BaseAdmin классе, который простирается от Сонаты \ AdminBundle \ Admin \ Admin)
/**
* List here the customized roles actions which are used within the Admin class you have extended. (e.g. the
* CustomerAdmin uses a special function to login as the customer. In this case set the array to array('LOGIN') and
* use at certain points like ->isGranted('LOGIN'). This is also available in templates like
* admin.isGranted('LOGIN', object)).
* The actions you are listing here, will be appended to the standard actions: EDIT, LIST, CREATE, VIEW, DELETE,
* EXPORT, OPERATOR, MASTER.
*
* @see http://sonata-project.org/bundles/admin/master/doc/index.html
*
* @var array
*/
protected $customizedRoles = array();
/**
* {@inheritdoc}
*/
public function getSecurityInformation()
{
$standardAdminRoles = parent::getSecurityInformation();
$customizedAdminRoles = $this->getCustomizedAdminRoles();
$allAdminRoles = array_merge($standardAdminRoles, $customizedAdminRoles);
ksort($allAdminRoles);
return $allAdminRoles;
}
/**
* Get the customized roles set at property of the Admin class 'customizedRoles' prepared to append to the standard
* roles.
*
* @return array
*/
private function getCustomizedAdminRoles()
{
$customizedRoles = array();
if (is_array($this->customizedRoles) && !empty($this->customizedRoles)) {
foreach ($this->customizedRoles as $customizedRole) {
$customizedRole = strtoupper($customizedRole);
$customizedRoles[$customizedRole] = $customizedRole;
}
}
return $customizedRoles;
}
И просто заполнить этот массив в классе администратора и перезапись:
/** @{inheritdoc} */
protected $customizedRoles = array('LOGIN');
Вот и все. Усилия и дизайн для меня довольно справедливы. :-)
Спасибо, я могу добавить под ROLE_SUPER_ADMIN и ROLE_ADMIN мои новые роли, это не изменяет никакого файла Sonata, поэтому очень чисто. Для новой версии моего программного обеспечения я постараюсь установить свои роли таким образом. –