By kristiaanvandeneynde on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
2.0.x
Introduced in version:
2.0.0
Issue links:
Description:
You may now present the user with a page of entities you can add to a group that is specific to a base plugin ID. This can be useful when you have a plugin with derivatives per bundle, so that you can present an add/create page with only node types, group types, or whatever bundleable entity you have enabled.
As a result, GroupNodeController and GroupNodeRouteProvider have been removed as the same functionality can now be achieved by a simple route subscriber cloning the original routes and adding a base_plugin_id default.
See the example from the gnode module below:
namespace Drupal\gnode\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Subscriber for Group Node routes.
*/
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
if ($route = $collection->get('entity.group_content.create_page')) {
$copy = clone $route;
$copy->setPath('group/{group}/node/create');
$copy->setDefault('base_plugin_id', 'group_node');
$collection->add('entity.group_content.group_node_create_page', $copy);
}
if ($route = $collection->get('entity.group_content.add_page')) {
$copy = clone $route;
$copy->setPath('group/{group}/node/add');
$copy->setDefault('base_plugin_id', 'group_node');
$collection->add('entity.group_content.group_node_add_page', $copy);
}
}
}
Impacts:
Module developers
Site templates, recipes and distribution developers