/** * Renders HTML for displaying the sequence of course module editing buttons * * @see course_get_cm_edit_actions() * * @param action_link[] $actions Array of action_link objects * @param cm_info $mod The module we are displaying actions for. * @param array $displayoptions additional display options: * ownerselector => A JS/CSS selector that can be used to find an cm node. * If specified the owning node will be given the class 'action-menu-shown' when the action * menu is being displayed. * constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain * the action menu to when it is being displayed. * donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS. * @return string */ public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) { global $CFG; if (empty($actions)) { return ''; } if (isset($displayoptions['ownerselector'])) { $ownerselector = $displayoptions['ownerselector']; } else { if ($mod) { $ownerselector = '#module-' . $mod->id; } else { debugging('You should upgrade your call to ' . __FUNCTION__ . ' and provide $mod', DEBUG_DEVELOPER); $ownerselector = 'li.activity'; } } if (isset($displayoptions['constraintselector'])) { $constraint = $displayoptions['constraintselector']; } else { $constraint = '.course-content'; } $menu = new action_menu(); $menu->set_owner_selector($ownerselector); $menu->set_constraint($constraint); $menu->set_alignment(action_menu::TR, action_menu::BR); $menu->set_menu_trigger(get_string('edit')); if (isset($CFG->modeditingmenu) && !$CFG->modeditingmenu || !empty($displayoptions['donotenhance'])) { $menu->do_not_enhance(); // Swap the left/right icons. // Normally we have have right, then left but this does not // make sense when modactionmenu is disabled. $moveright = null; $_actions = array(); foreach ($actions as $key => $value) { if ($key === 'moveright') { // Save moveright for later. $moveright = $value; } else { if ($moveright) { // This assumes that the order was moveright, moveleft. // If we have a moveright, then we should place it immediately after the current value. $_actions[$key] = $value; $_actions['moveright'] = $moveright; // Clear the value to prevent it being used multiple times. $moveright = null; } else { $_actions[$key] = $value; } } } $actions = $_actions; unset($_actions); } foreach ($actions as $action) { if ($action instanceof action_menu_link) { $action->add_class('cm-edit-action'); } $menu->add($action); } $menu->attributes['class'] .= ' section-cm-edit-actions commands'; // Prioritise the menu ahead of all other actions. $menu->prioritise = true; return $this->render($menu); }
/** * Output the row of editing icons for a block, as defined by the controls array. * * @param array $controls an array like {@link block_contents::$controls}. * @param string $blockid The ID given to the block. * @return string HTML fragment. */ public function block_controls($actions, $blockid = null) { global $CFG; if (empty($actions)) { return ''; } $menu = new action_menu($actions); if ($blockid !== null) { $menu->set_owner_selector('#'.$blockid); } $menu->set_constraint('.block-region'); $menu->attributes['class'] .= ' block-control-actions commands'; if (isset($CFG->blockeditingmenu) && !$CFG->blockeditingmenu) { $menu->do_not_enhance(); } return $this->render($menu); }
/** * Adds editing actions to the question name in the edit mode * @param stdClass $item * @param HTML_QuickForm_element $element */ protected function enhance_name_for_edit($item, $element) { global $OUTPUT; $menu = new action_menu(); $menu->set_owner_selector('#' . $this->guess_element_id($item, $element)); $menu->set_constraint('.feedback_form'); $menu->set_alignment(action_menu::TR, action_menu::BR); $menu->set_menu_trigger(get_string('edit')); $menu->do_not_enhance(); $menu->prioritise = true; $itemobj = feedback_get_item_class($item->typ); $actions = $itemobj->edit_actions($item, $this->get_feedback(), $this->get_cm()); foreach ($actions as $action) { $menu->add($action); } $editmenu = $OUTPUT->render($menu); $name = $element->getLabel(); $name = html_writer::span('', 'itemdd', array('id' => 'feedback_item_box_' . $item->id)) . html_writer::span($name, 'itemname') . html_writer::span($editmenu, 'itemactions'); $element->setLabel(html_writer::span($name, 'itemtitle')); }