Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 65 | Add new variant for the Content row type called "column Layout" #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,6 +34,7 @@ content:
region: content
hidden:
created: true
field_oe_content_row_layout: true
field_oe_title: true
status: true
translation: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,6 +43,7 @@ content:
third_party_settings: { }
hidden:
created: true
field_oe_content_row_layout: true
status: true
translation: true
uid: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies:
module:
- paragraphs
id: paragraph.columns_layout
label: 'Columns layout'
targetEntityType: paragraph
cache: true
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: _oe_paragraphs_allowed_values_content_row_column_layout
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
24 changes: 24 additions & 0 deletions oe_paragraphs.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @file
* Hooks for the OE Paragraphs module.
*/

declare(strict_types = 1);

/**
* Alters the allowed values for "Content row: Column layout".
*
* @param array $allowed_values
* Array of possible key and value options.
*
* @see _oe_paragraphs_allowed_values_content_row_column_layout()
*/
function hook_oe_paragraphs_allowed_values_content_row_column_layout_alter(array &$allowed_values) {
$allowed_values = [
'2' => 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)'),
];
}
6 changes: 6 additions & 0 deletions oe_paragraphs.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions oe_paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -31,3 +33,30 @@ 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 {
$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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that better have validation of data provided by other modules.

return $allowed_values;
}
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