Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Can we check and see if the entity should be deleted please?
Say you have an Event entity and you want to prevent them from being deleted if there are already sessions scheduled or something. I propose we add a canBeDeleted() method. Our placeholder method would just return TRUE, but entities could override it with something like
/**
* {@inheritdoc}
*/
public function canBeDeleted() {
$messenger = \Drupal::messenger();
if (!empty($this->getSessions())) {
$messenger->addMessage('I\'m sorry. I can\'t delete events which already have sessions.', 'error');
return FALSE;
}
return TRUE;
}
Comment | File | Size | Author |
---|---|---|---|
entity_delete_op-can-delete.patch | 2.87 KB | Tim Bozeman |
Comments
Comment #3
Tim Bozeman CreditAttribution: Tim Bozeman at CyberSolution for Tag1 Consulting commentedWow! What a great idea! Thanks!
Comment #4
Tim Bozeman CreditAttribution: Tim Bozeman at CyberSolution for Tag1 Consulting commentedComment #5
Tim Bozeman CreditAttribution: Tim Bozeman at CyberSolution for Tag1 Consulting commented