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);
}
}
}| Comment | File | Size | Author |
|---|---|---|---|
| #8 | paragraphs-view_mode_selector_support-2566103-8.patch | 1.13 KB | Anonymous (not verified) |
| #5 | paragraphs-view_mode_selector_support-2566103-4.patch | 1.15 KB | Anonymous (not verified) |
| #2 | paragraphs-view_mode_selector_support-2566103-1.patch | 1.12 KB | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) commentedDeraynger created an issue. See original summary.
Comment #2
Anonymous (not verified) commentedAdded patch
Comment #3
Anonymous (not verified) commentedComment #5
Anonymous (not verified) commentedCorrected patch format
Comment #6
Anonymous (not verified) commentedComment #8
Anonymous (not verified) commentedCorrect patch for dev version.
Comment #9
Anonymous (not verified) commentedComment #11
Anonymous (not verified) commentedOk, 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