Programmatically create a paragraph entity reference field I need to create a config page, that is able to add social media information ( name and icon ), the user must be able to add as many social medias as it wants. To do so, I'we created a paragraph with two fields: name &amp; icon, then I want to add this paragraph as an entity reference field programmaticaly in my config page, the paragraph machine name is social_media.

I tried this, but it didn't work: 

public function buildForm(array $form, FormStateInterface $form_state) {

    $form['social_media_fieldset'] = [
      '#type' =&gt; 'fieldset',
      '#title' =&gt; $this-&gt;t('Social Media Configuration'),
      '#collapsible' =&gt; TRUE,
      '#collapsed' =&gt; FALSE,
    ];

    $field = BaseFieldDefinition::create('entity_reference')
      -&gt;setLabel(t('Type'))
      -&gt;setDescription(t('The Paragraphs type.'))
      -&gt;setSetting('target_type', 'paragraph')
      -&gt;setSetting('handler', 'default')
      -&gt;setSetting('handler_settings',['target_bundles'=&gt;
                      ['social_media'=&gt;'social_media']
          ]);

    $form['social_media'] = $field;

    return parent::buildForm($form, $form_state);
  }


the page is shown but without a form:
The following code did the trick for me when adding the field to custom entity. This provides a reference to the paragraph and the revision. Just to note out that when the paragraph is edited, the reference field will still refer to the old revision. The field type is entity_reference_revisions and my paragraph type 

$fields['social_media_id'] = BaseFieldDefinition::create('entity_reference_revisions')
  -&gt;setLabel(t('Skill'))
  -&gt;setDescription(t('The ID of the skill'))
  -&gt;setRevisionable(TRUE)
  -&gt;setSetting('handler', 'default:paragraph')
  -&gt;setSetting('handler_settings', ['target_bundles' =&gt; ['social_media' =&gt; 'social_media']])
  -&gt;setSetting('handler_settings', ['negate' =&gt; 0])
  -&gt;setTranslatable(TRUE)
  -&gt;setDisplayOptions('form', [
    'type' =&gt; 'entity_reference_autocomplete',
    'weight' =&gt; 5,
    'settings' =&gt; [
      'match_operator' =&gt; 'CONTAINS',
      'size' =&gt; '60',
      'autocomplete_type' =&gt; 'tags',
      'placeholder' =&gt; '',
    ],
  ])
  -&gt;setDisplayConfigurable('form', TRUE);