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

Cannot add classes to pix_icon in boost properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Critical Critical
    • None
    • 3.2 regressions, 3.2.1
    • Themes
    • MOODLE_32_STABLE
    • 3.3 sprint 1

      This is a fun one.

      The renderer for theme_boost includes a function for render_pix_icon which calls export_for_template, and then modifies the content.
      This is a big no-no as it leads to inconsistent render information.

      You can see this already in the action menu as it is not possible to add an additional class to an icon in the action menu.

      For example:

      2086 sm:master> git d
      diff --git a/theme/boost/classes/output/core_renderer.php b/theme/boost/classes/output/core_renderer.php
      index 0f4993a..86d914d 100644
      --- a/theme/boost/classes/output/core_renderer.php
      +++ b/theme/boost/classes/output/core_renderer.php
      @@ -747,7 +747,7 @@ class core_renderer extends \core_renderer {
                           $link = new action_link(new moodle_url('#'), $menuitem->text, null, ['disabled' => true], $menuitem->icon);
                       }
                       if ($indent) {
      -                    $link->add_class('m-l-1');
      +                    $link->icon->attributes .= ' m-l-1';
                       }
                       if (!empty($menuitem->classes)) {
                           $link->add_class(implode(" ", $menuitem->classes));
      

      This should allow us to add the m-l-1 class to the icon instead of the link in an indented action menu, however it is silently dropped.

      This is because render_pix_icon calls $icon->export_for_template() and then modifies the content - https://github.com/moodle/moodle/blob/master/theme/boost/classes/output/core_renderer.php#L487.

      This modification only happens for an icon output directly. It does not get called when a template is included from another template. In that case the parent template should already include the context data for the icon.

      Basically, we need to remove that modification, and ideally we need to prevent such modifications from happening in themes at all.

            Unassigned Unassigned
            dobedobedoh Andrew Lyons
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

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