Consider adding a hook to Paragraphs::getSummary

Created on 10 April 2017, about 8 years ago
Updated 2 May 2023, about 2 years ago

Follow-up to #2862083: [META] Improve paragraphs summary

Problem/Motivation

We currently support a few field types in getSummary. Modules that implement other field types could use a hook to handle their types.

Proposed resolution

Let's first see how much does current solution already cover and if we see that there are more use cases that we can't handle in Paragraphs, add the hook.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

RTBC

Version

1.0

Component

Code

Created by

🇸🇮Slovenia primsi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom andrew robinson

    I believe these patches fail in Drupal 10 sites with the error:

    Uncaught Error: Class "Symfony\Component\EventDispatcher\Event" not found in modules/contrib/paragraphs/src/Event/ParagraphSummaryAlterEvent.php:4

    According to vendor/symfony/event-dispatcher/CHANGELOG.md, in Symfony 5.x

    Based on this I think the use statement at the top of src/Event/ParagraphSummaryAlterEvent.php should be updated
    from
    use Symfony\Component\EventDispatcher\Event;
    to
    use Symfony\Contracts\EventDispatcher\Event;

    for sites that are based on Symfony 5 or above.

  • 🇩🇪Germany a.dmitriiev

    @vladigor@gmail.com In patch #38 this class is not used. It uses the class Drupal\Component\EventDispatcher\Event according to change record: https://www.drupal.org/node/3159012

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update almost 2 years ago
    180 pass
  • 🇬🇧United Kingdom andrew robinson

    Thanks @a.dmitriiev.
    I've switched over to patch #38 on my Drupal 10.1.0 site using Paragraphs 1.15.0.
    When I try to edit a page that contains paragraphs I get the following error:

    TypeError: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch(): Argument #1 ($event) must be of type object, string given, called in /app/docroot/modules/contrib/paragraphs/src/Entity/Paragraph.php on line 468 in Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (line 89 of core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php).
    

    It appears that in Drupal 10.1 the event_dispatcher service uses the dispatch function from ContainerAwareEventDispatcher.php, which expects $event as the first parameter.
    Ref. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Even...

    I've attached an updated version of patch #38 that switches around the parameters in the two calls to the dispatch function.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    159 pass, 12 fail
  • Status changed to Needs review almost 2 years ago
  • 🇧🇪Belgium LRoels Ghent

    Changing the status to needs review for now. Seems wrong to keep it on RTBC.

  • 🇬🇧United Kingdom LiamPower

    #42 is working for me with Drupal 10.1.5 and Paragraphs 8.x-1.16

  • Status changed to RTBC over 1 year ago
  • 🇩🇪Germany a.dmitriiev

    #42 is working for me as well for Drupal 10

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Composer require-dev failure
  • 🇺🇸United States gmercer

    Re-rolled #42 patch to check for empty of summary[$type] on appendTextToSummary() and prependTextToSummary() in src/Event/ParagraphSummaryAlterEvent.php

  • 🇷🇴Romania alexandra22

    Re-rolled #46 for 1.19.

  • Pipeline finished with Canceled
    2 months ago
    Total: 75s
    #438521
  • 🇩🇪Germany a.dmitriiev

    I have opened MR based on patch #47 for easier review process and maybe it will speed up the merge of the changes.

  • Pipeline finished with Failed
    2 months ago
    Total: 302s
    #438522
  • First commit to issue fork.
  • Pipeline finished with Canceled
    2 months ago
    Total: 174s
    #438597
  • 🇧🇪Belgium joevagyok

    The MR had missing pieces from the patch, I pushed it.
    I attached a patch file for composer patching against 1.19 version.

  • Pipeline finished with Failed
    2 months ago
    Total: 293s
    #438600
  • 🇬🇧United Kingdom andreastkdf

    confirming that the pacth #51 📌 Consider adding a hook to Paragraphs::getSummary RTBC and MR work on:

    • Drupal: 10.4.5
    • Paragraphs: 1.19.0

    In our case we use a ParagraphSummarySubscriber to alter paragraphs summary based on custom conditions, which works as expected using ParagraphSummaryAlterEvent

  • 🇩🇪Germany harkonn

    I can confirm the merge-request code works fine in Drupal 10.4.6.

    I am just confused about adding isEmpty for append and prepend methods from #46. I don't see the benefit in having to check the summary in my own code before using appending/prepending.

    I don't want to just change it without getting another feedback on this opinion.

Production build 0.71.5 2024