From 7b5524a3b16509d1c0b7922f824766ba0c9a2208 Mon Sep 17 00:00:00 2001 From: Mohammed Nassar Date: Fri, 9 Aug 2019 08:26:59 +0000 Subject: [PATCH 1/5] Issue #65: Add (Columns layout) variant for (Content row) paragraph type. --- ...aragraph.oe_content_row.columns_layout.yml | 47 +++++++++++++++++++ ...splay.paragraph.oe_content_row.default.yml | 7 +++ ...ity_form_mode.paragraph.columns_layout.yml | 9 ++++ ...splay.paragraph.oe_content_row.default.yml | 9 ++++ ...ontent_row.field_oe_content_row_layout.yml | 20 ++++++++ ....paragraph.field_oe_content_row_layout.yml | 20 ++++++++ oe_paragraphs.info.yml | 6 +++ 7 files changed, 118 insertions(+) create mode 100644 config/install/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml create mode 100644 config/install/core.entity_form_mode.paragraph.columns_layout.yml create mode 100644 config/install/field.field.paragraph.oe_content_row.field_oe_content_row_layout.yml create mode 100644 config/install/field.storage.paragraph.field_oe_content_row_layout.yml diff --git a/config/install/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml b/config/install/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml new file mode 100644 index 00000000..d25d56e5 --- /dev/null +++ b/config/install/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml @@ -0,0 +1,47 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_form_mode.paragraph.columns_layout + - field.field.paragraph.oe_content_row.field_oe_content_row_layout + - field.field.paragraph.oe_content_row.field_oe_paragraphs + - field.field.paragraph.oe_content_row.field_oe_title + - paragraphs.paragraphs_type.oe_content_row + module: + - oe_paragraphs +id: paragraph.oe_content_row.columns_layout +targetEntityType: paragraph +bundle: oe_content_row +mode: columns_layout +content: + field_oe_content_row_layout: + type: options_select + weight: 0 + region: content + settings: { } + third_party_settings: { } + field_oe_paragraphs: + weight: 1 + settings: + title: Paragraph + title_plural: Paragraphs + edit_mode: closed + closed_mode: summary + autocollapse: none + closed_mode_threshold: 0 + add_mode: dropdown + form_display_mode: default + default_paragraph_type: _none + features: + duplicate: duplicate + collapse_edit_all: collapse_edit_all + add_above: '0' + third_party_settings: { } + type: oe_paragraphs_variants + region: content +hidden: + created: true + field_oe_title: true + status: true + translation: true + uid: true diff --git a/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml b/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml index 4dac2f15..746cc3ae 100644 --- a/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml +++ b/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml @@ -2,6 +2,7 @@ langcode: en status: true dependencies: config: + - field.field.paragraph.oe_content_row.field_oe_content_row_layout - field.field.paragraph.oe_content_row.field_oe_paragraphs - field.field.paragraph.oe_content_row.field_oe_title - paragraphs.paragraphs_type.oe_content_row @@ -12,6 +13,12 @@ targetEntityType: paragraph bundle: oe_content_row mode: default content: + field_oe_content_row_layout: + weight: 1 + settings: { } + third_party_settings: { } + type: options_select + region: content field_oe_paragraphs: weight: 0 settings: diff --git a/config/install/core.entity_form_mode.paragraph.columns_layout.yml b/config/install/core.entity_form_mode.paragraph.columns_layout.yml new file mode 100644 index 00000000..802495cd --- /dev/null +++ b/config/install/core.entity_form_mode.paragraph.columns_layout.yml @@ -0,0 +1,9 @@ +langcode: en +status: true +dependencies: + module: + - paragraphs +id: paragraph.columns_layout +label: 'Columns layout' +targetEntityType: paragraph +cache: true diff --git a/config/install/core.entity_view_display.paragraph.oe_content_row.default.yml b/config/install/core.entity_view_display.paragraph.oe_content_row.default.yml index 28fa2c5a..c88e3788 100644 --- a/config/install/core.entity_view_display.paragraph.oe_content_row.default.yml +++ b/config/install/core.entity_view_display.paragraph.oe_content_row.default.yml @@ -2,16 +2,25 @@ langcode: en status: true dependencies: config: + - field.field.paragraph.oe_content_row.field_oe_content_row_layout - field.field.paragraph.oe_content_row.field_oe_paragraphs - field.field.paragraph.oe_content_row.field_oe_title - paragraphs.paragraphs_type.oe_content_row module: - entity_reference_revisions + - options id: paragraph.oe_content_row.default targetEntityType: paragraph bundle: oe_content_row mode: default content: + field_oe_content_row_layout: + weight: 3 + label: above + settings: { } + third_party_settings: { } + type: list_default + region: content field_oe_paragraphs: weight: 2 label: above diff --git a/config/install/field.field.paragraph.oe_content_row.field_oe_content_row_layout.yml b/config/install/field.field.paragraph.oe_content_row.field_oe_content_row_layout.yml new file mode 100644 index 00000000..74adc126 --- /dev/null +++ b/config/install/field.field.paragraph.oe_content_row.field_oe_content_row_layout.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.paragraph.field_oe_content_row_layout + - paragraphs.paragraphs_type.oe_content_row + module: + - options +id: paragraph.oe_content_row.field_oe_content_row_layout +field_name: field_oe_content_row_layout +entity_type: paragraph +bundle: oe_content_row +label: Layout +description: 'Column layout for displaying content items. If none selected, the content will be displayed in one column.' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: list_string diff --git a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml new file mode 100644 index 00000000..51c20ad6 --- /dev/null +++ b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + module: + - options + - paragraphs +id: paragraph.field_oe_content_row_layout +field_name: field_oe_content_row_layout +entity_type: paragraph +type: list_string +settings: + allowed_values: { } + allowed_values_function: '' +module: options +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/oe_paragraphs.info.yml b/oe_paragraphs.info.yml index 3e3e48ef..9d26c446 100644 --- a/oe_paragraphs.info.yml +++ b/oe_paragraphs.info.yml @@ -17,6 +17,7 @@ dependencies: config_devel: install: # Form modes. + - core.entity_form_mode.paragraph.columns_layout - core.entity_form_mode.paragraph.date - core.entity_form_mode.paragraph.highlight - core.entity_form_mode.paragraph.inpage_navigation @@ -87,11 +88,13 @@ config_devel: - paragraphs.paragraphs_type.oe_list_item_block # Content row + - core.entity_form_display.paragraph.oe_content_row.columns_layout - core.entity_form_display.paragraph.oe_content_row.default - core.entity_form_display.paragraph.oe_content_row.inpage_navigation - core.entity_view_display.paragraph.oe_content_row.default - field.field.paragraph.oe_content_row.field_oe_paragraphs - field.field.paragraph.oe_content_row.field_oe_title + - field.field.paragraph.oe_content_row.field_oe_content_row_layout - paragraphs.paragraphs_type.oe_content_row # Field types already included @@ -130,6 +133,9 @@ config_devel: # List item block layout - field.storage.paragraph.field_oe_list_item_block_layout + # Content row layout + - field.storage.paragraph.field_oe_content_row_layout + optional: # Paragraph multilingual configuration - language.content_settings.paragraph.oe_accordion From 98d5c718234726ebc1bda10a1f15265f5db5aab7 Mon Sep 17 00:00:00 2001 From: Mohammed Nassar Date: Fri, 9 Aug 2019 09:58:15 +0000 Subject: [PATCH 2/5] Issue #65: Add predefined list for content row layout field. --- ....paragraph.field_oe_content_row_layout.yml | 2 +- oe_paragraphs.module | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml index 51c20ad6..0384c639 100644 --- a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml +++ b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml @@ -10,7 +10,7 @@ entity_type: paragraph type: list_string settings: allowed_values: { } - allowed_values_function: '' + allowed_values_function: '_oe_paragraphs_allowed_values_content_row_column_layout' module: options locked: false cardinality: 1 diff --git a/oe_paragraphs.module b/oe_paragraphs.module index 0f5a17ba..33e10d73 100644 --- a/oe_paragraphs.module +++ b/oe_paragraphs.module @@ -8,7 +8,9 @@ declare(strict_types = 1); use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\Field\FieldStorageDefinitionInterface; /** * Implements hook_entity_base_field_info(). @@ -31,3 +33,27 @@ function oe_paragraphs_entity_base_field_info(EntityTypeInterface $entity_type): return $fields; } + +/** + * Set dynamic allowed values for the "Content row: Column layout". + * + * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition + * The field definition. + * @param \Drupal\Core\Entity\FieldableEntityInterface|null $entity + * The entity being created if applicable. + * @param bool $cacheable + * Boolean indicating if the results are cacheable. + * + * @return array + * An array of possible key and value options. + * + * @see options_allowed_values() + */ +function _oe_paragraphs_allowed_values_content_row_column_layout(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, $cacheable): array { + return [ + '2' => t('2 columns (equal width | 6-6)'), + '8-4' => t('2 columns (non-equal width | 8-4)'), + '3' => t('3 columns (equal width | 4-4-4)'), + '3-6-3' => t('3 columns (non-equal width | 3-6-3)'), + ]; +} From ef5842e663f2589b903e41d957fd3cb9cb59aba4 Mon Sep 17 00:00:00 2001 From: Mohammed Nassar Date: Fri, 9 Aug 2019 11:00:41 +0000 Subject: [PATCH 3/5] Issue #65: Allow developers to alter the allowed values for (Content row: Column layout). --- oe_paragraphs.api.php | 24 ++++++++++++++++++++++++ oe_paragraphs.module | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 oe_paragraphs.api.php diff --git a/oe_paragraphs.api.php b/oe_paragraphs.api.php new file mode 100644 index 00000000..dfbbff1d --- /dev/null +++ b/oe_paragraphs.api.php @@ -0,0 +1,24 @@ + t('2 columns (equal width | 6-6)'), + '6-3-3' => t('3 columns (non-equal width | 6-3-3)'), + '4' => t('4 columns (equal width | 3-3-3-3)'), + ]; +} diff --git a/oe_paragraphs.module b/oe_paragraphs.module index 33e10d73..b5026494 100644 --- a/oe_paragraphs.module +++ b/oe_paragraphs.module @@ -50,10 +50,13 @@ function oe_paragraphs_entity_base_field_info(EntityTypeInterface $entity_type): * @see options_allowed_values() */ function _oe_paragraphs_allowed_values_content_row_column_layout(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, $cacheable): array { - return [ + $allowed_values = [ '2' => t('2 columns (equal width | 6-6)'), '8-4' => t('2 columns (non-equal width | 8-4)'), '3' => t('3 columns (equal width | 4-4-4)'), '3-6-3' => t('3 columns (non-equal width | 3-6-3)'), ]; + + \Drupal::moduleHandler()->alter('oe_paragraphs_allowed_values_content_row_column_layout', $allowed_values); + return $allowed_values; } From 76d5a089f5394199579eaa6c13ca42f4b0908c16 Mon Sep 17 00:00:00 2001 From: Mohammed Nassar Date: Fri, 9 Aug 2019 11:10:30 +0000 Subject: [PATCH 4/5] Issue #65: Change form display settings for (content row: column layout). --- ...ntity_form_display.paragraph.oe_content_row.default.yml | 7 +------ ..._display.paragraph.oe_content_row.inpage_navigation.yml | 2 ++ ...field.storage.paragraph.field_oe_content_row_layout.yml | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml b/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml index 746cc3ae..79a25c55 100644 --- a/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml +++ b/config/install/core.entity_form_display.paragraph.oe_content_row.default.yml @@ -13,12 +13,6 @@ targetEntityType: paragraph bundle: oe_content_row mode: default content: - field_oe_content_row_layout: - weight: 1 - settings: { } - third_party_settings: { } - type: options_select - region: content field_oe_paragraphs: weight: 0 settings: @@ -40,6 +34,7 @@ content: region: content hidden: created: true + field_oe_content_row_layout: true field_oe_title: true status: true translation: true diff --git a/config/install/core.entity_form_display.paragraph.oe_content_row.inpage_navigation.yml b/config/install/core.entity_form_display.paragraph.oe_content_row.inpage_navigation.yml index e1ad1864..94d02c17 100644 --- a/config/install/core.entity_form_display.paragraph.oe_content_row.inpage_navigation.yml +++ b/config/install/core.entity_form_display.paragraph.oe_content_row.inpage_navigation.yml @@ -3,6 +3,7 @@ status: true dependencies: config: - core.entity_form_mode.paragraph.inpage_navigation + - field.field.paragraph.oe_content_row.field_oe_content_row_layout - field.field.paragraph.oe_content_row.field_oe_paragraphs - field.field.paragraph.oe_content_row.field_oe_title - paragraphs.paragraphs_type.oe_content_row @@ -42,6 +43,7 @@ content: third_party_settings: { } hidden: created: true + field_oe_content_row_layout: true status: true translation: true uid: true diff --git a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml index 0384c639..52b3839e 100644 --- a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml +++ b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml @@ -10,7 +10,7 @@ entity_type: paragraph type: list_string settings: allowed_values: { } - allowed_values_function: '_oe_paragraphs_allowed_values_content_row_column_layout' + allowed_values_function: _oe_paragraphs_allowed_values_content_row_column_layout module: options locked: false cardinality: 1 From c877da625a4a794ba7dda30882a275da982c2e24 Mon Sep 17 00:00:00 2001 From: Mohammed Nassar Date: Thu, 5 Sep 2019 09:47:21 +0000 Subject: [PATCH 5/5] Issue #65: Add upgrade path for column layout variant for content row type. --- oe_paragraphs.post_update.php | 55 +++++++++++++++++++ ...aragraph.oe_content_row.columns_layout.yml | 47 ++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 post_updates/00002_content_row_type_add_column_layout_variant/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml diff --git a/oe_paragraphs.post_update.php b/oe_paragraphs.post_update.php index c761d1f0..7c3112ae 100644 --- a/oe_paragraphs.post_update.php +++ b/oe_paragraphs.post_update.php @@ -7,7 +7,11 @@ declare(strict_types = 1); +use Drupal\Core\Config\FileStorage; +use Drupal\Core\Entity\Entity\EntityFormDisplay; +use Drupal\Core\Entity\Entity\EntityFormMode; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; /** * Fix description for limit field on contextual navigation paragraph. @@ -40,3 +44,54 @@ function oe_paragraphs_post_update_00001_make_oe_links_required_in_contextual_na $field->setSetting('title', 2); $field->save(); } + +/** + * Add new variant for the Content row type called "column Layout". + */ +function oe_paragraphs_post_update_00002_content_row_type_add_column_layout_variant() { + // Create the storage for the "layout" field. + if (!\Drupal::service('entity_type.manager')->getStorage('field_storage_config')->load('paragraph.field_oe_content_row_layout')) { + FieldStorageConfig::create([ + 'field_name' => 'field_oe_content_row_layout', + 'entity_type' => 'paragraph', + 'type' => 'list_string', + 'settings' => [ + 'allowed_values' => [], + 'allowed_values_function' => '_oe_paragraphs_allowed_values_content_row_column_layout', + ], + 'cardinality' => 1, + 'translatable' => TRUE, + ])->save(); + } + + // Create the "layout" field. + if (!\Drupal::service('entity_type.manager')->getStorage('field_config')->load('paragraph.oe_content_row.field_oe_content_row_layout')) { + FieldConfig::create([ + 'field_name' => 'field_oe_content_row_layout', + 'entity_type' => 'paragraph', + 'bundle' => 'oe_content_row', + 'label' => 'Layout', + 'description' => 'Column layout for displaying content items. If none selected, the content will be displayed in one column.', + 'required' => FALSE, + 'translatable' => FALSE, + 'settings' => [], + ])->save(); + } + + // Create new form mode (Columns layout). + if (!\Drupal::service('entity_type.manager')->getStorage('entity_form_mode')->load('paragraph.columns_layout')) { + EntityFormMode::create([ + 'id' => 'paragraph.columns_layout', + 'label' => 'Columns layout', + 'targetEntityType' => 'paragraph', + ])->save(); + } + + // Setup the form display. + $storage = new FileStorage(drupal_get_path('module', 'oe_paragraphs') . '/post_updates/00002_content_row_type_add_column_layout_variant'); + $form_display_values = $storage->read('core.entity_form_display.paragraph.oe_content_row.columns_layout'); + if (!EntityFormDisplay::load($form_display_values['id'])) { + $form_display = EntityFormDisplay::create($form_display_values); + $form_display->save(); + } +} diff --git a/post_updates/00002_content_row_type_add_column_layout_variant/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml b/post_updates/00002_content_row_type_add_column_layout_variant/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml new file mode 100644 index 00000000..bc0fdd67 --- /dev/null +++ b/post_updates/00002_content_row_type_add_column_layout_variant/core.entity_form_display.paragraph.oe_content_row.columns_layout.yml @@ -0,0 +1,47 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_form_mode.paragraph.columns_layout + - field.field.paragraph.oe_content_row.field_oe_content_row_layout + - field.field.paragraph.oe_content_row.field_oe_paragraphs + - field.field.paragraph.oe_content_row.field_oe_title + - paragraphs.paragraphs_type.oe_content_row + module: + - oe_paragraphs +id: paragraph.oe_content_row.columns_layout +targetEntityType: paragraph +bundle: oe_content_row +mode: columns_layout +content: + field_oe_content_row_layout: + type: options_select + weight: 0 + region: content + settings: { } + third_party_settings: { } + field_oe_paragraphs: + weight: 1 + settings: + title: Paragraph + title_plural: Paragraphs + edit_mode: closed + closed_mode: summary + autocollapse: none + closed_mode_threshold: 0 + add_mode: dropdown + form_display_mode: default + default_paragraph_type: _none + features: + duplicate: duplicate + collapse_edit_all: collapse_edit_all + add_above: '0' + third_party_settings: { } + type: oe_paragraphs_variants + region: content +hidden: + created: true + field_oe_title: true + status: true + translation: true + uid: true