Skip to content

Commit

Permalink
Issue #65: Add upgrade path for column layout variant for content row…
Browse files Browse the repository at this point in the history
… type.
  • Loading branch information
msnassar committed Sep 5, 2019
1 parent 76d5a08 commit c877da6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
55 changes: 55 additions & 0 deletions oe_paragraphs.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c877da6

Please sign in to comment.