From 9ac099a1c14e149e90225e095186aecf53776e13 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 30 Oct 2013 16:29:56 +0800 Subject: [PATCH] MDL-40975 ActionMenu: Add support for fillers in primary menus This is required to maintain horizontal alignment of primary menus in rows. --- course/lib.php | 50 +++++++++++---------- lib/outputcomponents.php | 25 ++++++++++- lib/outputrenderers.php | 10 +++++ theme/base/style/course.css | 8 ++++ theme/bootstrapbase/less/moodle/course.less | 7 +++ 5 files changed, 76 insertions(+), 24 deletions(-) diff --git a/course/lib.php b/course/lib.php index d8635cc3f16..85c8c588aee 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2044,30 +2044,34 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) { } // Groupmode. - if ($hasmanageactivities && !$mod->coursegroupmodeforce && plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { - if ($mod->effectivegroupmode == SEPARATEGROUPS) { - $nextgroupmode = VISIBLEGROUPS; - $grouptitle = $str->groupsseparate; - $actionname = 'groupsseparate'; - $groupimage = 't/groups'; - } else if ($mod->effectivegroupmode == VISIBLEGROUPS) { - $nextgroupmode = NOGROUPS; - $grouptitle = $str->groupsvisible; - $actionname = 'groupsvisible'; - $groupimage = 't/groupv'; - } else { - $nextgroupmode = SEPARATEGROUPS; - $grouptitle = $str->groupsnone; - $actionname = 'groupsnone'; - $groupimage = 't/groupn'; - } + if ($hasmanageactivities && !$mod->coursegroupmodeforce) { + if (plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { + if ($mod->effectivegroupmode == SEPARATEGROUPS) { + $nextgroupmode = VISIBLEGROUPS; + $grouptitle = $str->groupsseparate; + $actionname = 'groupsseparate'; + $groupimage = 't/groups'; + } else if ($mod->effectivegroupmode == VISIBLEGROUPS) { + $nextgroupmode = NOGROUPS; + $grouptitle = $str->groupsvisible; + $actionname = 'groupsvisible'; + $groupimage = 't/groupv'; + } else { + $nextgroupmode = SEPARATEGROUPS; + $grouptitle = $str->groupsnone; + $actionname = 'groupsnone'; + $groupimage = 't/groupn'; + } - $actions[$actionname] = new action_menu_link_primary( - new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $nextgroupmode)), - new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => '')), - $grouptitle, - array('class' => 'editing_'. $actionname, 'data-action' => $actionname, 'data-nextgroupmode' => $nextgroupmode) - ); + $actions[$actionname] = new action_menu_link_primary( + new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $nextgroupmode)), + new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => '')), + $grouptitle, + array('class' => 'editing_'. $actionname, 'data-action' => $actionname, 'data-nextgroupmode' => $nextgroupmode) + ); + } else { + $actions['nogroupsupport'] = new action_menu_filler(); + } } // Assign. diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 9dbf761861a..0a659a3f46a 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -3182,7 +3182,7 @@ class action_menu implements renderable { * @param action_menu_link|pix_icon|string $action */ public function add($action) { - if ($action instanceof action_menu_link) { + if ($action instanceof action_link) { if ($action->primary) { $this->add_primary_action($action); } else { @@ -3371,6 +3371,29 @@ class action_menu implements renderable { } } +/** + * An action menu filler + * + * @package core + * @category output + * @copyright 2013 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class action_menu_filler extends action_link implements renderable { + + /** + * True if this is a primary action. False if not. + * @var bool + */ + public $primary = true; + + /** + * Constructs the object. + */ + public function __construct() { + } +} + /** * An action menu action * diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 72f911544ec..39a6e05fd23 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1161,6 +1161,16 @@ class core_renderer extends renderer_base { return html_writer::tag('a', $icon.$text, $attributes); } + /** + * Renders a primary action_menu_filler item. + * + * @param action_menu_link_filler $action + * @return string HTML fragment + */ + protected function render_action_menu_filler(action_menu_filler $action) { + return html_writer::span(' ', 'filler'); + } + /** * Renders a primary action_menu_link item. * diff --git a/theme/base/style/course.css b/theme/base/style/course.css index 7c52bd40ebd..32c66257dea 100644 --- a/theme/base/style/course.css +++ b/theme/base/style/course.css @@ -32,6 +32,14 @@ .course-content .section .activity .activityinstance form { display: inline;} .sitetopic .section .activity .activityinstance, .course-content .section .activity .activityinstance { padding-right: 1em; } +.course-content .section .activity .filler { + width: 16px; + height: 16px; + margin: 4px; + display: inline-block; + vertical-align: text-bottom; +} + .dir-rtl .sitetopic .section .activity .activityinstance, .dir-rtl .course-content .section .activity .activityinstance { padding-right: 0; padding-left: 3em;} .sitetopic .section .activity .commands, diff --git a/theme/bootstrapbase/less/moodle/course.less b/theme/bootstrapbase/less/moodle/course.less index ddcb950b680..5c3b9672526 100644 --- a/theme/bootstrapbase/less/moodle/course.less +++ b/theme/bootstrapbase/less/moodle/course.less @@ -51,6 +51,13 @@ } } + .filler { + width: 16px; + height: 16px; + padding: 0.3em; + display: inline-block; + } + .activity.editor_displayed { a.editing_title, .moodle-actionmenu {