Upload
skilld
View
196
Download
0
Tags:
Embed Size (px)
Citation preview
Drupal 7 vs 8
Andy PostnikovFreelancer
&
Alexey GaydaburaLead Developer at @SkillD
Lviv, 2013
http://www.skilld.fr
Installer makeup
Drupal 7 - install.phpif (version_compare(PHP_VERSION, '5.2.4') < 0) {
exit;
}
Drupal 8 - install.phpchdir('..');
require_once __DIR__ . '/vendor/autoload.php';
if (version_compare(PHP_VERSION, '5.3.10') < 0) {
exit;
}
if (ini_get('safe_mode')) {
print 'Your PHP installation has safe_mode enabled. ...';
exit;
}
Drupal 7 - index.phpdefine('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
Drupal 8 - index.phprequire_once __DIR__ . '/core/vendor/autoload.php';
require_once __DIR__ . '/core/includes/bootstrap.inc';
try {
drupal_handle_request();
}
catch (Exception $e) {
print 'If you have ... read http://drupal.org/documentation/rebuild';
throw $e;
}
Drupal 7 - Bootstrap
1. DRUPAL_BOOTSTRAP_CONFIGURATION2. DRUPAL_BOOTSTRAP_PAGE_CACHE3. DRUPAL_BOOTSTRAP_DATABASE4. DRUPAL_BOOTSTRAP_VARIABLES5. DRUPAL_BOOTSTRAP_SESSION6. DRUPAL_BOOTSTRAP_PAGE_HEADER7. DRUPAL_BOOTSTRAP_LANGUAGE8. DRUPAL_BOOTSTRAP_FULL
Drupal 8 - Bootstrap1. DRUPAL_BOOTSTRAP_CONFIGURATION
+ DRUPAL_BOOTSTRAP_KERNEL2. DRUPAL_BOOTSTRAP_PAGE_CACHE
3. DRUPAL_BOOTSTRAP_DATABASEDRUPAL_BOOTSTRAP_VARIABLES- DRUPAL_BOOTSTRAP_SESSION
- DRUPAL_BOOTSTRAP_PAGE_HEADER
- DRUPAL_BOOTSTRAP_LANGUAGE
+ DRUPAL_BOOTSTRAP_CODEDRUPAL_BOOTSTRAP_FULL (language + theme)
Should be 3 steps - https://drupal.org/node/2023495
Drupal 7: Menu page callback$result = _menu_site_is_offline() ? MENU_SITE_OFFLINE : MENU_SITE_ONLINE;
drupal_alter('menu_site_status', $result, ...);
$result = call_user_func_array( $router['page_callback'],
$router['page_arguments']);
drupal_alter('page_delivery_callback', $delivery_callback);
drupal_deliver_html_page()
drupal_render_page() - hook_page_build() + hook_page()
drupal_page_footer()
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);
D7: Hook, alter, preprocess!
● Core hooks● Custom hooks● Alter everything● Preprocess anything● Theme suggestions
You are the King!
D8: Hook, alter, preprocess!+ Subscribe
● Kernel & Routing events● Core hooks● Custom hooks● Alter everything● Preprocess anything● Theme suggestions ++
You are the King!
D8: Subscribe kernel
namespace Symfony\Component\HttpKernel;final class KernelEvents
● REQUEST - hook_boot()● CONTROLLER - menu “page callback”● VIEW - hook_page_build()● RESPONSE - hook_page_alter()● TERMINATE - hook_exit()● EXCEPTION
D8: Subscribe routing
namespace Drupal\Core\Routing;
final class RoutingEvents { const ALTER = 'routing.route_alter'; const DYNAMIC = 'routing.route_dynamic';}
D8: Subscribe and alter
namespace Drupal\Core\EventSubscriber;
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; }}
D8: Subscribe
D8: Hook, alter, preprocess
function telephone_field_info_alter(&$info) { if (\Drupal::moduleHandler()->moduleExists('text')) { $info['telephone']['default_formatter'] = 'text_plain'; }}
function telephone_field_formatter_info_alter(&$info) { if (isset($info['text_plain'])) { $info['text_plain']['field_types'][] = 'telephone'; }}
D7: My.module vs altering
● hook_menu()
$items['mypath'] = array( 'page callback' => 'mypath_page_view'
'theme callback' => 'theme_mypath_page_view'
'delivery callback' => 'deliver_mypath_page_view'
● hook_theme()● mypath_page_view($arg);
● hook_menu_alter()● hook_theme_registry_alter()● mycore_page_view()● mycore_page_theme()
VS
D7: My.module hook_menu()
1. Routing2. Menu links3. Local actions4. Local tasks5. Breadcrumbs6. Contextual links
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
D8: My.module vs alteringhook_”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) {}
}
D8: Services & Managers
D7 vs D8: render Render array (‘#theme’ => ‘item_list’,‘#items’ => array())
https://drupal.org/node/2068471
+ $events[KernelEvents::VIEW][] = array('onHtmlFragment', 100);
+ $events[KernelEvents::VIEW][] = array('onHtmlPage', 50);
class Link extends HeadElement
class Metatag extends HeadElement
class HeadElement
class HtmlPage extends HtmlFragment
class HtmlFragment
When it’s ready™?
https://drupal.org/node/2107085
http://xjm.drupalgardens.com/blog/when-its-ready
no more hook_menu()no more variable_get()complete language negotiationcomplete entity field api
Questions?
Anderey PostnikovFreelance Developer
Skype: andypostE-mail: [email protected]
http://www.skilld.fr
Drupal 7 vs 8
Alexey GaydaburaLead Developer at @SkillDSkype: alexey.gaydabura
E-mail: [email protected]