I'm preprocessing a paragraph to add a custom form but I'm having trouble with the visibility. I don't need any fields on this paragraph.

If I just add the form to the paragraph the whole paragraph is hidden for anonymous users.

function my_module_preprocess_paragraph__my_paragraph(&$variables) {
  $paragraph = $variables['paragraph'];
  $form = \Drupal::formBuilder()->getForm('Drupal\my_module\Form\MyCustomForm');
  $variables['content']['form'] = $form;

However, if I add a title field to that paragraph everything shows up fine. Is there a way I can get the form to show without having to add fields?

  • You can use hook_field_widget_form_alter and hide the fields with #access FALSE Mar 30, 2020 at 16:12

1 Answer 1


Implement hook_field_widget_alter

It will give control of paragraph fields.

function hook_field_widget_entity_reference_paragraphs_form_alter(&$element, &$form_state, $context) {
  if ($element['#paragraph_type'] == 'xyz') {
    $element['subform']['field_name']['#access'] = FALSE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.