Problem/Motivation

In an age where static analysis thrives, passing around RenderebleInterface is preferrable over passing "naked" RenderArrays. (An array can be anything, a Renderable is typed.)

Proposed resolution

Gradually replace passing around render arrays w/ passing around RenderableInterface objects (in child issues).

Some thoughts:
- Provide a blessed Renderable object with good DX in core.
- Allow RenderableInterface as a return value e.g. in EntityInterface::label(). (How can a deprecation dance be done for a return type extension? Prior examples?)

Remaining tasks

...

Comments

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Title: [Plan] Gradually replace passing around RenderArrays with RenderableInterfafce objects » [Plan] Gradually replace passing around RenderArrays with RenderableInterface objects
ghost of drupal past’s picture

Continue from https://www.drupal.org/project/drupal/issues/3525331#comment-16227159 , a full attempt failed but the partial attempt described there would work.

To recap

  1. Reuse the element plugins as element objects
  2. For phase 1, do not change the renderer and form builder itself just treat this as a builder helper
  3. In particular, add new methods for widgets and formatters which can be implemented with the new objects
  4. Add a helper to convert back and forth for form alter and "plain" forms
  5. Once everything uses oop convert renderer and form builder and drop the helpers. D13 or at this pace D14.
geek-merlin’s picture

@ghost of drupal past Terrific.

Ditched quickly through the source. ElementInterface is NOT RenderableInterface, so it looks like the other issue aims higher than this one. Do i get this right?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.