Problem/Motivation

Right now the Visibility per language plugin does not provide a summary to display in the Paragraph widget.

Proposed resolution

Build the summary,

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yongt9412 created an issue. See original summary.

johnchque’s picture

Status: Active » Needs review
FileSize
1.27 KB

This should work. :)

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/paragraphs/Behavior/ParagraphsLanguagePlugin.php
    @@ -182,4 +182,35 @@ class ParagraphsLanguagePlugin extends ParagraphsBehaviorBase {
    +
    +    switch ($visibility['visibility']) {
    +      case 'hide':
    +      case 'show':
    +        $summary[] = [
    +          'label' => $visibility['visibility'] == 'hide' ? 'Hide for' : 'Show for',
    +          'value' => \implode($language_names, ', '),
    +        ];
    

    hide for/show for should be translatable strings.

  2. +++ b/src/Plugin/paragraphs/Behavior/ParagraphsLanguagePlugin.php
    @@ -182,4 +182,35 @@ class ParagraphsLanguagePlugin extends ParagraphsBehaviorBase {
    +      case 'always':
    +      case 'default':
    +        $summary[] = [
    +          'label' => $this->t('Visibility'),
    +          'value' => $this->t('Always visible')
    +        ];
    +        break;
    

    we don't need a summary for the default setting, that doesn't add something useful.

    Do he have some UI tests that we could easily extend with an assertion for this?

Deepak Goyal’s picture

Assigned: Unassigned » Deepak Goyal
Deepak Goyal’s picture

Assigned: Deepak Goyal » Unassigned
Status: Needs work » Needs review
FileSize
1.28 KB
798 bytes

Hi @Berdir
Updated patch please review.

Berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Hm, looks like the test class renaming in paragraphs broke paragraphs_collection :-/

Lets fix that in a separate issue.

Also, I wasn't clear, but 'always' should be removed as well, not interested in that output either in the summary.

johnchque’s picture

Assigned: Unassigned » johnchque

Working on this.

johnchque’s picture

Status: Needs work » Needs review
FileSize
1.11 KB
1.51 KB

Updated the logic not to do some operations without having the right values set.

Status: Needs review » Needs work

The last submitted patch, 8: 3155150-visibility-summary-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

So the existing tests seems to trigger a notice, which is great, because it means we already trigger this method and need to a) fix it and b) add an assert for the expected message.

johnchque’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
2.35 KB
2.34 KB

Adding tests and fixing the notice. :)

Berdir’s picture

Status: Needs review » Fixed
+++ b/src/Plugin/paragraphs/Behavior/ParagraphsLanguagePlugin.php
@@ -189,14 +189,16 @@
     if ($visibility = $paragraph->getBehaviorSetting($this->getPluginId(), 'container')) {
       if ($visibility['visibility'] == 'hide' || $visibility['visibility'] == 'show') {
-        $language_names = [];
-        foreach ($visibility['languages'] as $language) {
-          $language_names[] = $this->languageManager->getLanguageName($language);
+        if (isset($visibility['languages'])) {
+          $language_names = [];

that we have this extra container key in the stored settings is unfortunate, but hard to fix now.

Committed.

  • Berdir committed 78876f6 on 8.x-1.x authored by yongt9412
    Issue #3155150 by yongt9412, Deepak Goyal: Visibility per language...

Status: Fixed » Closed (fixed)

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