Problem/Motivation

We have a summary with icons now.
However, only the text summary can be provided by plugins.

It's the plugins that extend Paragraphs with functionality where text representation is inaccessible.
The lock icon on the left side already should be provided by the lock plugin, while the lock on the right (instead of the edit button) side is a plain fact.

Common things that should be iconised:
- Layout (plugin)
- Style (plugins)
- Plugin type (A carousel, ..)

Proposed resolution

Add a new method so plugins can provide icons.

Extend a test plugin to provide e.g. a blod icon:
modules/paragraphs/src/Tests/Experimental/ParagraphsExperimentalBehaviorsTest.php
modules/paragraphs/tests/modules/paragraphs_test/src/Plugin/paragraphs/Behavior/TestBoldTextBehavior.php
\Drupal\paragraphs\Tests\Experimental\ParagraphsExperimentalBehaviorsTest::testCollapsedSummary

This implementation will remove the left lock icon from Paragraphs. Paragraphs Collection will bring it back with implementing the method.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker created an issue. See original summary.

miro_dietiker’s picture

From #2904402-3: Improvements in UI
Ideas about when the lock inside the summary should be displayed:

The left lock should not be displayed by Paragraphs itself. Instead, the Paragraphs Collection lock plugin should provide it and indicate "This row is locked (for people with lower permissions)."

Thus, as an admin, you never see the right lock and you need the lock in summary on the left side to understand what is locked for others.
We could also only output the lock by the behavior plugins summary lock if the user can edit the Paragraph. So it only appears once.

pivica’s picture

Here is a first patch proposal.

ParagraphsBehaviorInterface has a new method settingsInfo() method which is similar to settingsSummary() and it allows behaviour plugins to return an array of info items.

ParagraphInterface has a new method getInfo() which for now adds child count as a badge info item and then query all behaviour plugins for additional info items. With this, we can also close #2903491: Display Paragraphs child count in summary as badge as a duplicate now because we have child count badge support now.
And we also addressed all the issues in comment #2.

Tests are updated.

For this patch to work and be tested properly we also need a patch for a locking behaviour plugin #2904637: Convert lockable plugin to use new settingsInfo() instead of settingsSummary().

Attaching screenshots of a new look, notice that we also changed the colour of lock icon from blue to grey as per discussion in #2904402-3: Improvements in UI.

Regular editor (without permissions to change locked items):

Power editor (with permission to lock items and change them):

Status: Needs review » Needs work

The last submitted patch, 3: plugins-info-items-support-2903489.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pivica’s picture

Status: Needs work » Needs review
FileSize
4.31 KB
20.18 KB

Here is updated patch that is fixing broken tests.

However the

fail: [Other] Line 487 of modules/contrib/paragraphs/src/Tests/Experimental/ParagraphsExperimentalAdministrationTest.php:
"The referenced entity (node: 4) does not exist" found

Is not related to this changes. My guess is that probably something changed in core related to entity reference field or something else and now when you delete referenced node the reference will also be deleted in the parent node.

Status: Needs review » Needs work

The last submitted patch, 5: plugins-info-items-support-2903489-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

miro_dietiker’s picture

I triggered retest of PHP7 + MySQL 5.5 + Core 8.4 and it passed:
https://www.drupal.org/pift-ci-job/749628

So the issue seems to be specific to this patch.

Berdir’s picture

  1. +++ b/src/Entity/Paragraph.php
    @@ -469,12 +469,39 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getInfo(array $options = []) {
    

    this is called getInfo() but it returns $icons. getInfo() is a very generic name, why not call it getIcons() or getSummaryIcons() ?

  2. +++ b/src/Entity/Paragraph.php
    @@ -469,12 +469,39 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
    +        if ($plugin_info = $plugin->settingsInfo($this)) {
    

    same for this method.

  3. +++ b/src/ParagraphInterface.php
    @@ -39,6 +39,20 @@ interface ParagraphInterface extends ContentEntityInterface, EntityOwnerInterfac
    +   * @return array
    +   *   Info items array.
    +   */
    +  public function getInfo(array $options = []);
    

    related to naming, also needs better description/explanation of what the method returns (basically a list of render arrays that will be rendered as icoons)

  4. +++ b/src/ParagraphsBehaviorInterface.php
    @@ -123,8 +123,21 @@ interface ParagraphsBehaviorInterface extends PluginFormInterface, ConfigurableP
    +   * @return string[]
    +   *   The plugin settings.
    

    same here, but the descriptions above are already better, we could also add a @see here to the ParagraphsInterface method.

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -437,35 +436,38 @@ class ParagraphsWidget extends WidgetBase {
    +        'info' => [
    +          '#type' => 'container',
    +          '#attributes' => ['class' => ['paragraph-type-info']],
    +        ],
    +        'summary' => [
    +          '#type' => 'container',
    +          '#attributes' => ['class' => ['paragraph-type-summary']],
    +        ],
    

    classes are a bit strange, the above two makes sense as it is the paragraphs *type* title/icon, but this is about the paragraph, not the paragraph type.

    And again the point that info here is very generic and unclear, I also see now where getInfo() is coming from.

  6. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -437,35 +436,38 @@ class ParagraphsWidget extends WidgetBase {
    +        $element['top']['type']['label'] = ['#markup' => $bundle_info['label']];
    

    not a problem of this issue, but the fact that we check the existense of the paragraph type here is kinda weird, things are going to end badly if that doesn't exist. Lots of things are inside that check and many others are not, seems pretty random. but fine, lets keep that for now.

pivica’s picture

Status: Needs work » Needs review
FileSize
13.28 KB
24.79 KB

Here is a new patch (build against latest dev), points 1 to 5 from comment #8 are done. I've also change classes paragraph-type-title to just paragraph-type and paragraph-type-top to paragraph-top for experimental widget, make more sense too me.

> not a problem of this issue, but the fact that we check the existence of the paragraph type here is kinda weird

If you are referring to:

$item_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($target_type);
if (isset($item_bundles[$paragraphs_entity->bundle()])) {
  $bundle_info = $item_bundles[$paragraphs_entity->bundle()];

yeah seems to me this if is totally necessary because it is checking something that can not happen. Anyway, this is old code, we create follow-up for this?


I triggered retest of PHP7 + MySQL 5.5 + Core 8.4 and it passed:
https://www.drupal.org/pift-ci-job/749628

So the issue seems to be specific to this patch.

@berdir said he will check this when he find's time, probably he still didn't do it, will ping him about this.

pivica’s picture

@berdir, what do you think should we also rename paragraphs_info_icon theme to paragraphs_icon? I know here we have plural and in class names single - i guess classes should also be plural, but i think we have a separate issue for this already.

Status: Needs review » Needs work

The last submitted patch, 9: plugins-info-items-support-2903489-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pivica’s picture

Fixed new failed tests from the last patch.

Status: Needs review » Needs work

The last submitted patch, 12: plugins-info-items-support-2903489-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

Fixed the tests.

pivica’s picture

Discussed comment #10 also with @berdir, he is OK we leave paragraphs_info_icon theme name. So we are good to go with this.

  • miro_dietiker committed 861a759 on 8.x-1.x authored by Berdir
    Issue #2903489 by pivica, Berdir: Allow plugins to extend summary icons
    
miro_dietiker’s picture

Status: Needs review » Fixed

OK cool, committed. Cool to have the badge thing in as well! :-)

Status: Fixed » Closed (fixed)

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