8. Drupal 8: Symfony drupal_handle_request()
// Initialize the environment, load settings.php, and activate a PSR-0 class
// autoloader with required namespaces registered.
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
$kernel = new DrupalKernel('prod', drupal_classloader(),
!$test_only);
// @todo Remove this once everything in the bootstrap has been
//
converted to services in the DIC.
$kernel->boot();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
// Create a request object from the HttpFoundation.
$request = Request::createFromGlobals();
$response = $kernel->handle($request)
->prepare($request)->send();
$kernel->terminate($request, $response);
9. D7: Hook, alter, preprocess!
●
●
●
●
●
Core hooks
Custom hooks
Alter everything
Preprocess anything
Theme suggestions
You are the King!
10. D8: Hook, alter, preprocess!
+ Subscribe
●
●
●
●
●
●
Kernel & Routing events
Core hooks
Custom hooks
Alter everything
Preprocess anything
Theme suggestions ++
You are the King!
12. D8: Subscribe routing
namespace DrupalCoreRouting;
final class RoutingEvents {
const ALTER = 'routing.route_alter';
const DYNAMIC = 'routing.route_dynamic';
}
13. D8: Subscribe and alter
namespace DrupalCoreEventSubscriber;
class AccessSubscriber implements EventSubscriberInterface {
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array
('onKernelRequestAccessCheck', 30);
// Setting very low priority to ensure access checks are run after alters.
$events[RoutingEvents::ALTER][] = array
('onRoutingRouteAlterSetAccessCheck', -50);
return $events;
}
}
18. D8: My.module NO hook_menu()
1.
my.routing.yml
2.
my_default_menu_links()
3.
my.local_actions.yml
4.
my.local_tasks.yml
5.
class MyBreadcrumbBuilder
6.
my.contextual_links.yml
7.
my.services.yml
19. D8: My.module vs altering
hook_”world”_alter() - THE SAME!
class MyEventSubscriber implements
EventSubscriberInterface
{ public static function getSubscribedEvents(); }
class MyServiceProvider implements
ServiceProviderInterface, ServiceModifierInterface
{
public function register(ContainerBuilder $container) {}
public function alter(ContainerBuilder $container) {}
}