Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-74942

Allow modules to add custom action menu items

XMLWordPrintable

    • MDL-74942-master-extendable-action-menu
    • Hide

      On a vanilla master branch:

      1. Merge in the changes linked in the master diff URL (this will update course/lib.php)
      2. Install this test plugin https://github.com/ScottVerbeek/moodle-mod_extendedactionmenu
      3. Enable Edit mode
      4. Create a new course
      5. Add a new Extended Action Menu activity
      6. Give it a random name and content
      7. Save and return to course
      8. Click the the edit menu for the newly created module
      9. Verfiy that a new View All action is displayed on the second to last position in the list
      10. Click the View All action to view all instances of Extend Action Menu

       

      Show
      On a vanilla master branch: Merge in the changes linked in the master diff URL (this will update course/lib.php) Install this test plugin https://github.com/ScottVerbeek/moodle-mod_extendedactionmenu Enable Edit mode Create a new course Add a new Extended Action Menu activity Give it a random name and content Save and return to course Click the the edit menu for the newly created module Verfiy that a new View All action is displayed on the second to last position in the list Click the View All action to view all instances of Extend Action Menu  

      When editing a course from the course index, each activity includes an "Edit" dropdown menu:

      This menu is available to:

      • users with the moodle/course:manageactivities capability
      • who are viewing the course index
      • with Editing mode enabled

      This menu is static - that is its content cannot be changed programatically between activities.

      This issue proposes to allow individual activities to add to and extend the menu to add new actions, for example:

      In this screenshould you can see highlighted a new customized action menu link. In this case the activity module developer can add action menu link targeting all to the view all course modules page.

      To replicate:

      /**
       * Callback to add addition action menu item.
       *
       * @param int $cmid The course module id.
       * @return array Array of action_menu_link_secondary.
       */
      function modulename_extend_action_menu($cmid) {
          global $COURSE;    
          
          $actions = array();    
          
          $actions['custom1'] = new action_menu_link_secondary(
              new moodle_url('/mod/modulename/index.php', array('id' => $COURSE->id)),
              new pix_icon('a/view_list_active', '', 'moodle', array('class' => 'iconsmall')),
              get_string('viewall', 'mod_modulename'),
              array('class' => 'editing_delete', 'data-action' => 'hello')
          );   
          return $actions;
      }

      Expected is that you would get a extra action menu link in the "Edit" drop down. I've created a sample plugin here: https://github.com/ScottVerbeek/moodle-mod_extendedactionmenu You can install this plugin and create one in the modules to achieve the result as shown in attached screenshot.

      If the callback is not programmed properly it will throw a moodle coding exceptions;

      • If the callback doesn't return a array; or
      • elements of the array which the callback returned are not of type action_menu_link_secondary.

      For this to be as little disruptive of current user experience, I've find that the placement of custom actions at the bottom of the list, but before the delete action, is  best.

      Prototype Link: https://github.com/ScottVerbeek/moodle/commit/a046b7b592fb558face4846834ea5fa01c197c4a
      Also a mock module which implements the callback: https://github.com/ScottVerbeek/moodle-mod_extendedactionmenu/commit/c8954d6713ccd186223b7572b8fdf991a1458d15

        1. 2022-06-09_15-39.png
          56 kB
          Scott Verbeek
        2. course-edit-menu.png
          167 kB
          Andrew Lyons

            scottverbeek Scott Verbeek
            scottverbeek Scott Verbeek
            Safat Shahin Safat Shahin
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 minutes
                5m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.