From 9fa7cbf70e8f60ea170bd45dac9585fd0a7d1ee5 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 19 Apr 2019 14:01:01 -0600 Subject: [PATCH] Hide backend controller behavior public methods from controller actions. Fixes #3762, replaces #3764 --- modules/backend/behaviors/FormController.php | 5 +++++ modules/backend/behaviors/ImportExportController.php | 5 +++++ modules/backend/behaviors/ListController.php | 5 +++++ modules/backend/behaviors/RelationController.php | 5 +++++ modules/backend/behaviors/ReorderController.php | 5 +++++ modules/backend/classes/ControllerBehavior.php | 10 ++++++++++ 6 files changed, 35 insertions(+) diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 230b57f1e..e4f38f800 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -79,6 +79,11 @@ class FormController extends ControllerBehavior */ protected $requiredConfig = ['modelClass', 'form']; + /** + * @var array Visible actions in context of the controller + */ + protected $actions = ['create', 'update', 'preview']; + /** * @var string The context to pass to the form widget. */ diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index 7b726e1ff..61ac7551d 100644 --- a/modules/backend/behaviors/ImportExportController.php +++ b/modules/backend/behaviors/ImportExportController.php @@ -45,6 +45,11 @@ class ImportExportController extends ControllerBehavior */ protected $requiredConfig = []; + /** + * @var array Visible actions in context of the controller + */ + protected $actions = ['import', 'export', 'download']; + /** * @var Model Import model */ diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index 3a45521c2..df01b63ea 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -68,6 +68,11 @@ class ListController extends ControllerBehavior */ protected $requiredConfig = ['modelClass', 'list']; + /** + * @var array Visible actions in context of the controller + */ + protected $actions = ['index']; + /** * Behavior constructor * @param \Backend\Classes\Controller $controller diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index b339dcc8a..97d9336bb 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -85,6 +85,11 @@ class RelationController extends ControllerBehavior */ protected $requiredConfig = []; + /** + * @var array Visible actions in context of the controller + */ + protected $actions = []; + /** * @var array Original configuration values */ diff --git a/modules/backend/behaviors/ReorderController.php b/modules/backend/behaviors/ReorderController.php index 28a602394..1795afca0 100644 --- a/modules/backend/behaviors/ReorderController.php +++ b/modules/backend/behaviors/ReorderController.php @@ -35,6 +35,11 @@ class ReorderController extends ControllerBehavior */ protected $requiredConfig = ['modelClass']; + /** + * @var array Visible actions in context of the controller + */ + protected $actions = ['reorder']; + /** * @var Model Import model */ diff --git a/modules/backend/classes/ControllerBehavior.php b/modules/backend/classes/ControllerBehavior.php index 95b711566..1df06bd48 100644 --- a/modules/backend/classes/ControllerBehavior.php +++ b/modules/backend/classes/ControllerBehavior.php @@ -37,6 +37,11 @@ class ControllerBehavior extends ExtensionBase */ protected $requiredProperties = []; + /** + * @var array Visible actions in context of the controller. Only takes effect if it is an array + */ + protected $actions; + /** * Constructor. */ @@ -58,6 +63,11 @@ class ControllerBehavior extends ExtensionBase ])); } } + + // Hide all methods that aren't explicitly listed as actions + if (is_array($this->actions)) { + $this->hideAction(array_diff(get_class_methods(get_class($this)), $this->actions)); + } } /**