SlideShare a Scribd company logo
#D8CX
Kate Marshalkina & Konstantin Komelin
DrupalCamp Kyiv 2013 Start Here
Upgrade your modules
to Drupal 8
A Little More About Us
2
DrupalCamp Kyiv 2013
[Moscow, Russia]
• UI Cache Clear module author
• Contributor to several modules
• Web developer at Licel LLC
[Saint Petersburg, Russia]
• Author of Yandex.Metrics, Pinned Site
• Contributor to modules and themes
• Co-organizer of Drupal Community in St. Petersburg
• Individual web developer, trainer and consultant
Kate Marshalkina kalabro
Konstantin Komelin KKomelin
What is Drupal 8?
3
DrupalCamp Kyiv 2013
Drupal 8
≠
LOREM IPSUM DOLOREM COMPANY Insert You Tagline Here
Drupal 8 — Drupal,even better!
4
Mobilesupport&inlineediting
5
DrupalCamp Kyiv 2013
#D8CX: Drupal 8 Contrib Experience
• Release top 40 modules together with D8
• 27 modules with #D8CX flag (Jun 8, 2013)
• Not only top modules are important!
#D8CX: I pledge that UI Cache Clear will have a full Drupal 8 release on the day that
Drupal 8 is released.
#D8CX: We pledge that Yandex.Metrics will have a full Drupal 8 release on the day
that Drupal 8 is released.
#D8CX: I pledge that Yandex Services Authorization API will have a full Drupal 8
release on the day that Drupal 8 is released.
6
DrupalCamp Kyiv 2013
Why should I upgrade?
7
DrupalCamp Kyiv 2013
• Be one of the first
• Prepare to D8
• Learn Drupal 8 API
• Help to community and Drupal
• Just for fun ;)
When should I start?
8
DrupalCamp Kyiv 2013
“In Villabajo they are still drilling the core and don’t have agreements about
many things, and in Villarriba others have already upgraded modules”
D8 begins
Mar 10, 2011
Alpha1 RC
Dec, 2013
Beta
May 20, 2013
Drupal 8.0
Sep-Oct, 2013
July, 2013
Our examples>
DrupalCamp Kyiv 2013
Yandex.Metrics (8.x)
10
DrupalCamp Kyiv 2013
UI Cache Clear (7.x)
11
DrupalCamp Kyiv 2013
UI Cache Clear (8.x)
12
DrupalCamp Kyiv 2013
13
DrupalCamp Kyiv 2013
New home for sites/all/*
Drupal 7 Drupal 8
A new folder structure
Before you start
14
DrupalCamp Kyiv 2013
• Update PHP to 5.3.10
• Reconcile to o_OP
• Get used to use https://drupal.org/list-changes
• Be ready to reinstall Drupal
• Prepare your rocket ;)
Find 5 differences
15
DrupalCamp Kyiv 2013
Drupal 7 Drupal 8
name = 'Yandex.Metrics Counter'
core = 7.x
files[] = yandex_metrics.test
name: 'Yandex.Metrics Counter'
core: 8.x
type: module
yandex_metrics.info yandex_metrics.info.yml
16
Hurray!
We’ve just upgraded the module!
Thanks for coming!
Goodbye :-P
hook_menu and routing
17
DrupalCamp Kyiv 2013
function yandex_metrics_menu() {
$items['admin/config/system/yandex_metrics'] = array(
'title' => 'Yandex.Metrics',
'route_name' => 'yandex_metrics_counter_settings',
);
// ...
}
yandex_metrics.moduleStep 2
yandex_metrics_counter_settings:
pattern: '/admin/config/system/yandex_metrics'
defaults:
_form: 'Drupalyandex_metricsFormYandexMetricsCounterSettingsForm'
requirements:
_permission: 'administer Yandex.Metrics settings'
yandex_metrics.routing.ymlStep 1
Settings form
18
DrupalCamp Kyiv 2013
namespace Drupalyandex_metricsForm;
use DrupalsystemSystemConfigFormBase;
class YandexMetricsCounterSettingsForm extends SystemConfigFormBase {
public function getFormID() {
return 'yandex_metrics_counter_settings';
}
//...
lib/Drupal/yandex_metrics/Form/YandexMetricsCounterSettingsForm.php
— Goodbye, system_settings_form().
Settings form
19
DrupalCamp Kyiv 2013
public function buildForm(array $form, array &$form_state) {
$form['path'] = array(
'#type' => 'details',
'#title' => t('Page specific tracking settings'),
);
// ...
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, array &$form_state) { }
public function submitForm(array &$form, array &$form_state) { }
lib/Drupal/yandex_metrics/Form/YandexMetricsCounterSettingsForm.php
Override methods that you need
Configuration & State
20
DrupalCamp Kyiv 2013
Variables (D7)
Configuration (D8)
State (D8)
Configuration files
21
DrupalCamp Kyiv 2013
yandex_metrics.settings:
type: mapping
label: 'Yandex.Metrics Counter settings'
mapping:
counter_code:
type: string
label: 'Counter code'
config/schema/yandex_merics.schema.yml
counter_code: ''
config/yandex_merics.settings.yml
Config & State
22
DrupalCamp Kyiv 2013
// Get config value.
$counter_code = Drupal::config('yandex_metrics.settings')
->get('counter_code');
// Set config value.
Drupal::config('yandex_metrics.settings')
->set('counter_code', $counter_code)->save();
In files
// Get value of state variable.
$value = Drupal::state()->get('some_module.key');
// Set value of state variable.
Drupal::state()->set('some_module.key', $value);
In database
Entities
23
DrupalCamp Kyiv 2013
Fieldable
EntityNG (DX)
Why: deployment, unification
Idea: ctools exportables
Implementation: plugins + yml
new
Content Entities Config Entities
Examples:
Nodes
Taxonomy terms
Users
Comments
Files
Menu Links
…
Examples:
Block instances
Vocabularies
User roles
Views
Menus
Display Modes
Image Styles
…
>
DrupalCamp Kyiv 2013
To be continued…
#D8CX
Kate Marshalkina & Konstantin Komelin
DrupalCamp Kyiv 2013 Continue Here
Upgrade your modules
to Drupal 8
Part 2
Drupal 8 Plugins
26
DrupalCamp Kyiv 2013
Why: extend them all!
Idea: ctools, next generation.
Implementation: classes, annotations.
Examples:
Blocks
Views
Entities
Field Widgets/Formatters
Text Filters
…
That’s not a
“Wordpress” plugin,
guys :)
Block Plugin (theoretical)
27
DrupalCamp Kyiv 2013
Block Plugin (practice)
28
LOREM IPSUM DOLOREM COMPANY Insert You Tagline Here
28
namespace Drupalhello_worldPluginBlock;
Now plugin will be found
automatically!
Block Plugin (practice)
29
DrupalCamp Kyiv 2013
Annotations instead of hook_*_info()
/**
* Provides a 'Random number' block.
*
* @Plugin(
* id = "hello_world_random_number",
* admin_label = @Translation("Random number"),
* module = "hello_world"
* )
*/
class HelloWorldRandomBlock extends BlockBase {
lib/Drupal/hello_world/Plugin/Block/HelloWorldRandomBlock.php
Block Plugin (practice)
30
DrupalCamp Kyiv 2013
Override methods that you need
protected function blockBuild() {
$this->configuration['label'] = t('Random number');
return array(
'#markup' => rand(1, 9),
);
}
//..
public function settings() { }
public function blockForm($form, &$form_state) { }
public function blockSubmit($form, &$form_state) { }
..lib/Drupal/hello_world/Plugin/Block/HelloWorldRandomBlock.php
Block Entities (theoretical)
31
DrupalCamp Kyiv 2013
block.block.bartik.search.yml
block.block.bartik.about_this_site.yml
block.block.bartik.random_number.yml
Block Entities (practice)
32
DrupalCamp Kyiv 2013
sites/default/files/config_#HASH#/active/block.block.bartik.random_number_1.yml
× 2
sites/default/files/config_#HASH#/active/block.block.bartik.random_number_2.yml
sites/default/files/config_#HASH#/active/block.block.bartik.random_number_3.yml
Hooks?
33
DrupalCamp Kyiv 2013
/**
* Implements hook_form_FORM_ID_alter().
*/
function ui_cache_clear_form_block_form_alter(&$form, $form_state)
{
$config_entity = $form_state['controller']->getEntity();
// Fieldset replaced by details.
$form['cache_details'] = array(
'#type' => 'details',
'#title' => t('Cache settings'),
);
// ..
• Hooks are still here.
• And there are new!
ui_cache_clear.module
>
DrupalCamp Kyiv 2013
Views
Visualization API (8.x)
35
DrupalCamp Kyiv 2013
https://drupal.org/sandbox/Niremizov/1985870
Thx Christophe Van Gysel!
Module features:
• Theme hook
• Plugin service (custom
chart handlers)
• Views Style Plugin
Views
36
DrupalCamp Kyiv 2013
• Inside core and already works
• Uses core Plugin System
• Export/Import using Config Entities
• Small API changes
CamelCase
hook_views_api, hook_views_plugin
Tip: How to create default view in Drupal 8:
Copy sitesdefaultfilesconfig_{HASH}activeconfigviews.view.{view_name}.yml
Paste modules{module_name}configviews.view.{view_name}.yml
Views Plugins
37
Drupal 7 Drupal 8
/**
* Implements hook_views_plugins().
*/
function vi..on_views_plugins() {
return array(
'style' => array(
'visualization' => array(
'title' =>
t('Visualization'),
'type' => 'normal',
'theme' => 'visualization',
// ...
'handler' =>
'visualization_plugin_style',
'uses options' => TRUE,
'uses grouping' => FALSE,
/*
* @Plugin(
* id = "visualization",
* title = @Translation("Visualization"),
* display_types = {"normal"}
* theme = "visualization",
* module = "visualization",
* )
*/
class Visualization
extends StylePluginBase {
protected $usesRowClass = TRUE;
protected $usesGrouping = FALSE;
protected $usesFields = TRUE;
// ...
}
DrupalCamp Kyiv 2013
PHPTemplate → Twig
38
DrupalCamp Kyiv 2013
{# core/modules/block/templates/block.html.twig #}
<div{{ attributes }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
<div{{ content_attributes }}>
{{ content }}
</div>
</div>
DrupalCamp Kyiv 2013
KEEP CALM
AND
CLEAR CACHE
And Drupal 8 says:
— “Fatal error: Call to undefined function cache_clear_all()”
Cache System
Cache Tags instead of wildcards
DrupalCamp Kyiv 2013
Cached Item 1
Tag 1
Tag 2
Tag 3
Cached Item 2 Tag 2 Cached Item 3
Tag 1
Tag 3
cache()->invalidateTags(array('Tag 2'));
Cached Item 3
Tag 1
Tag 3
Cached Item 1
Tag 1
Tag 2
Tag 3
Cached Item 2 Tag 2
*
Note: Drupal calculates “checksum” for every cache tag when read from cache!
40
Cache System
41
DrupalCamp Kyiv 2013
// Set cache to 'page' bin.
cache('page')->set($cid, $data, $expire, $tags);
New Cache API
// Truncate cache table.
cache()->deleteAll();
// Marks cache items from all bins with 'content' tag as invalid.
cache_invalidate_tags(array('content' => TRUE));
// Get multiple cache items.
cache('field')->getMultiple($cids);
// Get item even it is invalid.
cache()->get('field:user:1', TRUE);
Automated tests
42
DrupalCamp Kyiv 2013
namespace Drupalyandex_metricsTests;
use DrupalsimpletestWebTestBase;
class CounterTest extends WebTestBase {
public static $modules = array('yandex_metrics');
public static function getInfo() { }
public function setUp() {
parent::setUp();
}
public function tearDown() { }
lib/Drupal/yandex_metrics/Tests/CounterTest.php
Join #D8CX!
Upgrade your module to Drupal 8 or help others!+
DrupalCamp Kyiv 2013
References
44
DrupalCamp Kyiv 2013
• Change records for Drupal core
http://drupal.org/list-changes
• [May 22, 2013] Alex Bronstein (effulgentsia) - Upgrading your modules to
Drupal 8
http://portland2013.drupal.org/session/upgrading-your-modules-drupal-8
• [Feb 8, 2013] Angie Byron (webchick) - Step-by-step: Converting modules
from Drupal 7 to Drupal 8
http://webchick.net/node/118
• [Nov 4, 2012] Tim Plunkett (tim.plunkett) - D8CX: The Reckoning
http://2012.badcamp.net/program/sessions/d8cx-reckoning
!
DrupalCamp Kyiv 2013
Thank you for your attention!
Konstantin Komelin
@KKomelin
konstantin@komelin.com
Kate Marshalkina
@kalabro
marshalkina@licel.ru

More Related Content

PDF
Drupal upgrades and migrations. BAD Camp 2013 version
PDF
ODP
Conference Migrate to Drupal 8 by Leon Cros at Drupal Developer Days 2015 in ...
PPTX
Drupal 6 to Drupal 8 Migration
PDF
Migrate to Drupal 8
PPT
Are you ready for Drupal 8?
PDF
Everything You Need to Know About the Top Changes in Drupal 8
PDF
Yet Another Drupal Development/Deployment Presentation
Drupal upgrades and migrations. BAD Camp 2013 version
Conference Migrate to Drupal 8 by Leon Cros at Drupal Developer Days 2015 in ...
Drupal 6 to Drupal 8 Migration
Migrate to Drupal 8
Are you ready for Drupal 8?
Everything You Need to Know About the Top Changes in Drupal 8
Yet Another Drupal Development/Deployment Presentation

What's hot (19)

PPTX
Top 8 Improvements in Drupal 8
PDF
Evolution of Drupal and the Drupal community
PPT
Taking your module from Drupal 6 to Drupal 7
PDF
Drupal 6 to 7 migration guide
PPTX
History of Drupal: From Drop 1.0 to Drupal 8
PDF
10 New Things You Can Do with Drupal 8 Out-of-the-Box
PDF
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
PDF
Drupal migrations in 2018 - presentation at DrupalCon in Nashville
PPTX
Database Migrations with Gradle and Liquibase
PDF
features+
PDF
Drupal 8 Configuration Management
PDF
Blisstering drupal module development ppt v1.2
PPT
Taking your site from Drupal 6 to Drupal 7
PDF
Plain english guide to drupal 8 criticals
ODP
Upgrading your site from Drupal 6 to Drupal 7
PPTX
Drupal 7 vs. Drupal 8: A Contrast of Multilingual Support
PDF
Drupal 8 - A Brief Introduction
PDF
Drush und Multisite: drush_multi
Top 8 Improvements in Drupal 8
Evolution of Drupal and the Drupal community
Taking your module from Drupal 6 to Drupal 7
Drupal 6 to 7 migration guide
History of Drupal: From Drop 1.0 to Drupal 8
10 New Things You Can Do with Drupal 8 Out-of-the-Box
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Drupal migrations in 2018 - presentation at DrupalCon in Nashville
Database Migrations with Gradle and Liquibase
features+
Drupal 8 Configuration Management
Blisstering drupal module development ppt v1.2
Taking your site from Drupal 6 to Drupal 7
Plain english guide to drupal 8 criticals
Upgrading your site from Drupal 6 to Drupal 7
Drupal 7 vs. Drupal 8: A Contrast of Multilingual Support
Drupal 8 - A Brief Introduction
Drush und Multisite: drush_multi

Viewers also liked (13)

PDF
Your first d8 module
PDF
Future-proof styling in Drupal (8)
PDF
Faster and Smarter Development with Drupal Console
 
PDF
Drupal 8 Configuration Management
PDF
A New Theme Layer for Drupal 8
PPTX
Paragraphs at drupal 8.
PDF
Made with drupal 8
PDF
How Drupal 8 Reaches Its Full Potential on Pantheon
PDF
Drupal 8 Sample Module
PDF
Create rich web stories with Drupal 8 and paragraphs
PPTX
Drupal 8 Vocabulary Lesson
PDF
Getting started with Drupal 8
PDF
Drupal 8, tricks and tips learned from the first 6 months
Your first d8 module
Future-proof styling in Drupal (8)
Faster and Smarter Development with Drupal Console
 
Drupal 8 Configuration Management
A New Theme Layer for Drupal 8
Paragraphs at drupal 8.
Made with drupal 8
How Drupal 8 Reaches Its Full Potential on Pantheon
Drupal 8 Sample Module
Create rich web stories with Drupal 8 and paragraphs
Drupal 8 Vocabulary Lesson
Getting started with Drupal 8
Drupal 8, tricks and tips learned from the first 6 months

Similar to #D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2) (20)

PDF
PlovDev 2016: Drupal 8 Evolution & Kickstart by Ivo Radulovski
PDF
Drupal 8 - Core and API Changes
PDF
Building a Custom Theme in Drupal 8
PDF
Upgrading to Drupal 8: Benefits and Gotchas
PPTX
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
PDF
Drupal 8: frontend development
PDF
Drupal 8 introduction
PDF
Drupal 8 deeper dive
PDF
[HKDUG] #20151017 - BarCamp 2015 - Drupal 8 is Coming! Are You Ready?
PDF
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
PDF
Lviv 2013 d7 vs d8
PDF
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
PPTX
Welcome to Drupal: Midcamp 2015
PPTX
Drupal 8 Initiatives
PDF
Drupal 8 - Corso frontend development
PDF
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
PDF
Drupal 8 - Build Week Update
PDF
Drupal 8 Basic Training - DrupalEurope 2018 - Maarten De Block
PDF
Drupal 7 migrating to drupal 8
PDF
Drupal 8 for site builders
PlovDev 2016: Drupal 8 Evolution & Kickstart by Ivo Radulovski
Drupal 8 - Core and API Changes
Building a Custom Theme in Drupal 8
Upgrading to Drupal 8: Benefits and Gotchas
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Drupal 8: frontend development
Drupal 8 introduction
Drupal 8 deeper dive
[HKDUG] #20151017 - BarCamp 2015 - Drupal 8 is Coming! Are You Ready?
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
Lviv 2013 d7 vs d8
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Welcome to Drupal: Midcamp 2015
Drupal 8 Initiatives
Drupal 8 - Corso frontend development
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
Drupal 8 - Build Week Update
Drupal 8 Basic Training - DrupalEurope 2018 - Maarten De Block
Drupal 7 migrating to drupal 8
Drupal 8 for site builders

More from Konstantin Komelin (7)

PDF
Vue.js - реактивный фронтенд фреймворк для людей
PDF
Open Source == Money
PPTX
Responsive Web Design & Drupal
PPTX
The Journey to Drupal World
PPTX
Респонсила вашего сайта
PPT
Drupal и мобильные устройства
PPT
Свой проект на Drupal.org от идеи до первого релиза
Vue.js - реактивный фронтенд фреймворк для людей
Open Source == Money
Responsive Web Design & Drupal
The Journey to Drupal World
Респонсила вашего сайта
Drupal и мобильные устройства
Свой проект на Drupal.org от идеи до первого релиза

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
KodekX | Application Modernization Development
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Monthly Chronicles - July 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
KodekX | Application Modernization Development
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.

#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)

  • 1. #D8CX Kate Marshalkina & Konstantin Komelin DrupalCamp Kyiv 2013 Start Here Upgrade your modules to Drupal 8
  • 2. A Little More About Us 2 DrupalCamp Kyiv 2013 [Moscow, Russia] • UI Cache Clear module author • Contributor to several modules • Web developer at Licel LLC [Saint Petersburg, Russia] • Author of Yandex.Metrics, Pinned Site • Contributor to modules and themes • Co-organizer of Drupal Community in St. Petersburg • Individual web developer, trainer and consultant Kate Marshalkina kalabro Konstantin Komelin KKomelin
  • 3. What is Drupal 8? 3 DrupalCamp Kyiv 2013 Drupal 8 ≠
  • 4. LOREM IPSUM DOLOREM COMPANY Insert You Tagline Here Drupal 8 — Drupal,even better! 4
  • 6. #D8CX: Drupal 8 Contrib Experience • Release top 40 modules together with D8 • 27 modules with #D8CX flag (Jun 8, 2013) • Not only top modules are important! #D8CX: I pledge that UI Cache Clear will have a full Drupal 8 release on the day that Drupal 8 is released. #D8CX: We pledge that Yandex.Metrics will have a full Drupal 8 release on the day that Drupal 8 is released. #D8CX: I pledge that Yandex Services Authorization API will have a full Drupal 8 release on the day that Drupal 8 is released. 6 DrupalCamp Kyiv 2013
  • 7. Why should I upgrade? 7 DrupalCamp Kyiv 2013 • Be one of the first • Prepare to D8 • Learn Drupal 8 API • Help to community and Drupal • Just for fun ;)
  • 8. When should I start? 8 DrupalCamp Kyiv 2013 “In Villabajo they are still drilling the core and don’t have agreements about many things, and in Villarriba others have already upgraded modules” D8 begins Mar 10, 2011 Alpha1 RC Dec, 2013 Beta May 20, 2013 Drupal 8.0 Sep-Oct, 2013 July, 2013
  • 11. UI Cache Clear (7.x) 11 DrupalCamp Kyiv 2013
  • 12. UI Cache Clear (8.x) 12 DrupalCamp Kyiv 2013
  • 13. 13 DrupalCamp Kyiv 2013 New home for sites/all/* Drupal 7 Drupal 8 A new folder structure
  • 14. Before you start 14 DrupalCamp Kyiv 2013 • Update PHP to 5.3.10 • Reconcile to o_OP • Get used to use https://drupal.org/list-changes • Be ready to reinstall Drupal • Prepare your rocket ;)
  • 15. Find 5 differences 15 DrupalCamp Kyiv 2013 Drupal 7 Drupal 8 name = 'Yandex.Metrics Counter' core = 7.x files[] = yandex_metrics.test name: 'Yandex.Metrics Counter' core: 8.x type: module yandex_metrics.info yandex_metrics.info.yml
  • 16. 16 Hurray! We’ve just upgraded the module! Thanks for coming! Goodbye :-P
  • 17. hook_menu and routing 17 DrupalCamp Kyiv 2013 function yandex_metrics_menu() { $items['admin/config/system/yandex_metrics'] = array( 'title' => 'Yandex.Metrics', 'route_name' => 'yandex_metrics_counter_settings', ); // ... } yandex_metrics.moduleStep 2 yandex_metrics_counter_settings: pattern: '/admin/config/system/yandex_metrics' defaults: _form: 'Drupalyandex_metricsFormYandexMetricsCounterSettingsForm' requirements: _permission: 'administer Yandex.Metrics settings' yandex_metrics.routing.ymlStep 1
  • 18. Settings form 18 DrupalCamp Kyiv 2013 namespace Drupalyandex_metricsForm; use DrupalsystemSystemConfigFormBase; class YandexMetricsCounterSettingsForm extends SystemConfigFormBase { public function getFormID() { return 'yandex_metrics_counter_settings'; } //... lib/Drupal/yandex_metrics/Form/YandexMetricsCounterSettingsForm.php — Goodbye, system_settings_form().
  • 19. Settings form 19 DrupalCamp Kyiv 2013 public function buildForm(array $form, array &$form_state) { $form['path'] = array( '#type' => 'details', '#title' => t('Page specific tracking settings'), ); // ... return parent::buildForm($form, $form_state); } public function validateForm(array &$form, array &$form_state) { } public function submitForm(array &$form, array &$form_state) { } lib/Drupal/yandex_metrics/Form/YandexMetricsCounterSettingsForm.php Override methods that you need
  • 20. Configuration & State 20 DrupalCamp Kyiv 2013 Variables (D7) Configuration (D8) State (D8)
  • 21. Configuration files 21 DrupalCamp Kyiv 2013 yandex_metrics.settings: type: mapping label: 'Yandex.Metrics Counter settings' mapping: counter_code: type: string label: 'Counter code' config/schema/yandex_merics.schema.yml counter_code: '' config/yandex_merics.settings.yml
  • 22. Config & State 22 DrupalCamp Kyiv 2013 // Get config value. $counter_code = Drupal::config('yandex_metrics.settings') ->get('counter_code'); // Set config value. Drupal::config('yandex_metrics.settings') ->set('counter_code', $counter_code)->save(); In files // Get value of state variable. $value = Drupal::state()->get('some_module.key'); // Set value of state variable. Drupal::state()->set('some_module.key', $value); In database
  • 23. Entities 23 DrupalCamp Kyiv 2013 Fieldable EntityNG (DX) Why: deployment, unification Idea: ctools exportables Implementation: plugins + yml new Content Entities Config Entities Examples: Nodes Taxonomy terms Users Comments Files Menu Links … Examples: Block instances Vocabularies User roles Views Menus Display Modes Image Styles …
  • 24. > DrupalCamp Kyiv 2013 To be continued…
  • 25. #D8CX Kate Marshalkina & Konstantin Komelin DrupalCamp Kyiv 2013 Continue Here Upgrade your modules to Drupal 8 Part 2
  • 26. Drupal 8 Plugins 26 DrupalCamp Kyiv 2013 Why: extend them all! Idea: ctools, next generation. Implementation: classes, annotations. Examples: Blocks Views Entities Field Widgets/Formatters Text Filters … That’s not a “Wordpress” plugin, guys :)
  • 28. Block Plugin (practice) 28 LOREM IPSUM DOLOREM COMPANY Insert You Tagline Here 28 namespace Drupalhello_worldPluginBlock; Now plugin will be found automatically!
  • 29. Block Plugin (practice) 29 DrupalCamp Kyiv 2013 Annotations instead of hook_*_info() /** * Provides a 'Random number' block. * * @Plugin( * id = "hello_world_random_number", * admin_label = @Translation("Random number"), * module = "hello_world" * ) */ class HelloWorldRandomBlock extends BlockBase { lib/Drupal/hello_world/Plugin/Block/HelloWorldRandomBlock.php
  • 30. Block Plugin (practice) 30 DrupalCamp Kyiv 2013 Override methods that you need protected function blockBuild() { $this->configuration['label'] = t('Random number'); return array( '#markup' => rand(1, 9), ); } //.. public function settings() { } public function blockForm($form, &$form_state) { } public function blockSubmit($form, &$form_state) { } ..lib/Drupal/hello_world/Plugin/Block/HelloWorldRandomBlock.php
  • 31. Block Entities (theoretical) 31 DrupalCamp Kyiv 2013 block.block.bartik.search.yml block.block.bartik.about_this_site.yml block.block.bartik.random_number.yml
  • 32. Block Entities (practice) 32 DrupalCamp Kyiv 2013 sites/default/files/config_#HASH#/active/block.block.bartik.random_number_1.yml × 2 sites/default/files/config_#HASH#/active/block.block.bartik.random_number_2.yml sites/default/files/config_#HASH#/active/block.block.bartik.random_number_3.yml
  • 33. Hooks? 33 DrupalCamp Kyiv 2013 /** * Implements hook_form_FORM_ID_alter(). */ function ui_cache_clear_form_block_form_alter(&$form, $form_state) { $config_entity = $form_state['controller']->getEntity(); // Fieldset replaced by details. $form['cache_details'] = array( '#type' => 'details', '#title' => t('Cache settings'), ); // .. • Hooks are still here. • And there are new! ui_cache_clear.module
  • 35. Visualization API (8.x) 35 DrupalCamp Kyiv 2013 https://drupal.org/sandbox/Niremizov/1985870 Thx Christophe Van Gysel! Module features: • Theme hook • Plugin service (custom chart handlers) • Views Style Plugin
  • 36. Views 36 DrupalCamp Kyiv 2013 • Inside core and already works • Uses core Plugin System • Export/Import using Config Entities • Small API changes CamelCase hook_views_api, hook_views_plugin Tip: How to create default view in Drupal 8: Copy sitesdefaultfilesconfig_{HASH}activeconfigviews.view.{view_name}.yml Paste modules{module_name}configviews.view.{view_name}.yml
  • 37. Views Plugins 37 Drupal 7 Drupal 8 /** * Implements hook_views_plugins(). */ function vi..on_views_plugins() { return array( 'style' => array( 'visualization' => array( 'title' => t('Visualization'), 'type' => 'normal', 'theme' => 'visualization', // ... 'handler' => 'visualization_plugin_style', 'uses options' => TRUE, 'uses grouping' => FALSE, /* * @Plugin( * id = "visualization", * title = @Translation("Visualization"), * display_types = {"normal"} * theme = "visualization", * module = "visualization", * ) */ class Visualization extends StylePluginBase { protected $usesRowClass = TRUE; protected $usesGrouping = FALSE; protected $usesFields = TRUE; // ... } DrupalCamp Kyiv 2013
  • 38. PHPTemplate → Twig 38 DrupalCamp Kyiv 2013 {# core/modules/block/templates/block.html.twig #} <div{{ attributes }}> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} <div{{ content_attributes }}> {{ content }} </div> </div>
  • 39. DrupalCamp Kyiv 2013 KEEP CALM AND CLEAR CACHE And Drupal 8 says: — “Fatal error: Call to undefined function cache_clear_all()”
  • 40. Cache System Cache Tags instead of wildcards DrupalCamp Kyiv 2013 Cached Item 1 Tag 1 Tag 2 Tag 3 Cached Item 2 Tag 2 Cached Item 3 Tag 1 Tag 3 cache()->invalidateTags(array('Tag 2')); Cached Item 3 Tag 1 Tag 3 Cached Item 1 Tag 1 Tag 2 Tag 3 Cached Item 2 Tag 2 * Note: Drupal calculates “checksum” for every cache tag when read from cache! 40
  • 41. Cache System 41 DrupalCamp Kyiv 2013 // Set cache to 'page' bin. cache('page')->set($cid, $data, $expire, $tags); New Cache API // Truncate cache table. cache()->deleteAll(); // Marks cache items from all bins with 'content' tag as invalid. cache_invalidate_tags(array('content' => TRUE)); // Get multiple cache items. cache('field')->getMultiple($cids); // Get item even it is invalid. cache()->get('field:user:1', TRUE);
  • 42. Automated tests 42 DrupalCamp Kyiv 2013 namespace Drupalyandex_metricsTests; use DrupalsimpletestWebTestBase; class CounterTest extends WebTestBase { public static $modules = array('yandex_metrics'); public static function getInfo() { } public function setUp() { parent::setUp(); } public function tearDown() { } lib/Drupal/yandex_metrics/Tests/CounterTest.php
  • 43. Join #D8CX! Upgrade your module to Drupal 8 or help others!+ DrupalCamp Kyiv 2013
  • 44. References 44 DrupalCamp Kyiv 2013 • Change records for Drupal core http://drupal.org/list-changes • [May 22, 2013] Alex Bronstein (effulgentsia) - Upgrading your modules to Drupal 8 http://portland2013.drupal.org/session/upgrading-your-modules-drupal-8 • [Feb 8, 2013] Angie Byron (webchick) - Step-by-step: Converting modules from Drupal 7 to Drupal 8 http://webchick.net/node/118 • [Nov 4, 2012] Tim Plunkett (tim.plunkett) - D8CX: The Reckoning http://2012.badcamp.net/program/sessions/d8cx-reckoning
  • 45. ! DrupalCamp Kyiv 2013 Thank you for your attention! Konstantin Komelin @KKomelin konstantin@komelin.com Kate Marshalkina @kalabro marshalkina@licel.ru