ORIENT/modules/backend/formwidgets/PermissionEditor.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2016-02-20 06:12:41 +00:00
<?php namespace Backend\FormWidgets;
use Backend\Classes\FormWidgetBase;
use BackendAuth;
/**
* User/group permission editor
* This widget is used by the system internally on the System / Administrators pages.
*
* @package october\backend
* @author Alexey Bobkov, Samuel Georges
*/
class PermissionEditor extends FormWidgetBase
{
2016-02-23 05:52:23 +00:00
public $mode;
2016-02-20 06:12:41 +00:00
/**
* {@inheritDoc}
*/
public function init()
{
2016-02-23 05:52:23 +00:00
$this->fillFromConfig([
'mode'
]);
2016-02-20 06:12:41 +00:00
}
/**
* {@inheritDoc}
*/
public function render()
{
$this->prepareVars();
return $this->makePartial('permissioneditor');
}
/**
* Prepares the list data
*/
public function prepareVars()
{
2016-02-23 05:52:23 +00:00
$permissionsData = $this->formField->getValueFromData($this->model);
if (!is_array($permissionsData)) {
$permissionsData = [];
}
$this->vars['checkboxMode'] = $this->getControlMode() === 'checkbox';
$this->vars['permissions'] = BackendAuth::listTabbedPermissions();
$this->vars['baseFieldName'] = $this->getFieldName();
2016-02-23 05:52:23 +00:00
$this->vars['permissionsData'] = $permissionsData;
$this->vars['field'] = $this->formField;
}
/**
* {@inheritDoc}
*/
public function getSaveValue($value)
{
if (is_array($value)) {
return $value;
}
return [];
2016-02-20 06:12:41 +00:00
}
/**
* {@inheritDoc}
*/
protected function loadAssets()
{
$this->addCss('css/permissioneditor.css', 'core');
2016-02-24 05:44:05 +00:00
$this->addJs('js/permissioneditor.js', 'core');
2016-02-20 06:12:41 +00:00
}
2016-02-23 05:52:23 +00:00
protected function getControlMode()
{
return strlen($this->mode) ? $this->mode : 'radio';
}
}