Skip to content

Commit 1e3d868

Browse files
committed
disabled actions
1 parent e9666aa commit 1e3d868

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

AdminDefaultController.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ class AdminDefaultController extends BaseController
2323
public $modelSearchClass;
2424

2525
/**
26-
* If false then 'index', 'update', 'grid-sort', etc. will be disabled
26+
* Actions that will be disabled
2727
*
28-
* @var bool
28+
* List of available actions:
29+
*
30+
* ['index', 'view', 'create', 'update', 'delete', 'toggle-attribute',
31+
* 'bulk-activate', 'bulk-deactivate', 'bulk-delete', 'grid-sort', 'grid-page-size']
32+
*
33+
* @var array
2934
*/
30-
protected $enableBaseActions = true;
35+
public $disabledActions = [];
3136

3237
/**
33-
* Actions that will be disable on enableBaseActions = false;
38+
* Opposite to $disabledActions. Every action except those will be disabled
39+
*
40+
* But if action listed both in $disabledActions and $enableOnlyActions
41+
* then it will be disabled
3442
*
3543
* @var array
3644
*/
37-
protected $baseActions = ['index', 'update', 'create', 'view', 'delete', 'toggleAttribute', 'bulkActivate',
38-
'bulkDeactivate', 'bulkDelete', 'gridSort', 'gridPageSize'];
45+
public $enableOnlyActions = [];
3946

4047

4148
public function behaviors()
@@ -301,7 +308,12 @@ public function beforeAction($action)
301308
{
302309
if ( parent::beforeAction($action) )
303310
{
304-
if ( !$this->enableBaseActions AND in_array($action->id, $this->baseActions) )
311+
if ( $this->enableOnlyActions !== [] AND !in_array($action->id, $this->enableOnlyActions) )
312+
{
313+
throw new NotFoundHttpException('Page not found');
314+
}
315+
316+
if ( in_array($action->id, $this->disabledActions) )
305317
{
306318
throw new NotFoundHttpException('Page not found');
307319
}

0 commit comments

Comments
 (0)