Problem/Motivation
Currently there is no way to know when HTML attributes arrays (i.e. attributes, title_attributes, content_attributes, etc.) should be cast to Attribute objects. template_preprocess(), for example, creates three Attribute objects, but the template to be rendered may not use any of them.
Proposed resolution
Instantiate Attribute objects in a consistent fashion and/or location. Since the main benefit of the Attribute class is only printing the attributes once, consider moving all instantiation of Attribute objects to as late as possible in the rendering process.
Remaining tasks
TBD
User interface changes
n/a
API changes
TBD
Related Issues
#1982018: [meta] Refactor template_preprocess()
#1757550: [meta] Convert core theme functions and templates to Twig