- Create a MessageHtmlRouteProvider class in the src directory that extends
\Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider:
<?php
namespace Drupal\mymodule;
use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider;
/**
* Provides HTML routes for the message entity type.
*/
class MessageHtmlRouteProvider extends DefaultHtmlRouteProvider {
}
- Override the provided getCanonicalRoute method and return the value from getEditFormRoute:
<?php
namespace Drupal\mymodule;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider;
/**
* Provides HTML routes for the message entity type.
*/
class MessageHtmlRouteProvider extends DefaultHtmlRouteProvider {
/**
* {@inheritdoc}
*/
protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
// Messages use the edit-form route as the canonical route.
// @todo Remove this when #2479377 gets fixed.
return $this->getEditFormRoute($entity_type);
}
}
- Rebuild Drupal's caches for the change to take effect and routes to be rebuilt.
- Navigating to /message/{message} will now load the edit form, just as /message/{message}/edit.