0

I'm unable to delete a custom entity. I'm getting the following error

$storage_handler = \Drupal::entityTypeManager()->getStorage("notification_storage");
$notification_entities = $storage_handler->loadMultiple($notifications['notification']);
$storage_handler->delete($notification_entities);

Symfony\Component\Routing\Exception\RouteNotFoundException : Route "entity.notification_storage.canonical" does not exist. dans Drupal\Core\Routing\RouteProvider->getRouteByName() (ligne 202 de /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteProvider.php).

/**
 * Define NotificationStorage entity.
 *
 * @package Drupal\notification\Entity
 *
 * @ContentEntityType(
 *   id = "notification_storage",
 *   label = @Translation("Notification Storage"),
 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list_builder" = "Drupal\notification\Controller\NotificationStorageListBuilder",
 *     "views_data" = "Drupal\notification\NotificationViewsData"
 *   },
 *   base_table = "notification_storage",
 *   entity_keys = {
 *    "id" = "id",
 *    "uuid" = "uuid",
 *    "langcode" = "langcode"
 *   },
 *   fieldable = TRUE,
 *   links = {
 *     "canonical" = "/admin/notification_storage/list"
 *   },
 *   field_ui_base_route = "notification_storage.settings"
 * )
 */
5
  • is the value of $notifications['notification'] an array of ID's ?
    – No Sssweat
    Jun 7, 2018 at 11:16
  • Well, the obvious error would be entity.notification_storage.canonical not being defined. Whats that come from? Was that module disabled?
    – Kevin
    Jun 7, 2018 at 14:37
  • @Kevin you define the entity canonical in the entity type annotation itself, thats probably where it’s missing from. I’d wager it’s a form state redirect trying to forward to the canonical but not being able to find the route
    – Clive
    Jun 7, 2018 at 16:42
  • @clive I've updated the code with the annotation
    – U.N
    Jun 8, 2018 at 4:36
  • @Kevin I've updated the code with the annotation
    – U.N
    Jun 8, 2018 at 4:36

1 Answer 1

1

You've defined a canonical link in the entity annotations, but this doesn't build a route automatically. If you don't want to do specify the route in a yaml file you need a route provider:

 *   handlers = {
 *     "route_provider" = {
 *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",

If the custom entity should be part of the admin interface use AdminHtmlRouteProvider.

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.