From 53ff1c3cc62458546744dede07c735196009ef8c Mon Sep 17 00:00:00 2001
From: gthibert <gthibert@3621448.no-reply.drupal.org>
Date: Fri, 24 Apr 2020 15:54:11 -0400
Subject: [PATCH 1/1] Added allow_entity_reference_field config option

---
 paragraphs.module                   | 5 ++++-
 src/Form/ParagraphsSettingsForm.php | 7 +++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/paragraphs.module b/paragraphs.module
index a8563ad..6902adb 100644
--- a/paragraphs.module
+++ b/paragraphs.module
@@ -122,8 +122,11 @@ function paragraphs_form_entity_form_display_edit_form_alter(&$form, \Drupal\Cor
  */
 function paragraphs_form_field_storage_config_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
   if ($form_state->getFormObject()->getEntity()->getType() == 'entity_reference') {
+    $config = \Drupal::config('paragraphs.settings');
+    if (!$config->get('allow_entity_reference_field')){
     // Entity Reference fields are no longer supported to reference Paragraphs.
-    unset($form['settings']['target_type']['#options'][(string) t('Content')]['paragraph']);
+      unset($form['settings']['target_type']['#options'][(string) t('Content')]['paragraph']);
+    }
   }
 }
 
diff --git a/src/Form/ParagraphsSettingsForm.php b/src/Form/ParagraphsSettingsForm.php
index 1d7da4c..a09b43e 100644
--- a/src/Form/ParagraphsSettingsForm.php
+++ b/src/Form/ParagraphsSettingsForm.php
@@ -35,6 +35,12 @@ class ParagraphsSettingsForm extends ConfigFormBase {
       '#default_value' => $config->get('show_unpublished'),
       '#description' => $this->t('Allow users with "View unpublished paragraphs" permission to see unpublished Paragraphs.')
     ];
+    $form['allow_entity_reference_field'] = [
+      '#type' => 'checkbox',
+      '#title' => $this->t('Allow Entity Reference fields'),
+      '#default_value' => $config->get('allow_entity_reference_field'),
+      '#description' => $this->t('Allow the usage of Entity Reference fields to refer to Paragraphs.')
+    ];
 
     return parent::buildForm($form, $form_state);
   }
@@ -45,6 +51,7 @@ class ParagraphsSettingsForm extends ConfigFormBase {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $config = $this->config('paragraphs.settings');
     $config->set('show_unpublished', $form_state->getValue('show_unpublished'));
+    $config->set('allow_entity_reference_field', $form_state->getValue('allow_entity_reference_field'));
     $config->save();
 
     parent::submitForm($form, $form_state);
-- 
2.26.0.windows.1

