How to delete paragraph items programmatically

Created on 6 October 2020, over 3 years ago
Updated 16 November 2023, 7 months ago

Problem/Motivation

I created a paragraph item programmatically with host user profile. I used this to help me: https://www.drupal.org/project/paragraphs/issues/2395131 β†’ .
Now I need to delete it. But when I retrieve my paragraph item like so:
$metadata_paragraph = entity_metadata_wrapper('paragraphs_item', $paragraph->getIdentifier());

and then I try this:
$metadata_paragraph->delete();

The paragraph does not show anymore on the user profile, so that's good. But now there is an empty field on the user profile (not the worst part). And on top of that I still see the value of the paragraph on the user profile. In other words, the paragraph item has been emptied, but not actually removed from the host.
How do I remove the item from the host without removing the other paragraph items from the host?
Is there an easy way to do this? I feel like this should have been a part of the $metadata_paragraph->delete(); functionality.

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands colorfulCoder

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia jannakha Brisbane!

    please provide more details
    or indicate if this issue can be closed

  • πŸ‡³πŸ‡±Netherlands colorfulCoder

    I have not worked with Drupal for over 2 years by now so I could not tell you how to reproduce this if I wanted to.
    I sugges to close this issue, but only if users can see this after closing it. Because my solution might help some people with the same issue.

Production build 0.69.0 2024