Created
July 26, 2024 13:02
-
-
Save isalmanhaider/41649e279442cd355229fce2db6f7c89 to your computer and use it in GitHub Desktop.
delete node from content and group_content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\Core\DrupalKernel; | |
use Symfony\Component\HttpFoundation\Request; | |
use Drupal\node\Entity\Node; | |
// Bootstrap Drupal. | |
$autoloader = require_once __DIR__ . '/vendor/autoload.php'; | |
$kernel = DrupalKernel::createFromRequest(Request::createFromGlobals(), $autoloader, 'prod'); | |
$kernel->boot(); | |
// Node ID to delete. | |
$nid = 292921; // Replace with your actual node ID | |
// Load the node. | |
$node = Node::load($nid); | |
if ($node) { | |
// Delete group content associated with the node. | |
$group_contents = \Drupal::entityTypeManager() | |
->getStorage('group_content') | |
->loadByProperties(['entity_id' => $nid]); | |
foreach ($group_contents as $group_content) { | |
$group_content->delete(); | |
} | |
// Delete the node. | |
$node->delete(); | |
echo "Node with ID $nid and its group content have been deleted.\n"; | |
} else { | |
echo "Node with ID $nid does not exist.\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
drush scr delete_node.php