I'd like support for the module View Mode Selector module for paragraph items. I saw similar issues, but couldn't find one directly related to the module. What happens is that the view mode doesn't get selected.

I'll provide a patch, but it needs to be reviewed, e.g. I didn't consider multi-lingual support (but apparently entity field translation isn't supported (yet), so this shouldn't be a problem). Then there's the view_mode_selector 'default' view mode, but paragraphs usually uses 'full', so maybe this would need to be changed (but I believe it'd fall back to that if no view_mode is found). Here's the code, so it's easier to review.

In paragraphs_field_formatter_view during the foreach-loop I modified it like this:

foreach ($items as $delta => $item) {
        if ($paragraph = paragraphs_field_get_entity($item)) {
          if (entity_access('view', 'paragraphs_item', $paragraph)) {

            

            // Get correct view_mode for paragraph if view_mode_selector module is used.
            if (module_exists('view_mode_selector')) {

              $fields_info = field_info_instances('paragraphs_item', $paragraph->bundle);
              foreach ($fields_info as $field_name => $value) {

                if (field_info_field($field_name)['type'] == 'view_mode_selector') {
                  if (!empty($paragraph->{$field_name}[LANGUAGE_NONE][0]['value'])) {
                    $view_mode = $paragraph->{$field_name}[LANGUAGE_NONE][0]['value'];
                  }
                  break;
                }
              }
            }


            $element[$delta]['entity'] = $paragraph->view($view_mode);
          }
        }
      }
CommentFileSizeAuthor
#8 paragraphs-view_mode_selector_support-2566103-8.patch1.13 KBAnonymous (not verified)
#5 paragraphs-view_mode_selector_support-2566103-4.patch1.15 KBAnonymous (not verified)
#2 paragraphs-view_mode_selector_support-2566103-1.patch1.12 KBAnonymous (not verified)

Comments

Anonymous’s picture

Deraynger created an issue. See original summary.

Anonymous’s picture

Added patch

Anonymous’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: paragraphs-view_mode_selector_support-2566103-1.patch, failed testing.

Anonymous’s picture

Corrected patch format

Anonymous’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: paragraphs-view_mode_selector_support-2566103-4.patch, failed testing.

Anonymous’s picture

Correct patch for dev version.

Anonymous’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: paragraphs-view_mode_selector_support-2566103-8.patch, failed testing.

Anonymous’s picture

Status: Needs work » Closed (duplicate)

Ok, my bad, it is actually the same issue, I just had to update the paragraphs module to RC3: https://www.drupal.org/node/2493409#comment-9951511