Problem/Motivation
\Drupal\filter\Plugin\FilterInterface::tips()
is designed to return only translated strings. However, sometime the tips text gets complex, involving a lot of markup that fits better to a renderable array than a simple string.
Here's a use case that reveals the need of providing a renderable array instead of a string: https://github.com/claudiu-cristea/token_filter/blob/8.x-1.x/src/Plugin/.... You can see here that, right now, the process is: renderable > render > string (MarkupInterface) > renderable [in _filter_tips()] > render> string (MarkupInterface). You can see that, for this particular case, we render twice the same piece of markup.
Proposed resolution
Alternatively, allow renderable arrays as return for \Drupal\filter\Plugin\FilterInterface::tips()
. Convert one core implementation.
The above use case (https://github.com/claudiu-cristea/token_filter/blob/8.x-1.x/src/Plugin/...) will simply return the array (not MarkupInterface) and that will simplify the process: renderable > render> string (MarkupInterface)
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#13 | Screenshot from 2018 01 04 15 39 35.png | 28.19 KB | pvsureshmca |
#3 | interdiff.txt | 2.42 KB | claudiu.cristea |
#3 | 2642432-3.patch | 6.46 KB | claudiu.cristea |
#2 | 2642432-2.patch | 4.03 KB | claudiu.cristea |
Comments
Comment #2
claudiu.cristeaPatch.
Comment #3
claudiu.cristeaAdded test.
Comment #4
claudiu.cristeaUpdated the IS.
Comment #5
XanoComment #6
claudiu.cristea@Xano, what is the reason for tagging with "BC break"? This patch doesn't break the BC. If I'm wrong please readd the tag but add also an explanation.
Comment #7
XanoIf a method suddenly returns a new data type, it breaks calling code that does not expect this new type. Because this is an API method (and not an internal one), this is a backwards-compatibility breaking API change.
Comment #12
pvsureshmca CreditAttribution: pvsureshmca at DrupalPartners commentedComment #13
pvsureshmca CreditAttribution: pvsureshmca at DrupalPartners commentedHi,
I am getting the below issue when I apply this patch.
Comment #15
claudiu.cristeaMarked #2867425: Let FilterInterface::tips return a render array, not a string. as duplicate of this.
Comment #16
claudiu.cristea