Problem/Motivation

Followup from #2852126: Improve paragraphs display in the library overview.The paragraphs library overview displays library items as rendered entities in a default view mode.
We could add a new view mode, showing just the summary for library items and use it instead (in the overview).

Proposed resolution

Provide a paragraphs formatter showing just the summary.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Ginovski created an issue. See original summary.

ginovski’s picture

Title: Create paragraphs formatter » Add paragraphs formatter
StatusFileSize
new1.71 KB

Added paragraphs formatter.

ginovski’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: create_paragraphs-2862284-2.patch, failed testing.

miro_dietiker’s picture

The summary is an admin UI output, here intentionally for a super compact output inside an administrative table.

The teaser output is typically a frontend output.
IMHO we should not use the term "teaser" for an admin UI view mode.

ginovski’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.06 KB

Re-added the formatter, think it will apply this time.
Addressed #5 comment, changed issue description.

ginovski’s picture

StatusFileSize
new1.68 KB

Removed unrelated change from previous patch.

primsi’s picture

Status: Needs review » Needs work
Related issues: +#2852001: Consider container multivalue children for closed summary
  1. +++ b/src/Plugin/Field/FieldFormatter/ParagraphsFormatter.php
    @@ -0,0 +1,54 @@
    +class ParagraphsFormatter extends FormatterBase {
    

    ParagraphsFormatter is to generic IMHO. We should name this something like ParagraphsSummaryFormatter

  2. +++ b/src/Plugin/Field/FieldFormatter/ParagraphsFormatter.php
    @@ -0,0 +1,54 @@
    +    $paragraph_type = \Drupal::entityTypeManager()->getDefinition($target_type);
    

    Inject

Direction is in my opinion good. But we need to add tests.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new7.73 KB

Changed name to ParagraphsSummaryFormatter.
Added tests.
About the injection, the method is static, so it cannot use $this.

primsi’s picture

Title: Add paragraphs formatter » Add paragraphs summary formatter
primsi’s picture

primsi’s picture

Old issue with an interesting link in #11: #2433933: Paragraph summary formatter

primsi’s picture

Issue summary: View changes

We have a lot of room for improvement in the summary area. But we could keep it simple here, so that other issues can have something to work on and we can improve it later.

+++ b/src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php
@@ -0,0 +1,54 @@
+      if ($paragraph = Paragraph::load($item->getValue()['target_id'])) {

I think loading of additional information should be done in prepareView. See \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase::prepareView for example.

Also I see that in EntityRefferenceFormatterBase::view core tries add acces result cacheability information. Not sure if we need something similar here in the light of behavior lockable plugin. More opinions regarding that woud be wellcome.

primsi’s picture

Status: Needs review » Needs work
berdir’s picture

lockable is edit, that doesn't apply here but yes, we need to respect entity view access, which

But yes, that code is very strange, just do $item->entity. And actually, in that method, the correct thing to do is the same as all other formatters, that is foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {

miro_dietiker’s picture

Priority: Normal » Major

This is blocking progress for the library in collection. Plz link.

miro_dietiker’s picture

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new2.13 KB
new8.4 KB

1. Loading paragraphs in prepareView.
2. Adding the markup through getEntitiesToView().

berdir’s picture

Status: Needs review » Needs work

I don't see why we need to override prepareView(), isn't that the same as the parent?

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new1.29 KB
new7.71 KB

Removed prepareView.

  • Primsi committed 9102e30 on 8.x-1.x authored by Ginovski
    Issue #2862284 by Ginovski, Primsi, miro_dietiker, Berdir: Add...
primsi’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.