Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/paragraphs
  • issue/paragraphs-3182921
  • issue/paragraphs-3095945
  • issue/paragraphs-2919690
  • issue/paragraphs-3041810
  • issue/paragraphs-3145755
  • issue/paragraphs-2890086
  • issue/paragraphs-3199551
  • issue/paragraphs-2707017
  • issue/paragraphs-3204692
  • issue/paragraphs-3082703
  • issue/paragraphs-3213800
  • issue/paragraphs-3220321
  • issue/paragraphs-3228913
  • issue/paragraphs-3124166
  • issue/paragraphs-3231174
  • issue/paragraphs-3229807
  • issue/paragraphs-3231976
  • issue/paragraphs-3199042
  • issue/paragraphs-3233467
  • issue/paragraphs-2452675
  • issue/paragraphs-3157494
  • issue/paragraphs-3070010
  • issue/paragraphs-2877695
  • issue/paragraphs-3247490
  • issue/paragraphs-3247493
  • issue/paragraphs-3248381
  • issue/paragraphs-3248693
  • issue/paragraphs-3079782
  • issue/paragraphs-3251383
  • issue/paragraphs-3253843
  • issue/paragraphs-3255456
  • issue/paragraphs-2632580
  • issue/paragraphs-3256371
  • issue/paragraphs-3258236
  • issue/paragraphs-3175217
  • issue/paragraphs-3262157
  • issue/paragraphs-3262149
  • issue/paragraphs-3263415
  • issue/paragraphs-3047678
  • issue/paragraphs-3165793
  • issue/paragraphs-2912016
  • issue/paragraphs-3272251
  • issue/paragraphs-3130385
  • issue/paragraphs-3067265
  • issue/paragraphs-3105137
  • issue/paragraphs-3091424
  • issue/paragraphs-3036020
  • issue/paragraphs-2854585
  • issue/paragraphs-3293834
  • issue/paragraphs-3294257
  • issue/paragraphs-3227917
  • issue/paragraphs-3297813
  • issue/paragraphs-3042015
  • issue/paragraphs-3298786
  • issue/paragraphs-3299701
  • issue/paragraphs-3113257
  • issue/paragraphs-3293677
  • issue/paragraphs-2879370
  • issue/paragraphs-3301655
  • issue/paragraphs-2877942
  • issue/paragraphs-3253545
  • issue/paragraphs-3246140
  • issue/paragraphs-3306562
  • issue/paragraphs-3306140
  • issue/paragraphs-2949412
  • issue/paragraphs-2855735
  • issue/paragraphs-3030041
  • issue/paragraphs-3312044
  • issue/paragraphs-3291266
  • issue/paragraphs-3128512
  • issue/paragraphs-2940988
  • issue/paragraphs-3334005
  • issue/paragraphs-3307481
  • issue/paragraphs-3345730
  • issue/paragraphs-3333974
  • issue/paragraphs-3331203
  • issue/paragraphs-3345127
  • issue/paragraphs-3340697
  • issue/paragraphs-3340086
  • issue/paragraphs-3340409
  • issue/paragraphs-3340724
  • issue/paragraphs-3332030
  • issue/paragraphs-3344291
  • issue/paragraphs-3350885
  • issue/paragraphs-2833934
  • issue/paragraphs-3348733
  • issue/paragraphs-3350210
  • issue/paragraphs-2854168
  • issue/paragraphs-3352059
  • issue/paragraphs-3350698
  • issue/paragraphs-3354666
  • issue/paragraphs-3099024
  • issue/paragraphs-3359321
  • issue/paragraphs-3362358
  • issue/paragraphs-3363389
  • issue/paragraphs-3364116
  • issue/paragraphs-3120718
  • issue/paragraphs-3368107
  • issue/paragraphs-2879350
  • issue/paragraphs-3202543
  • issue/paragraphs-3374050
  • issue/paragraphs-3374442
  • issue/paragraphs-3376790
  • issue/paragraphs-3376909
  • issue/paragraphs-3372741
  • issue/paragraphs-3337935
  • issue/paragraphs-3350747
  • issue/paragraphs-3385177
  • issue/paragraphs-3384394
  • issue/paragraphs-3217028
  • issue/paragraphs-3392929
  • issue/paragraphs-3376124
  • issue/paragraphs-3386740
  • issue/paragraphs-2911244
  • issue/paragraphs-3407931
  • issue/paragraphs-3408482
  • issue/paragraphs-3238515
  • issue/paragraphs-3411311
  • issue/paragraphs-3408818
  • issue/paragraphs-3414495
  • issue/paragraphs-3043559
  • issue/paragraphs-3415034
  • issue/paragraphs-3037708
  • issue/paragraphs-3417771
  • issue/paragraphs-3414855
  • issue/paragraphs-3097493
  • issue/paragraphs-2994660
  • issue/paragraphs-3422082
  • issue/paragraphs-3422917
  • issue/paragraphs-3310161
  • issue/paragraphs-3084200
  • issue/paragraphs-3375722
  • issue/paragraphs-3424471
  • issue/paragraphs-3072058
  • issue/paragraphs-3443457
  • issue/paragraphs-2938017
  • issue/paragraphs-3321404
  • issue/paragraphs-3444596
  • issue/paragraphs-3444598
  • issue/paragraphs-2990527
  • issue/paragraphs-3318730
  • issue/paragraphs-3424486
  • issue/paragraphs-3433032
  • issue/paragraphs-3437549
  • issue/paragraphs-2744835
  • issue/paragraphs-3445936
  • issue/paragraphs-3433816
  • issue/paragraphs-3444580
  • issue/paragraphs-2977853
  • issue/paragraphs-3451313
  • issue/paragraphs-3452997
  • issue/paragraphs-3453956
  • issue/paragraphs-3454273
  • issue/paragraphs-3177867
  • issue/paragraphs-3454863
  • issue/paragraphs-3455402
  • issue/paragraphs-3458306
  • issue/paragraphs-3459850
  • issue/paragraphs-3419799
  • issue/paragraphs-3461066
  • issue/paragraphs-3462555
  • issue/paragraphs-3462547
  • issue/paragraphs-3350521
  • issue/paragraphs-3090101
  • issue/paragraphs-3027525
  • issue/paragraphs-3194151
  • issue/paragraphs-3405515
  • issue/paragraphs-3467124
  • issue/paragraphs-2925533
  • issue/paragraphs-2770243
  • issue/paragraphs-3469454
  • issue/paragraphs-3469830
  • issue/paragraphs-3425503
  • issue/paragraphs-3470569
  • issue/paragraphs-3471069
  • issue/paragraphs-3090200
  • issue/paragraphs-3056358
  • issue/paragraphs-3315835
  • issue/paragraphs-3472388
  • issue/paragraphs-3472439
  • issue/paragraphs-2854867
  • issue/paragraphs-3473001
  • issue/paragraphs-3473771
  • issue/paragraphs-3418303
  • issue/paragraphs-3482159
  • issue/paragraphs-3495877
  • issue/paragraphs-3495866
  • issue/paragraphs-3466304
  • issue/paragraphs-3484510
  • issue/paragraphs-2904705
  • issue/paragraphs-3485869
  • issue/paragraphs-3198881
  • issue/paragraphs-3486454
  • issue/paragraphs-3486479
  • issue/paragraphs-3485210
  • issue/paragraphs-3489564
  • issue/paragraphs-3492349
  • issue/paragraphs-3492419
  • issue/paragraphs-2867238
  • issue/paragraphs-3493679
  • issue/paragraphs-3495373
  • issue/paragraphs-3472308
  • issue/paragraphs-3493700
  • issue/paragraphs-3500649
  • issue/paragraphs-3500847
  • issue/paragraphs-2884131
  • issue/paragraphs-3501591
  • issue/paragraphs-3508702
  • issue/paragraphs-3508707
  • issue/paragraphs-3455925
  • issue/paragraphs-2868252
  • issue/paragraphs-3509430
  • issue/paragraphs-3244433
  • issue/paragraphs-3510842
215 results
Show changes
Commits on Source (44)
Showing
with 388 additions and 25 deletions
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
# EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below.
# - '/includes/include.drupalci.main-d7.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
variables:
KUBERNETES_CPU_REQUEST: "8"
_CONCURRENCY_THREADS: 16
_PHPUNIT_CONCURRENT: '1'
OPT_IN_TEST_PREVIOUS_MAJOR: 1
OPT_IN_TEST_PREVIOUS_MINOR: 1
phpcs:
before_script:
- cp $_WEB_ROOT/core/phpcs.xml.dist ./core.phpcs.xml.dist
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
......@@ -6,7 +6,7 @@
width: auto;
}
.js .field--widget-entity-reference-paragraphs .dropbutton-widget {
.js .field--widget-entity-reference-paragraphs div div .dropbutton-widget {
position: relative;
}
......
.field-icon-field-uientity-reference-revisionsparagraph {
background-image: url(../icons/paragraphs.svg);
}
.field-icon-field-uientity-reference-revisionsparagraph {
background-image: url(../icons/paragraphs.svg);
}
......@@ -168,18 +168,21 @@
margin-right: -11px;
}
.js .field--widget-paragraphs .form-actions {
.js .field--widget-paragraphs .form-actions,
.js .field--widget-paragraphs .field-actions {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.js .field--widget-paragraphs .form-actions .dropbutton-multiple {
.js .field--widget-paragraphs .form-actions .dropbutton-multiple,
.js .field--widget-paragraphs .field-actions .dropbutton-multiple {
margin-right: .5rem;
}
.js .field--widget-paragraphs .form-actions .placeholder {
.js .field--widget-paragraphs .form-actions .placeholder,
.js .field--widget-paragraphs .field-actions .placeholder {
margin-left: .25em;
}
......@@ -193,7 +196,7 @@
}
.js .field--widget-paragraphs .paragraphs-dropbutton-wrapper .dropbutton-multiple {
margin: 0;
margin: 0 .5rem 0 0;
}
.js .field--widget-paragraphs .dropbutton-wrapper {
......@@ -220,6 +223,7 @@
margin-top: 3px;
padding-right: .25em;
width: 23px;
vertical-align: baseline;
}
.js .field--widget-paragraphs .draggable .tabledrag-handle:focus::before {
......@@ -230,6 +234,7 @@
.js .field--widget-paragraphs .draggable .tabledrag-handle::after {
margin-left: 0;
padding: .5rem;
margin-top: 0.9375rem;
}
.js .field--widget-paragraphs .draggable .tabledrag-handle:hover .handle {
......@@ -394,6 +399,10 @@ tr:hover .paragraphs-description::after {
background: #057ec7 none;
}
.js .paragraphs-convert-button {
margin-left: 0;
}
.paragraphs-dragdrop__item .paragraphs-summary-wrapper .paragraphs-description .paragraphs-content-wrapper,
.paragraphs-dragdrop__item .paragraphs-summary-wrapper .paragraphs-description .paragraphs-plugin-wrapper {
font-size: 81.3%;
......
......@@ -96,8 +96,9 @@
margin-right: -11px;
}
// Fix alignment of form-actions.
.form-actions {
// Fix alignment of field-actions / form-actions.
.form-actions,
.field-actions {
align-items: center;
// Fix alignment to content.
......@@ -120,7 +121,7 @@
padding: 0;
.dropbutton-multiple {
margin: 0;
margin: 0 .5rem 0 0;
}
}
......@@ -152,6 +153,7 @@
margin-top: 3px;
padding-right: .25em;
width: 23px;
vertical-align: baseline;
// Fix active focus.
&:focus {
......@@ -165,6 +167,7 @@
&::after {
margin-left: 0;
padding: .5rem;
margin-top: 0.9375rem;
}
// Scale the icon on hover.
......@@ -309,6 +312,10 @@
color: #ffffff;
background: #057ec7 none;
}
.paragraphs-convert-button {
margin-left: 0;
}
}
.paragraphs-dragdrop__item {
......
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="none"><path fill="#55565B" fill-rule="evenodd" d="M21.105 2.6c3.925.002 7.128 3.19 7.128 7.106 0 3.894-3.168 7.063-7.064 7.099l-.48.004-1.124.008c-.654.003-1.379.004-1.893-.002v15.532a1.038 1.038 0 0 1-.642.972 1.047 1.047 0 0 1-1.37-.572 1.038 1.038 0 0 1-.076-.4v-16.46a1.04 1.04 0 0 1 0-.243V4.696h-2.386v27.65a1.04 1.04 0 0 1-1.044 1.054 1.047 1.047 0 0 1-.969-.653 1.04 1.04 0 0 1-.075-.4V4.697H7.685a1.047 1.047 0 0 1-1.084-.99 1.04 1.04 0 0 1 .992-1.093M21.105 2.6c-2.896-.044-5.802-.025-8.702-.007-1.575.01-3.149.02-4.718.02a1.048 1.048 0 0 0-.092 0m13.662 2.074c-.052.007-.104.01-.157.01h-3.426v10.028h3.43c2.791 0 5.043-2.242 5.043-5.02a5.025 5.025 0 0 0-4.89-5.018Z" clip-rule="evenodd"/></svg>
\ No newline at end of file
......@@ -29,8 +29,12 @@
// Find delta for row without interference of unrelated table rows.
var $anchorRow = $button.closest('tr');
var delta = $anchorRow.parent().find('> .draggable').index($anchorRow);
// If the form table has a layout wrapper use that (see claro / gin).
var $table = $button.closest('.field-multiple-table');
var $layer_wrapper = $table.closest('.layer-wrapper');
$table = $layer_wrapper.length > 0 ? $layer_wrapper : $table;
// We need the siblings function to avoid finding the 'Add paragraph' button inside a container.
var $add_more_wrapper = $button.closest('.field-multiple-table').siblings('.clearfix,.form-actions').find('.paragraphs-add-wrapper');
var $add_more_wrapper = $table.siblings('.clearfix,.form-actions,.multiple-value-form-actions,.field-actions').find('.paragraphs-add-wrapper');
// Set delta before opening of dialog.
$add_more_wrapper.find('.paragraph-type-add-delta').val(delta);
......@@ -55,7 +59,11 @@
var $actions = $(this);
if ($actions.closest('.paragraph-top').hasClass('add-above-on')) {
var $add_above = false;
var $add_more_wrapper = $actions.closest('.field-multiple-table').siblings('.clearfix,.form-actions').find('.paragraphs-add-wrapper');
// If the form table has a layout wrapper use that (see claro / gin).
var $table = $actions.closest('.field-multiple-table');
var $layer_wrapper = $table.closest('.layer-wrapper');
$table = $layer_wrapper.length > 0 ? $layer_wrapper : $table;
var $add_more_wrapper = $table.siblings('.clearfix,.form-actions,.multiple-value-form-actions,.field-actions').find('.paragraphs-add-wrapper');
// The Add Above button is added when the add mode is modal or when
// there is only one add button in the other add modes.
if ($add_more_wrapper.find('.paragraph-type-add-delta').hasClass('modal') || $add_more_wrapper.find('.field-add-more-submit').length === 1) {
......
......@@ -55,8 +55,7 @@
$element = $element.clone(true);
var dialog = Drupal.dialog($element, {
// Turn off autoResize from dialog.position so draggable is not disabled.
autoResize: false,
autoResize: true,
resizable: false,
title: title,
width: 'auto',
......
logo.png

2.81 KiB

......@@ -33,7 +33,11 @@ content:
edit_mode: closed
add_mode: dropdown
form_display_mode: default
default_paragraph_type: ''
features:
duplicate: duplicate
collapse_edit_all: collapse_edit_all
convert: convert
add_above: '0'
third_party_settings: { }
langcode:
type: language_select
......
description: 'Provides multilingual demo Paragraphs types.'
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^10.2 || ^11
dependencies:
- paragraphs:paragraphs
- drupal:field
......
<?php
namespace Drupal\paragraphs_demo\Plugin\paragraphs\Conversion;
use Drupal\Core\Form\FormStateInterface;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs\ParagraphsConversionBase;
/**
* Provides a Paragraphs conversion plugin.
*
* @ParagraphsConversion(
* id = "paragraphs_demo_user_to_text",
* label = @Translation("Convert to Text"),
* source_type = "user",
* target_types = {"text"},
* weight = 0
* )
*/
class ParagraphsDemoUserText extends ParagraphsConversionBase {
/**
* {@inheritdoc}
*/
public function convert(array $settings, ParagraphInterface $original_paragraph, array $converted_paragraphs = NULL) {
$username = "Empty user field";
if ($original_paragraph->get('field_user_demo')->entity) {
$username = $original_paragraph->get('field_user_demo')->entity->label();
}
$converted_paragraphs = [
[
'type' => 'text',
'field_text_demo' => [
'value' => $username,
],
],
];
if ($settings['multiple']) {
$converted_paragraphs[] = [
'type' => 'text',
'field_text_demo' => [
'value' => $username,
],
];
}
return $converted_paragraphs;
}
/**
* {@inheritdoc}
*/
public function buildConversionForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
$form = [];
$form['multiple'] = [
'#type' => 'checkbox',
'#title' => $this->t('Multiple'),
'#description' => $this->t('If selected the conversion will return two paragraphs.'),
];
return $form;
}
}
<?php
namespace Drupal\paragraphs_demo\Plugin\paragraphs\Conversion;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs\ParagraphsConversionBase;
/**
* Provides a Paragraphs conversion plugin.
*
* @ParagraphsConversion(
* id = "paragraphs_demo_user_to_text_user",
* label = @Translation("Convert to Text and User"),
* source_type = "user",
* target_types = {"text", "user"},
* weight = 0
* )
*/
class ParagraphsDemoUserToTextUser extends ParagraphsConversionBase {
/**
* {@inheritdoc}
*/
public function convert(array $settings, ParagraphInterface $original_paragraph, array $converted_paragraphs = NULL) {
$username = "Empty user field";
$user = NULL;
if ($original_paragraph->get('field_user_demo')->entity) {
$username = $original_paragraph->get('field_user_demo')->entity->label();
$user = $original_paragraph->get('field_user_demo')->entity;
}
return [
[
'type' => 'text',
'field_text_demo' => [
'value' => $username,
],
],
[
'type' => 'user',
'field_user_demo' => $user ?: NULL,
],
];
}
}
langcode: en
status: true
dependencies: { }
dependencies:
enforced:
module:
- paragraphs_library
id: from_library
label: 'From library'
behavior_plugins: { }
name: Paragraphs Library
type: module
description: 'Provides a library for reusing paragraphs.'
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^10.2 || ^11
package: Paragraphs
configure: paragraphs_library_item.settings
dependencies:
......
......@@ -370,3 +370,19 @@ function paragraphs_library_update_8102() {
->save();
}
}
/**
* Add the paragraphs_library module as dependency to the from_library paragraphs type.
*/
function paragraphs_library_update_8103() {
$config = \Drupal::configFactory()->getEditable('paragraphs.paragraphs_type.from_library');
if ($config->isNew()) {
return;
}
$dependencies = $config->get('dependencies') ?? [];
$dependencies['enforced']['module'][] = 'paragraphs_library';
$config->set('dependencies', $dependencies);
$config->save();
}
......@@ -196,7 +196,7 @@ function paragraphs_library_form_paragraphs_type_form_alter(&$form, FormStateInt
if ($paragraph_type->id() != 'from_library') {
$form['allow_library_conversion'] = [
'#type' => 'checkbox',
'#title' => t('Allow adding to library'),
'#title' => t('Allow promoting to library'),
'#default_value' => $paragraph_type->getThirdPartySetting('paragraphs_library', 'allow_library_conversion', FALSE),
];
$form['#entity_builders'][] = 'paragraphs_library_form_paragraphs_type_form_builder';
......@@ -207,7 +207,7 @@ function paragraphs_library_form_paragraphs_type_form_alter(&$form, FormStateInt
/**
* Entity builder for the paragraphs type form with group property.
*
* @see primer_base_form_paragraphs_type_form_alter()
* @see paragraphs_library_form_paragraphs_type_form_alter()
*/
function paragraphs_library_form_paragraphs_type_form_builder($entity_type, ParagraphsTypeInterface $type, &$form, FormStateInterface $form_state) {
if ($form_state->getValue('allow_library_conversion')) {
......
......@@ -4,12 +4,55 @@ namespace Drupal\paragraphs_library\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface;
/**
* Form for Paragraphs library item settings.
*/
class LibraryItemSettingsForm extends ConfigFormBase {
/**
* The entity reference selection plugin manager.
*
* @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface
*/
protected $pluginManagerEntityReferenceSelection;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Constructs a new LibraryItemBaseParagraphOverrideForm object.
*
* @param \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $plugin_manager_entity_reference_selection
* The selection plugin manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(
SelectionPluginManagerInterface $plugin_manager_entity_reference_selection,
EntityFieldManagerInterface $entity_field_manager
) {
$this->entityFieldManager = $entity_field_manager;
$this->pluginManagerEntityReferenceSelection = $plugin_manager_entity_reference_selection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.entity_reference_selection'),
$container->get('entity_field.manager')
);
}
/**
* {@inheritdoc}
*/
......@@ -28,11 +71,64 @@ class LibraryItemSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// This exists to make the field UI pages visible and must not be removed.
$form['account'] = array(
'#markup' => '<p>' . $this->t('There are no settings yet.') . '</p>',
);
$paragraph_selection_handler = $this->getParagraphSelectionHandler();
return $form;
// Set the form state to match the existing paragraph selection handler
// settings.
$fields = $this->entityFieldManager->getFieldDefinitions('paragraphs_library_item', 'paragraphs_library_item');
$settings = $fields['paragraphs']->getConfig('paragraphs_library_item')->getSettings();
if (!empty($settings['handler_settings'])) {
// Since we are building a handler's form, have to move handler settings
// up to the same level as the rest of the config.
$handler_settings = $settings['handler_settings'];
unset($settings['handler_settings']);
$settings = array_merge($settings, $handler_settings);
$paragraph_selection_handler->setConfiguration($settings);
}
// Build this form using the ParagraphsSelection form.
$form = $paragraph_selection_handler->buildConfigurationForm($form, $form_state);
return parent::buildForm($form, $form_state);
}
/**
* Get an instance of the paragraph selection handler.
*
* @return false|\Drupal\paragraphs\Plugin\EntityReferenceSelection\ParagraphSelection
* The paragraph selection handler.
*/
protected function getParagraphSelectionHandler() {
// Get an instance of the ParagraphsSelection handler.
$options = [
'target_type' => 'paragraph',
'handler' => 'default:paragraph',
];
return $this->pluginManagerEntityReferenceSelection->getInstance($options);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get only the values related to the paragraph selection handler form.
$values = $form_state->getValues();
$paragraph_selection_handler = $this->getParagraphSelectionHandler();
$paragraph_selection_form = $paragraph_selection_handler->buildConfigurationForm([], $form_state);
$paragraph_selection_form_values = array_intersect_key($values, $paragraph_selection_form);
// Get existing paragraphs selection settings.
$fields = $this->entityFieldManager->getFieldDefinitions('paragraphs_library_item', 'paragraphs_library_item');
$paragraphs_config = $fields['paragraphs']->getConfig('paragraphs_library_item');
$settings = $paragraphs_config->getSettings();
// Save the new handler settings.
$settings['handler_settings'] = $paragraph_selection_form_values;
$settings['handler'] = 'default:paragraph';
$paragraphs_config->setSettings($settings)->save();
$this->entityFieldManager->clearCachedFieldDefinitions();
}
}