Your SlideShare is downloading. ×
Dev days Szeged 2014: Plugin system in drupal 8
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

Dev days Szeged 2014: Plugin system in drupal 8

276
views

Published on

Drupal dev days 2014 presentation in Szeged. …

Drupal dev days 2014 presentation in Szeged.
Plugin system in drupal 8.

This is the unchanged version of my slides.

Published in: Software

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
276
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Drupal 8 plugin system aspilicious!
  • 2. About me •  Bram Goffings @aspilicious •  Drupal developer •  Work for Nascom www.nascom.be •  Maintainer of Display Suite •  Drupal 8 core contributor
  • 3. Target audience •  Site builders & module developers •  Experience with module development •  Understanding of the hook system •  Know how to handle object oriented code
  • 4. Success? •  Nobody is scared anymore •  Everyone can make a *basic* plugin type
  • 5. Not the expert •  I’m an end user, just like you •  Learned by trying (and failing) •  I can say stupid things
  • 6. Drupal developer •  Mr. Steven •  Brave drupal 7 expert •  Made his first Drupal 8 site •  Wants to build a plugin system
  • 7. Client •  Mr. Arnold •  Rich webmaster •  Loves cars
  • 8. •  I want to choose my favorite car on my profile from a predefined list. •  It should be possible to plug in different cars into the list. •  The name and an image of the selected car should placed on the homepage.
  • 9. I take the job…
  • 10. Step 1 I want to choose my favorite car on my profile from a predefined list.
  • 11. Arnold’s wireframe
  • 12. Steven’s plan •  Add a “Car selector” field •  Create a custom select widget
  • 13. The drupal 7 way •  Implements hook_field_widget_info() •  Implements hook_field_widget_form()
  • 14. Those hooks are gone!
  • 15. They are plugin-y-fied!
  • 16. What is a plugin? Plugins are small pieces of functionality that are swappable. Plugins that perform similar functionality are of the same plugin type.
  • 17. Field widget plugins! •  There is a “widget” plugin type! •  Each field widget is from that type!
  • 18. Structure
  • 19. SelectWidget.php namespace DrupaloptionsPluginFieldFieldWidget;
  • 20. SelectWidget.php namespace DrupaloptionsPluginFieldFieldWidget;
  • 21. SelectWidget.php namespace DrupaloptionsPluginFieldFieldWidget;
  • 22. SelectWidget.php namespace DrupaloptionsPluginFieldFieldWidget;
  • 23. Namespaces •  Namespaces were introduced in PHP 5.3 •  Used to avoid name collisions
  • 24. PSR-0 •  Aims to provide a standard file, class and namespace convention to allow plug-and-play code. •  Uses the defined namespaces to automatically load files when needed. •  One on one mapping between namespaces and directory structure.
  • 25. SelectWidget.php namespace DrupaloptionsPluginFieldFieldWidget;
  • 26. Structure
  • 27. PSR-4 •  “New standard” •  Makes alternative mapping possible •  Drupal will use it to remove “unneeded” folders. The empty *drupal* and *module-name* folder won’t be needed anymore.
  • 28. Let’s recap •  We know how to find plugins •  We understand namespaces and the directory structure •  We understand PSR-0 and the difference between PSR-4
  • 29. SelectWidget.php
  • 30. Available methods
  • 31. Car module structure
  • 32. car.info.yml
  • 33. Step 1: done
  • 34. Let’s recap •  We know how to start with writing a field widget plugin •  We know how to start writing a custom module
  • 35. Step 2 It should be possible to plug in different cars into the list.
  • 36. Steven’s plan •  Create a custom plugin type named “Car” •  Create two sample car plugins
  • 37. Custom plugin type •  Create a plugin manager service record •  Create an annotation class •  Create the plugin manager class
  • 38. Custom plugin type
  • 39. car.services.yml
  • 40. Car module structure (part 2)
  • 41. Sample plugins
  • 42. Sample plugins
  • 43. getOptions() v2
  • 44. Debug output
  • 45. Car module structure (part 3)
  • 46. Let’s recap •  We know how to write a basic plugin manager •  We know how to handle annotations •  We know how to get all the plugin definitions
  • 47. Disadvantage Each car requires a plugin
  • 48. Derivative •  Allows you to create multiple plugin definitions through a single plugin class.
  • 49. Derivative example! •  Create a yml file containing cars! •  Create a derivative plugin! •  Create a definition for each car in the yml file!
  • 50. cars-example.yml
  • 51. YamlCar.php
  • 52. Step 2: done
  • 53. Let’s recap •  We know when to use derivatives •  We are able to build one
  • 54. Step 3 The name and an image of the selected car should placed on the homepage.
  • 55. Steven’s plan •  Add a function to the plugins that returns an image url •  Create the frontpage
  • 56. hook_menu is gone!
  • 57. car.routing.yml
  • 58. Car module structure (part 4)
  • 59. Let’s recap •  We figured out how to add a function to a plugin •  We know how to create a plugin instance •  We saw how we should create our routes •  We learned how to build a page controller
  • 60. The end
  • 61. Questions?
  • 62. THANK YOU!

×