I have proposed a change MDL-31833 (see issue for details and patch). The summary is that it adds functions to html_writer for div and span, so that you can do:
html_writer::span($str, 'accesshide');
where you currently have to do
html_writer::tag('span', $str, array('class' => 'accesshide');
I.e. it calls the same underlying functions but is just a shortcut so the code can be shorter and easier to read. There are over a thousand uses of html_writer::tag for div and span in the code (and also lots more uses of plain strings with <div> in that really ought to be using html_writer).
Some arguments against this, and my responses:
- It will add to the complexity of the code
I disagree, I think it simplifies code by reducing clutter and making it easier to read in some common cases. - A renderer method such as container should be used
I think div and span are low-level primitives that it should be OK to use directly when implementing renderer methods, rather than calling another renderer method.
Putting a div around something is too generic an activity to benefit significantly from being able to override it in themes, it's not like 'create a formatted box for display of notifications to users' (which should be a renderer method), it's just 'this is a div, could be anything'.
Comments welcome.
--sam