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

Form elements editor does not support freezing

    • MOODLE_21_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • MDL-29421-master
    • Hide
      1. Login as an administrator
      2. Create a test course
      3. Create a test quiz inside the test course
      4. Add 1 MCQ question
        • Populate the question text and upload an image
        • Populate the choice answer 1 and upload an image
        • Populate the choice answer 2 and upload an image
        • Populate the choice answer 3 and upload a text file
        • Save changes
      5. Go to Site administration > Define roles > Non-editing teacher
      6. Allow question:viewall for Non-editing teacher
      7. Create a test user
      8. Enrol the test user into your test course as a non-editing teacher
      9. Login as the test user
      10. Go to the test course and click on question bank
      11. Find the MCQ question
      12. Click on Actions drop down menu and select View. There will be an error: Exception - MoodleQuickForm_editor::get_text(): Return value must be of type string, null returned (This error has been raised in MDL-79026)
        • As a workaround, modify line 257 of the lib/form/editor.php from:
          return $this->_values['text'];
          to:
          return $this->_values['text'] ?? '';
      13. Refresh the page and verify that the error is gone and the images are not displaying
      14. Click on the text file link and verify that it will show a broken file url (e.g., http://localhost:8000/brokenfile.php#/17/user/draft/811506973/helloworld.txt)
      15. Undo your code changes in lib/form/editor.php
      16. Apply the MDL-29421-master-latest.patch
      17. Refresh the page and verify that the images are appearing and the text file can be viewed
      Show
      Login as an administrator Create a test course Create a test quiz inside the test course Add 1 MCQ question Populate the question text and upload an image Populate the choice answer 1 and upload an image Populate the choice answer 2 and upload an image Populate the choice answer 3 and upload a text file Save changes Go to Site administration > Define roles > Non-editing teacher Allow question:viewall for Non-editing teacher Create a test user Enrol the test user into your test course as a non-editing teacher Login as the test user Go to the test course and click on question bank Find the MCQ question Click on Actions drop down menu and select View. There will be an error: Exception - MoodleQuickForm_editor::get_text(): Return value must be of type string, null returned (This error has been raised in MDL-79026 ) As a workaround, modify line 257 of the lib/form/editor.php from: return $this->_values ['text'] ; to: return $this->_values ['text'] ?? ''; Refresh the page and verify that the error is gone and the images are not displaying Click on the text file link and verify that it will show a broken file url (e.g., http://localhost:8000/brokenfile.php#/17/user/draft/811506973/helloworld.txt) Undo your code changes in lib/form/editor.php Apply the MDL-29421 -master-latest.patch Refresh the page and verify that the images are appearing and the text file can be viewed

      HTML_QuickForm_element has a nice feature called freezing. One can call $element->freeze() and element will be displayed as a static label+value pair plus a hidden field with a value.
      There is also an attribute _persistantFreeze (see method setPersistantFreeze), true by default. If set to false, no hidden field is generated.

      This feature is forgotten in the elements of type 'editor' and 'filepicker' (lib/form/editor.php and lib/form/filepicker.php)

      method toHtml() in both classes call getFrozenHtml() if element is frozen, but the classes do not redeclare the function getFrozenHtml()

      in case of filepicker, the draftitemid is displayed (could be list of files)
      in case of editor, warning is thrown because parent function assumes value to be a scalar. Also editor needs to redeclare hidden field generation in _getPersistantData() (or not use this function)

      the select field (lib/pear/HTML/QuickForm/select.php) can be used as an example of an element with an array stored in _value.

        1. MDL-29421-editor.patch
          0.8 kB
        2. MDL-29421-editor.patch
          0.7 kB
        3. test_editor_form.php
          1.0 kB
        4. image-2019-09-03-00-58-10-071.png
          image-2019-09-03-00-58-10-071.png
          9 kB
        5. MDL-29421-master-latest.patch
          12 kB
        6. Testing patch.webm
          6.30 MB

            trishamilan Trisha Milan
            marina Marina Glancy
            Andrew Lyons Andrew Lyons
            Votes:
            9 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 34 minutes
                3h 34m

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