• Save
#D8 cx: upgrade your modules to drupal 8
Upcoming SlideShare
Loading in...5
×
 

#D8 cx: upgrade your modules to drupal 8

on

  • 2,562 views

 

Statistics

Views

Total Views
2,562
Views on SlideShare
2,065
Embed Views
497

Actions

Likes
8
Downloads
0
Comments
0

3 Embeds 497

http://camp13.drupal.ua 434
https://twitter.com 62
http://drupalcamp35.rssing.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

#D8 cx: upgrade your modules to drupal 8 #D8 cx: upgrade your modules to drupal 8 Presentation Transcript

  • #D8CXKate Marshalkina & Konstantin KomelinDrupalCamp Kyiv 2013 Start HereUpgrade your modulesto Drupal 8
  • 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
  • What is Drupal 8?3DrupalCamp Kyiv 2013Drupal 8≠
  • LOREM IPSUM DOLOREM COMPANY Insert You Tagline HereDrupal 8 — Drupal,even better!4
  • Mobilesupport&inlineediting5DrupalCamp 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 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
  • 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 ;)
  • 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
  • Our examples>DrupalCamp Kyiv 2013
  • Yandex.Metrics (8.x)10DrupalCamp Kyiv 2013
  • UI Cache Clear (7.x)11DrupalCamp Kyiv 2013
  • UI Cache Clear (8.x)12DrupalCamp Kyiv 2013
  • 13DrupalCamp Kyiv 2013New home for sites/all/*Drupal 7 Drupal 8A new folder structure
  • Before you start14DrupalCamp 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 differences15DrupalCamp Kyiv 2013Drupal 7 Drupal 8name = Yandex.Metrics Countercore = 7.xfiles[] = yandex_metrics.testname: Yandex.Metrics Countercore: 8.xtype: moduleyandex_metrics.info yandex_metrics.info.yml
  • 16Hurray!We’ve just upgraded the module!Thanks for coming!Goodbye :-P
  • 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
  • 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().
  • 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
  • Configuration & State20DrupalCamp Kyiv 2013Variables (D7)Configuration (D8)State (D8)
  • 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
  • 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
  • Entities23DrupalCamp Kyiv 2013FieldableEntityNG (DX)Why: deployment, unificationIdea: ctools exportablesImplementation: plugins + ymlnewContent Entities Config EntitiesExamples:NodesTaxonomy termsUsersCommentsFilesMenu Links…Examples:Block instancesVocabulariesUser rolesViewsMenusDisplay ModesImage Styles…
  • >DrupalCamp Kyiv 2013To be continued…
  • #D8CXKate Marshalkina & Konstantin KomelinDrupalCamp Kyiv 2013 Continue HereUpgrade your modulesto Drupal 8Part 2
  • 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 :)
  • Block Plugin (theoretical)27DrupalCamp Kyiv 2013
  • Block Plugin (practice)28LOREM IPSUM DOLOREM COMPANY Insert You Tagline Here28namespace Drupalhello_worldPluginBlock;Now plugin will be foundautomatically!
  • 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
  • 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
  • Block Entities (theoretical)31DrupalCamp Kyiv 2013block.block.bartik.search.ymlblock.block.bartik.about_this_site.ymlblock.block.bartik.random_number.yml
  • 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
  • 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
  • >DrupalCamp Kyiv 2013Views
  • Visualization API (8.x)35DrupalCamp Kyiv 2013https://drupal.org/sandbox/Niremizov/1985870Thx Christophe Van Gysel!Module features:• Theme hook• Plugin service (customchart handlers)• Views Style Plugin
  • 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
  • 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
  • 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>
  • DrupalCamp Kyiv 2013KEEP CALMANDCLEAR CACHEAnd Drupal 8 says:— “Fatal error: Call to undefined function cache_clear_all()”
  • 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
  • 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);
  • 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
  • Join #D8CX!Upgrade your module to Drupal 8 or help others!+DrupalCamp Kyiv 2013
  • References44DrupalCamp Kyiv 2013• Change records for Drupal corehttp://drupal.org/list-changes• [May 22, 2013] Alex Bronstein (effulgentsia) - Upgrading your modules toDrupal 8http://portland2013.drupal.org/session/upgrading-your-modules-drupal-8• [Feb 8, 2013] Angie Byron (webchick) - Step-by-step: Converting modulesfrom Drupal 7 to Drupal 8http://webchick.net/node/118• [Nov 4, 2012] Tim Plunkett (tim.plunkett) - D8CX: The Reckoninghttp://2012.badcamp.net/program/sessions/d8cx-reckoning
  • !DrupalCamp Kyiv 2013Thank you for your attention!Konstantin Komelin@KKomelinkonstantin@komelin.comKate Marshalkina@kalabromarshalkina@licel.ru