Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Published status of paragraph is lost when cloning a node with paragraphs #200

Open
stpaultim opened this issue Jan 17, 2025 · 4 comments · May be fixed by #201
Open

Published status of paragraph is lost when cloning a node with paragraphs #200

stpaultim opened this issue Jan 17, 2025 · 4 comments · May be fixed by #201

Comments

@stpaultim
Copy link
Member

stpaultim commented Jan 17, 2025

I'm not sure if this is a problem with paragraphs, node clone, or if it's necessarily a bug at all. But, my client is asking if there is a way to fix this.

  1. Enable and configure a site with paragraphs and node clone modules.
  2. Create an article with multiple paragraphs
  3. Unpublish one of the paragraphs on the node
  4. Clone the node
  5. Note that the unpublished paragraph on the original node is now published on the new node.

My client would prefer that the original status of each paragraph is respected on the new node.

QUESTION:

Any thoughts on whether the responsibility for this lies with Node Clone or Paragraphs?

Does this seem like a reasonable issue to fix?

@laryn
Copy link
Member

laryn commented Jan 17, 2025

It's probably in here:

And it's probably not been looked at since unpublishing Paragraphs was added. Yes, it should be fixed. 👍 Are you able to start looking into it?

I also probably need to verify with Replicate UI and Replicate Paragraphs that this is working as expected. I don't know off-hand...

@stpaultim
Copy link
Member Author

@laryn Yes, we'll take a look and see if we can figure something out and potentially offer a PR. Otherwise, we'll let you know.

@sudipto68
Copy link

sudipto68 commented Jan 20, 2025

@laryn Thanks for pointing us to the issue. I have managed to fix this by adding this( $new_item->status = $old_item->status ) line on the paragraphs_clone_items function. In my initial test it is working for me, can you please test this more and if you think, it is ok then I can submit a PR for this.
Here is the updated code for that function.

foreach ($old_items as $old_item) {
    list(, , $bundle) = entity_extract_ids('paragraphs_item', $old_item);

    /* @var $new_item ParagraphsItemEntity */
    $new_item = entity_create('paragraphs_item', array('bundle' => $bundle, 'field_name' => $field_name));
    $new_item->setHostEntity($entity_type, $entity, $langcode);

    $new_item->status = $old_item->status; // this is the new changes line for cloning node issue

    // Check if any of the fields in the newly cloned fc item is a paragraph.
    foreach (field_info_instances('paragraphs_item', $bundle) as $new_field_name => $new_field_instance) {
      if (!empty($old_item->{$new_field_name})) {
        $new_item->{$new_field_name} = $old_item->{$new_field_name};
        $field_info = field_info_field($new_field_name);
        if ($field_info['type'] == 'paragraphs') {
          paragraphs_clone_items('paragraphs_item', $new_item, $new_field_name, $langcode);
        }
      }
    }
  }

@sudipto68
Copy link

@laryn I have added a PR for this issue. Can you please check this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants