Back to InstallerScript class

Method addDashboardMenu

public void
addDashboardMenu
(string $dashboard, string $preset)
Creates the dashboard menu module
Parameters
  • string $dashboard The name of the dashboard
  • string $preset The name of the menu preset
Returns
  • void
Since
  • 4.0.0
-
  • \Exception

Method addDashboardMenu - Source code

/**
 * Creates the dashboard menu module
 *
 * @param string $dashboard The name of the dashboard
 * @param string $preset    The name of the menu preset
 *
 * @return  void
 *
 * @throws \Exception
 * @since   4.0.0
 */
public function addDashboardMenu(string $dashboard, string $preset)
{
    $model = Factory::getApplication()->bootComponent('com_modules')->getMVCFactory()->createModel('Module', 'Administrator', ['ignore_request' => true]);
    $module = array('id' => 0, 'asset_id' => 0, 'language' => '*', 'note' => '', 'published' => 1, 'assignment' => 0, 'client_id' => 1, 'showtitle' => 0, 'content' => '', 'module' => 'mod_submenu', 'position' => 'cpanel-' . $dashboard);
    // Try to get a translated module title, otherwise fall back to a fixed string.
    $titleKey = strtoupper('COM_' . $this->extension . '_DASHBOARD_' . $dashboard . '_TITLE');
    $title = Text::_($titleKey);
    $module['title'] = $title === $titleKey ? ucfirst($dashboard) . ' Dashboard' : $title;
    $module['access'] = (int) Factory::getApplication()->get('access', 1);
    $module['params'] = array('menutype' => '*', 'preset' => $preset, 'style' => 'System-none');
    if (!$model->save($module)) {
        Factory::getApplication()->enqueueMessage(Text::sprintf('JLIB_INSTALLER_ERROR_COMP_INSTALL_FAILED_TO_CREATE_DASHBOARD', $model->getError()));
    }
}