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

get_module_types_names() returns lang_string object instead of lang string

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.9.12, 3.10.9, 3.11.5, 4.0
    • 3.11.6
    • Language

    Description

      The method docs say it returns an array where key is the module name and the value is the human-readable string, but in fact it returns lang_string object (because lazyload is set to true) https://github.com/moodle/moodle/blob/master/course/lib.php#L566-L567

      It works perfectly across Moodle as lang_string has a magic method __toString() https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L10658-L10665

      However, it doesn't work when lang_string is encoded into a json string:

      $name = $cminfo->get_module_type_name();
      echo('Mod name: ' . $name);
      echo('Mod name json: ' . json_encode($name));
      

      has the following output:

      Mod name: Assignment
      Mod name json: {}
      

      Attachments

        Activity

          People

            mikhailgolenkov Misha Golenkov
            mikhailgolenkov Misha Golenkov
            David Mudrák (@mudrd8mz) David Mudrák (@mudrd8mz)
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            CiBoT CiBoT
            David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              14/Mar/22

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 days, 2 hours, 45 minutes
                3d 2h 45m