Hi,

For a client needs, I create a "paragraph_summary" formatter that I use in the teaser view_mode for my host entity.

This formatter allow to
- choose which paragraphs bundles are allowed to be displayed (only "text" paragraph in my case)
- paragraphs bundles view mode
- How many paragraphs items are displayed

You can find the code here : https://gist.github.com/opi/c0cb89a3b7c934c5fe7a, and a screenshot with formatter's settings attached

I wonder how to release this formatter to the beautiful Drupal contrib world, whether in a dedicated contrib module or as a core paragraphs formatter.
Do you think that it's a usefull formatter ? Do you prefer a patch to integrate this formatter to paragraphs module or a separated contib module ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rozh’s picture

Thank you, opi. This is very useful!
IMHO it is a missed part of Paragraphs module functionality because of drupal node nature. Node has summary formatter in core. So I think this formatter should be in Paragraphs module.

jeroen.b’s picture

Very cool indeed!
Would you mind making a patch out of this?

opi’s picture

Thanks for your positive replies !
I will make a patch against the dev branch in the next few days.

opi’s picture

Status: Active » Needs review
FileSize
5.5 KB

Here's the patch ;)

dddbbb’s picture

Just tested the patch in #4 and it works - top work @opi, much appreciated.

However, I still find myself creating a dedicated "summary" long text field on entities for use on teaser-like view modes, here's why:

Mostly, my paragraphs fields are drop in replacements for typical body fields; they consist of a mixture of long text fields and images mainly and as such are generally setup to allow unlimited values. The patch in #4 usefully allows me to restrict what paragraphs bundles are considered for summary text (so just the long text ones in my case) but it doesn't allow me to specify which paragraph item(s). Also, I prefer to restrict summary text to just plain text to save headaches when presenting teasers but my paragraphs text items support HTML to a degree in order to allow users to add links, lists, bold text etc.

My workaround is OK but there's room for improvement: it doesn't support a "Summary or trimmed" model for example.

Ideally what I'd like to see is for the Paragraphs field itself to have a single, optional summary field, much like a "Long text with summary" field. Then via a formatter I could choose "Summary or trimmed" - the former rendering the content of the previously mentioned Summary field, the latter handing over to something like what @opi has already developed but with an additional trim setting.

I hesitate to set this issue back to "Needs work" as @opi's patch does indeed work (if all you need is a summary formatter then you're good to go). I just feel that it's a single part of something a bit larger that is needed.

n_vashenko’s picture

Hi, #4 works great, thanks. Is it planned to commit this patch?

Thanks, Nikita.

miro_dietiker’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

This is a (nice) new feature. This means IMHO
- Drupal 8 first
- Needs full functional test coverage

opi’s picture

I'm not doing any Drupal8 dev for now, so you need to find someone else to port this patch to the 8.x branch of paragraph module.

miro_dietiker’s picture

Issue tags: +Usability

Something like this could make sense for the JS collapsing while dragging.
See #2721941: Add a JS based collapse / expand

A paragraph has no title / label, thus we need a way to configure what is its summary.

opi’s picture

Note that I released a stand-alone module for Drupal 7 branch of paragraphs : https://www.drupal.org/project/paragraphs_summary

John Pitcairn’s picture

mtalt also started a sandbox based on the D7 module at https://www.drupal.org/sandbox/mtaltavull/2830717

I'm using a modified version of that with the text filtering/trim options removed, simply to limit the type and number of paragraphs that a multi-value paragraphs field displays for each host entity view mode. This returns an $elements build array and allows more generic handling for any paragraph type.

The text filter/trim/summary options are very bundle-specific, and I think these are perhaps better handled in each referenced paragraph, via advanced text formatter or similar in a view mode, rather than returning a combined markup element from this formatter (which can only work for text). Either that or the summary needs to be optional, and return an $elements build array if the summary option is not selected.

A very useful enhancement to this would be to allow a different view mode to be configured for each allowed paragraph bundle.

Primsi’s picture

This looks great. We are adding a summary formatter in #2862284: Add paragraphs summary formatter The patch over there could use some improvements. It would be great if we could somehow combine both.

One note: Paragraphs entity class now has a method that generates summary (was moved from the widget), but that too needs improvement, like passing in arguments about the desired output of the summary. Meta issue: #2862083: [META] Improve paragraphs summary

tea.time’s picture

opi’s picture

FYI I've ported my old D7 paragraphs_summary formatter to D8, here is the code https://gist.github.com/opi/879fe7d9932c25a41daa9c42f1dc804b ; It's pretty raw and do not have test coverage, but one could find it useful anyway.
It has the same behavior as the D7 version, you select which bundle are allowed, how much, and the view_mode.

waspper’s picture

Nice feature. IMHO, the contrib module (https://www.drupal.org/project/paragraphs_summary) could be a sub-module into Paragraphs project. very useful.