diff --git a/config/schema/layout_paragraphs.schema.yml b/config/schema/layout_paragraphs.schema.yml index f0e21cc1a283011c9e0d90096f60435b4e5ccd91..1c59c38d487397b4b95d5c462f4d70b840de9045 100644 --- a/config/schema/layout_paragraphs.schema.yml +++ b/config/schema/layout_paragraphs.schema.yml @@ -78,6 +78,9 @@ field.widget.settings.layout_paragraphs: type: mapping label: 'Layout Paragraphs display format settings' mapping: + view_mode: + type: string + label: 'View mode' preview_view_mode: type: string label: 'Preview view mode' diff --git a/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php b/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php index ac8a88c2a08d1f7ef8075de6709131b480f4000d..fc0f6a36ec37ba96d9172e90944379248fb812ed 100644 --- a/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php @@ -365,12 +365,19 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi public function settingsForm(array $form, FormStateInterface $form_state) { $entity_type_id = $this->getFieldSetting('target_type'); $element = parent::settingsForm($form, $form_state); + $element['view_mode'] = array( + '#type' => 'select', + '#title' => $this->t('View mode'), + '#default_value' => $this->getSetting('view_mode'), + '#options' => $this->entityDisplayRepository->getViewModeOptions($entity_type_id), + '#required' => TRUE, + ); $element['preview_view_mode'] = [ '#type' => 'select', '#title' => $this->t('Preview view mode'), '#default_value' => $this->getSetting('preview_view_mode'), '#options' => $this->entityDisplayRepository->getViewModeOptions($entity_type_id), - '#description' => $this->t('View mode for the referenced entity preview on the edit form. Automatically falls back to "default", if it is not enabled in the referenced entity type displays.'), + '#description' => $this->t('View mode for the referenced entity preview on the edit form. Automatically falls back to "default" if it is not enabled in the referenced entity type displays.'), ]; $element['nesting_depth'] = [ '#type' => 'select', @@ -397,7 +404,12 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi */ public function settingsSummary() { $summary = parent::settingsSummary(); - $summary[] = $this->t('Preview view mode: @preview_view_mode', ['@preview_view_mode' => $this->getSetting('preview_view_mode')]); + $view_modes = $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type')); + $view_mode = $this->getSetting('view_mode'); + $preview_view_mode = $this->getSetting('preview_view_mode'); + + $summary[] = $this->t('Rendered as @mode', ['@mode' => $view_modes[$view_mode] ?? $view_mode]); + $summary[] = $this->t('Preview view mode: @preview_mode', ['@preview_mode' => $view_modes[$preview_view_mode] ?? $preview_view_mode]); $summary[] = $this->t('Maximum nesting depth: @max_depth', ['@max_depth' => $this->getSetting('nesting_depth')]); if ($this->getSetting('require_layouts')) { $summary[] = $this->t('Paragraphs <b>must be</b> added within layouts.'); @@ -418,6 +430,7 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $defaults = parent::defaultSettings(); $defaults += [ 'empty_message' => '', + 'view_mode' => 'default', 'preview_view_mode' => 'default', 'nesting_depth' => 0, 'require_layouts' => 0,