andy postnikov - drupal 7 vs drupal 8: от бутстрапа до рендера
TRANSCRIPT
![Page 1: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/1.jpg)
Drupal 7 vs 8
Andy PostnikovFreelancer
&
Alexey GaydaburaLead Developer at @SkillD
Lviv, 2013
http://www.skilld.fr
![Page 2: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/2.jpg)
Installer makeup
![Page 3: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/3.jpg)
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;
}
![Page 4: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/4.jpg)
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;
}
![Page 5: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/5.jpg)
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
![Page 6: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/6.jpg)
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
![Page 7: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/7.jpg)
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()
![Page 8: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/8.jpg)
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);
![Page 9: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/9.jpg)
D7: Hook, alter, preprocess!
● Core hooks● Custom hooks● Alter everything● Preprocess anything● Theme suggestions
You are the King!
![Page 10: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/10.jpg)
D8: Hook, alter, preprocess!+ Subscribe
● Kernel & Routing events● Core hooks● Custom hooks● Alter everything● Preprocess anything● Theme suggestions ++
You are the King!
![Page 11: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/11.jpg)
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
![Page 12: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/12.jpg)
D8: Subscribe routing
namespace Drupal\Core\Routing;
final class RoutingEvents { const ALTER = 'routing.route_alter'; const DYNAMIC = 'routing.route_dynamic';}
![Page 13: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/13.jpg)
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; }}
![Page 14: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/14.jpg)
D8: Subscribe
![Page 15: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/15.jpg)
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'; }}
![Page 16: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/16.jpg)
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
![Page 17: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/17.jpg)
D7: My.module hook_menu()
1. Routing2. Menu links3. Local actions4. Local tasks5. Breadcrumbs6. Contextual links
![Page 18: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/18.jpg)
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
![Page 19: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/19.jpg)
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) {}
}
![Page 20: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/20.jpg)
D8: Services & Managers
![Page 21: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/21.jpg)
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
![Page 22: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/22.jpg)
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
![Page 23: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/23.jpg)
Questions?
![Page 24: Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера](https://reader034.vdocument.in/reader034/viewer/2022042614/55a2849f1a28ab391d8b472a/html5/thumbnails/24.jpg)
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]