From df9e5c47eaaa19b8d5e7569cf2d9c61e489e40ab Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Dec 2014 21:39:39 +0100 Subject: [PATCH] [ticket/416] Fix incorrect behavior discovered by tests B3P-416 --- acp/portal_module.php | 12 ++++++++++++ language/en/portal_acp.php | 1 + portal/modules/constraints_handler.php | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/acp/portal_module.php b/acp/portal_module.php index 20fcf52d..4189c2f7 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -443,6 +443,12 @@ class portal_module continue; } + // Do not add modules that shouldn't be added + if (!$this->modules_constraints->can_add_module($this->c_class, $add_column)) + { + trigger_error($this->user->lang('UNABLE_TO_ADD_MODULE') . adm_back_link($this->u_action), E_USER_WARNING); + } + // Do not install if module already exists in the // column and it can't be added more than once if (!$this->c_class->can_multi_include() && !$this->modules_constraints->can_move_module($this->portal_columns->number_to_string($add_column), $module_classname)) @@ -512,6 +518,12 @@ class portal_module // Find new modules foreach ($modules_list as $module_class => $module) { + // Module can't be added to this column + if (!$this->modules_constraints->can_add_module($module, $add_column)) + { + continue; + } + // Do not install if module already exists in the // column and it can't be added more than once if (!$module->can_multi_include() && !$this->modules_constraints->can_move_module($this->portal_columns->number_to_string($add_column), $module_class)) diff --git a/language/en/portal_acp.php b/language/en/portal_acp.php index 07e96f28..485ff84e 100644 --- a/language/en/portal_acp.php +++ b/language/en/portal_acp.php @@ -52,6 +52,7 @@ $lang = array_merge($lang, array( 'B3P_FILE_NOT_FOUND' => 'The requested file could not be found', 'UNABLE_TO_MOVE' => 'It is not possible to move the block to the selected column.', 'UNABLE_TO_MOVE_ROW' => 'It is not possible to move the block to the selected row.', + 'UNABLE_TO_ADD_MODULE' => 'It is not possible to add the module to the selected column.', 'DELETE_MODULE_CONFIRM' => 'Are you sure you wish to delete the module "%1$s"?', 'MODULE_RESET_SUCCESS' => 'Successfully reset the module settings.', 'MODULE_RESET_CONFIRM' => 'Are you sure you wish to reset the settings of the module "%1$s"?', diff --git a/portal/modules/constraints_handler.php b/portal/modules/constraints_handler.php index acf504f6..244cf9c7 100644 --- a/portal/modules/constraints_handler.php +++ b/portal/modules/constraints_handler.php @@ -139,6 +139,19 @@ class constraints_handler return $this->check_module_already_exists($target_column, $module_class); } + /** + * Check if module can be moved to desired column + * + * @param \board3\portal\modules\module_interface $module + * @param string $column Column string + * + * @return bool True if module can be moved, false if not + */ + public function can_add_module($module, $column) + { + return $module->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($column)); + } + /** * Check if module already exists in specified target column type *