Your SlideShare is downloading. ×
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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


Published on

Conference: DrupalCamp Kyiv 2013 …

Conference: DrupalCamp Kyiv 2013
Date: June 8, 2013
Speakers: Kate Marshalkina and Konstantin Komelin

Published in: Technology
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. #D8CXKate Marshalkina & Konstantin KomelinDrupalCamp Kyiv 2013 Start HereUpgrade your modulesto Drupal 8
  • 2. A Little More About Us2DrupalCamp 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 consultantKate Marshalkina kalabroKonstantin Komelin KKomelin
  • 3. What is Drupal 8?3DrupalCamp Kyiv 2013Drupal 8≠
  • 4. LOREM IPSUM DOLOREM COMPANY Insert You Tagline HereDrupal 8 — Drupal,even better!4
  • 5. Mobilesupport&inlineediting5DrupalCamp Kyiv 2013
  • 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 thatDrupal 8 is released.#D8CX: We pledge that Yandex.Metrics will have a full Drupal 8 release on the daythat Drupal 8 is released.#D8CX: I pledge that Yandex Services Authorization API will have a full Drupal 8release on the day that Drupal 8 is released.6DrupalCamp Kyiv 2013
  • 7. Why should I upgrade?7DrupalCamp 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?8DrupalCamp Kyiv 2013“In Villabajo they are still drilling the core and don’t have agreements aboutmany things, and in Villarriba others have already upgraded modules”D8 beginsMar 10, 2011Alpha1 RCDec, 2013BetaMay 20, 2013Drupal 8.0Sep-Oct, 2013July, 2013
  • 9. Our examples>DrupalCamp Kyiv 2013
  • 10. Yandex.Metrics (8.x)10DrupalCamp Kyiv 2013
  • 11. UI Cache Clear (7.x)11DrupalCamp Kyiv 2013
  • 12. UI Cache Clear (8.x)12DrupalCamp Kyiv 2013
  • 13. 13DrupalCamp Kyiv 2013New home for sites/all/*Drupal 7 Drupal 8A new folder structure
  • 14. Before you start14DrupalCamp Kyiv 2013• Update PHP to 5.3.10• Reconcile to o_OP• Get used to use• Be ready to reinstall Drupal• Prepare your rocket ;)
  • 15. Find 5 differences15DrupalCamp Kyiv 2013Drupal 7 Drupal 8name = Yandex.Metrics Countercore = 7.xfiles[] = yandex_metrics.testname: Yandex.Metrics Countercore: 8.xtype:
  • 16. 16Hurray!We’ve just upgraded the module!Thanks for coming!Goodbye :-P
  • 17. hook_menu and routing17DrupalCamp Kyiv 2013function yandex_metrics_menu() {$items[admin/config/system/yandex_metrics] = array(title => Yandex.Metrics,route_name => yandex_metrics_counter_settings,);// ...}yandex_metrics.moduleStep 2yandex_metrics_counter_settings:pattern: /admin/config/system/yandex_metricsdefaults:_form: Drupalyandex_metricsFormYandexMetricsCounterSettingsFormrequirements:_permission: administer Yandex.Metrics settingsyandex_metrics.routing.ymlStep 1
  • 18. Settings form18DrupalCamp Kyiv 2013namespace 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 form19DrupalCamp Kyiv 2013public 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.phpOverride methods that you need
  • 20. Configuration & State20DrupalCamp Kyiv 2013Variables (D7)Configuration (D8)State (D8)
  • 21. Configuration files21DrupalCamp Kyiv 2013yandex_metrics.settings:type: mappinglabel: Yandex.Metrics Counter settingsmapping:counter_code:type: stringlabel: Counter codeconfig/schema/yandex_merics.schema.ymlcounter_code: config/yandex_merics.settings.yml
  • 22. Config & State22DrupalCamp 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. Entities23DrupalCamp Kyiv 2013FieldableEntityNG (DX)Why: deployment, unificationIdea: ctools exportablesImplementation: plugins + ymlnewContent Entities Config EntitiesExamples:NodesTaxonomy termsUsersCommentsFilesMenu Links…Examples:Block instancesVocabulariesUser rolesViewsMenusDisplay ModesImage Styles…
  • 24. >DrupalCamp Kyiv 2013To be continued…
  • 25. #D8CXKate Marshalkina & Konstantin KomelinDrupalCamp Kyiv 2013 Continue HereUpgrade your modulesto Drupal 8Part 2
  • 26. Drupal 8 Plugins26DrupalCamp Kyiv 2013Why: extend them all!Idea: ctools, next generation.Implementation: classes, annotations.Examples:BlocksViewsEntitiesField Widgets/FormattersText Filters…That’s not a“Wordpress” plugin,guys :)
  • 27. Block Plugin (theoretical)27DrupalCamp Kyiv 2013
  • 28. Block Plugin (practice)28LOREM IPSUM DOLOREM COMPANY Insert You Tagline Here28namespace Drupalhello_worldPluginBlock;Now plugin will be foundautomatically!
  • 29. Block Plugin (practice)29DrupalCamp Kyiv 2013Annotations 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)30DrupalCamp Kyiv 2013Override methods that you needprotected 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)31DrupalCamp Kyiv
  • 32. Block Entities (practice)32DrupalCamp Kyiv 2013sites/default/files/config_#HASH#/active/block.block.bartik.random_number_1.yml× 2sites/default/files/config_#HASH#/active/block.block.bartik.random_number_2.ymlsites/default/files/config_#HASH#/active/block.block.bartik.random_number_3.yml
  • 33. Hooks?33DrupalCamp 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
  • 34. >DrupalCamp Kyiv 2013Views
  • 35. Visualization API (8.x)35DrupalCamp Kyiv 2013 Christophe Van Gysel!Module features:• Theme hook• Plugin service (customchart handlers)• Views Style Plugin
  • 36. Views36DrupalCamp Kyiv 2013• Inside core and already works• Uses core Plugin System• Export/Import using Config Entities• Small API changesCamelCasehook_views_api, hook_views_pluginTip: How to create default view in Drupal 8:Copy sitesdefaultfilesconfig_{HASH}activeconfigviews.view.{view_name}.ymlPaste modules{module_name}configviews.view.{view_name}.yml
  • 37. Views Plugins37Drupal 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 Visualizationextends StylePluginBase {protected $usesRowClass = TRUE;protected $usesGrouping = FALSE;protected $usesFields = TRUE;// ...}DrupalCamp Kyiv 2013
  • 38. PHPTemplate → Twig38DrupalCamp 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 2013KEEP CALMANDCLEAR CACHEAnd Drupal 8 says:— “Fatal error: Call to undefined function cache_clear_all()”
  • 40. Cache SystemCache Tags instead of wildcardsDrupalCamp Kyiv 2013Cached Item 1Tag 1Tag 2Tag 3Cached Item 2 Tag 2 Cached Item 3Tag 1Tag 3cache()->invalidateTags(array(Tag 2));Cached Item 3Tag 1Tag 3Cached Item 1Tag 1Tag 2Tag 3Cached Item 2 Tag 2*Note: Drupal calculates “checksum” for every cache tag when read from cache!40
  • 41. Cache System41DrupalCamp 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 tests42DrupalCamp Kyiv 2013namespace 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. References44DrupalCamp Kyiv 2013• Change records for Drupal core• [May 22, 2013] Alex Bronstein (effulgentsia) - Upgrading your modules toDrupal 8• [Feb 8, 2013] Angie Byron (webchick) - Step-by-step: Converting modulesfrom Drupal 7 to Drupal 8• [Nov 4, 2012] Tim Plunkett (tim.plunkett) - D8CX: The Reckoning
  • 45. !DrupalCamp Kyiv 2013Thank you for your attention!Konstantin Komelin@KKomelinkonstantin@komelin.comKate