1

Is there a way, to set new Paragraphs to unpublished per Default?

For Content Types, I can set that new Nodes are not published per Default (Structure -> Content types -> Tab 'Edit' -> Widget 'Publishing options' -> Group 'Default options'. Is there a way to enable the same behaviour for paragraphs?

I use Drupal 9.5.9 and Paragraph 8.x-1.15

If I add a new paragraph to a page, I don't want it to be published. I can unpublish it manually, yes, but I as the Page is multilingual, this leads to a problem: I would like to have the Published-Field translated, so that a Paragraph is published in one language but not in another. If I have to unpublish manually, only the paragraph in the default language (where I added it) gets unpublished, but in all translations it is still published. Therefor I have to unpublish the same paragraph in all translated languages as well, which is a) tedious b) prone to errors and c) has them published in an not yet edited state for some time until I get to this language.

This is why I currently have the publish-field not translated, which is not my desired configuration. I insert the new paragraph, set it to unpublished, edit all its translations and then publish all translations at once. If newly inserted paragraphs would be unpublished per Default, this would solve my problem.

When editing Paragraph Types, there is no Publishing-Options-Widget as on Content Types. I could not find any relevant configuration for Paragraph Module, no setting on the 'Paragraphs (stable)'-Widget on the encompassing Content Types 'Manage Form Display'.

Thanks a lot for any hint... Kind regards, mullzk

1 Answer 1

2

As I could not find any other way, i made my own small module with just one hook:

<?php
use Drupal\Core\Entity\EntityPublishedInterface;

function paragraph_default_status_paragraph_create(\Drupal\Core\Entity\EntityInterface $entity) {    
  if ($entity instanceof EntityPublishedInterface) {
    $entity->setUnpublished();
  }
}

This of course depends on the 'published'-field be enabled in the manage-form-display of all paragraphs, otherwise they will remain unpublished for all eternity :)

1
  • You should also follow Drupal's coding standards and add a docblock comment with Implements hook_ENTITY_TYPE_create() for paragraph entities. Search the Drupal codebase for hook_ENTITY_TYPE_create() to see examples. See Drupal coding standards
    – mbomb007
    Sep 4 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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