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
Yet Another Drupal Development/Deployment Presentation
PPT
Are you ready for Drupal 8?
PDF
Drupal Best Practices
PPTX
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
PDF
Drupal upgrades and migrations. BAD Camp 2013 version
ODP
Conference Migrate to Drupal 8 by Leon Cros at Drupal Developer Days 2015 in ...
PDF
PDF
Evolution of Drupal and the Drupal community
Yet Another Drupal Development/Deployment Presentation
Are you ready for Drupal 8?
Drupal Best Practices
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
Drupal upgrades and migrations. BAD Camp 2013 version
Conference Migrate to Drupal 8 by Leon Cros at Drupal Developer Days 2015 in ...
Evolution of Drupal and the Drupal community

What's hot (20)

PDF
Migrate to Drupal 8
PDF
COSA SIGNIFICA CONVERTIRE UN MODULO DA D7 A D8
PDF
Drupal in-depth
PDF
[drupalday2017] - Decoupled frontend con Drupal 8 e OpenUI 5
PPTX
History of Drupal: From Drop 1.0 to Drupal 8
PDF
Drupal Migrations in 2018
PDF
Building and Maintaining a Distribution in Drupal 7 with Features
PDF
Drupal 6 to 7 migration guide
PDF
Drupal 8 Configuration Management
PPTX
Drupal 8 Vocabulary Lesson
PDF
10 New Things You Can Do with Drupal 8 Out-of-the-Box
PDF
Drupal 8 Configuration Management for you and your team
PDF
Introduction to Composer for Drupal
PDF
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
PPTX
Drupal core indeas - Andy Postnikov
PDF
[drupalday2017] - Devel - D8 release party
ODP
Drupal 7x Installation - Introduction to Drupal Concepts
PDF
The OpenEuropa Initiative
PDF
Collaborating with the Community
PDF
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017
Migrate to Drupal 8
COSA SIGNIFICA CONVERTIRE UN MODULO DA D7 A D8
Drupal in-depth
[drupalday2017] - Decoupled frontend con Drupal 8 e OpenUI 5
History of Drupal: From Drop 1.0 to Drupal 8
Drupal Migrations in 2018
Building and Maintaining a Distribution in Drupal 7 with Features
Drupal 6 to 7 migration guide
Drupal 8 Configuration Management
Drupal 8 Vocabulary Lesson
10 New Things You Can Do with Drupal 8 Out-of-the-Box
Drupal 8 Configuration Management for you and your team
Introduction to Composer for Drupal
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Drupal core indeas - Andy Postnikov
[drupalday2017] - Devel - D8 release party
Drupal 7x Installation - Introduction to Drupal Concepts
The OpenEuropa Initiative
Collaborating with the Community
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017

Viewers also liked (9)

PPTX
Presentation_Final_lowfatmilk
PPT
Next08 Real-Time Web – What Brands Can Learn from Street Musicans
 
PPT
139-000675-3
PPTX
139-000675-2
PPT
Marketing 2.0 – Influence Starts @ Home
 
PDF
Business Case Studies
PPTX
Atletismo
PPT
Calvin Crewe, 1933- 2016
PDF
دراسة تحليلية مقارنة لتأثير دور العمود فى ظل التقنيات الحديثة
Presentation_Final_lowfatmilk
Next08 Real-Time Web – What Brands Can Learn from Street Musicans
 
139-000675-3
139-000675-2
Marketing 2.0 – Influence Starts @ Home
 
Business Case Studies
Atletismo
Calvin Crewe, 1933- 2016
دراسة تحليلية مقارنة لتأثير دور العمود فى ظل التقنيات الحديثة

Similar to #D8 cx: upgrade your modules to drupal 8 (20)

PDF
Everything You Need to Know About the Top Changes in Drupal 8
PPTX
Top 8 Improvements in Drupal 8
PDF
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
PDF
Drupal training-by-ruchiwebsolutions
PDF
Building mobile applications with DrupalGap
PDF
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
PDF
Drupal 8: What's new? Anton Shubkin
PDF
Drupal Recipes: Building Image Galleries with jQuery and Flickr
ODP
Drupal Best Practices
ZIP
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
ODP
Drupal distributions - how to build them
PDF
Drupal Module Development
PDF
Drupal Module Development - OSI Days 2010
PPT
Taking your site from Drupal 6 to Drupal 7
PDF
Drupal 8 improvements for developer productivity php symfony and more
PPT
Overview Of Drupal
PPT
Overview Of Drupal
PDF
Making views - DrupalGov Canberra 2017
PDF
Building a Custom Theme in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
Top 8 Improvements in Drupal 8
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
Drupal training-by-ruchiwebsolutions
Building mobile applications with DrupalGap
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
Drupal 8: What's new? Anton Shubkin
Drupal Recipes: Building Image Galleries with jQuery and Flickr
Drupal Best Practices
Building a Drupal Distribution using Features, Drush Make, Installation Profi...
Drupal distributions - how to build them
Drupal Module Development
Drupal Module Development - OSI Days 2010
Taking your site from Drupal 6 to Drupal 7
Drupal 8 improvements for developer productivity php symfony and more
Overview Of Drupal
Overview Of Drupal
Making views - DrupalGov Canberra 2017
Building a Custom Theme in Drupal 8

More from DrupalCamp Kyiv Рысь (17)

PDF
Drupal association slides us 2013
PDF
Drupal association slides ru
PPTX
Game of-sales-presentation
PPT
Backbone js-slides
ODP
система управления конфигурацией в Drupal 8. анализ результатов изменений.
PPT
симфони это не страшно
PDF
ознакомления с модулем Entity api
PPT
Services в drupal 8
PPT
Erpal erp with drupal
PDF
Drupal 8 theming principles
PPT
Drupal 7 и history.js или как ajax инфицировать сайт
PPT
Cdn hosting решения для drupal (medium)
PPTX
Aegir. развертывание и управление большой сетью drupal сайтов
ODP
что нового в мире Services
Drupal association slides us 2013
Drupal association slides ru
Game of-sales-presentation
Backbone js-slides
система управления конфигурацией в Drupal 8. анализ результатов изменений.
симфони это не страшно
ознакомления с модулем Entity api
Services в drupal 8
Erpal erp with drupal
Drupal 8 theming principles
Drupal 7 и history.js или как ajax инфицировать сайт
Cdn hosting решения для drupal (medium)
Aegir. развертывание и управление большой сетью drupal сайтов
что нового в мире Services

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Digital-Transformation-Roadmap-for-Companies.pptx
Machine Learning_overview_presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Reach Out and Touch Someone: Haptics and Empathic Computing
Chapter 3 Spatial Domain Image Processing.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Machine learning based COVID-19 study performance prediction

#D8 cx: upgrade your modules to drupal 8

  • 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