DrupalCon Portland 2013

Un estudio detallado del sistema de plugins de Drupal

Kris Vanderwater, James Gilliland, Tim Plunkett, Alex Bronstein  · 


Extracto de la transcripción automática del vídeo realizada por YouTube.

okay how's that yeah all right so we're a couple minutes past we still got some people filing in here so we're just going to go ahead and get started and other people can catch up or whatever this is the Drupal 8 plugin deep dive session and so

very quickly we wanted to introduce ourselves I'm Chris Vander water I'm with Commerce guys lead up over there i'm also the initiative owner for the Drupal 8 blocks and layouts initiative all that everybody introduced themselves well I also do

James gilliland real quick he's not on the panel today because he couldn't make it to dribble con but he was going to if he had made it here I've left him up here because he was significant in the development of the plug-in system so he's still

up there great music hi I'm Alex Brownstein I'm a software engineer for aquia I work for octo or office of the CTO and that actually gives me a lot of time to work on Drupal 8 quart I'm Tim Plunkett I work at Stanford Graduate School of Business

as developer and I'm on the views and core team so I've got a handful of slides here that I'm just going to kind of walk through real quickly and this is an attempt at a visual explanation of what plugins really is I gave this same talk drupalcamp

dallas and it went really really long because i had definitions for everything so we're not going to do that we're going to talk about the Drupal like specific stuff here and then acknowledge what's really just like plain old PHP as Larry Garfield

says and will kind of take it from there our attempt here is probably going to be to spend like the first half telling you what this is and then maybe the last half doing question and answer and maybe showing some code examples or things like that so this

is very much designed to be an interactive session start getting your questions ready so really quickly will run just kind of a glossary of terms we have a whole bunch of things that we throw around when we start talking about about plugins and we have plugin

types and managers and discovery and factory and mappers and plugins themselves and all of this can be kind of daunting so I've tried to put it together into what I'm hoping will be a fairly concise visual representation of how this code flows and

we'll talk about it what really is specific to Drupal and what would have worked anywhere anyhow right so the first and really one of the most important things that we're going to talk about here is the manager the manager is a class it does some stuff

it does three major things and can be used as a really great place to attach various helper functions for your plug-in types if you dig through say the entity types manager it has all sorts of helpers on it for getting the controllers and various other things

like that one of the responsibilities of the managers to do discovery discovery is the clear Drupal ISM in what we're doing here Drupal has an awful lot of configurable pneus in it and plugins is really kind of an answer to that in many ways plugins is

defined like designed to replace what we've traditionally thought of as being info hooks so any sort of info hook that you might have in your own contribs in Drupal 8 yet and I'll get to that topic could likely be replaced with plugins so discoveries

job is to go out and discover plugins if you've ever implemented an info hook you functionally done what discovery is trying to do through a different mechanism and so there is this metadata out there which it finds and parses and brings back one way or

another there's some really cool stuff around metadata that tim has worked very very hard on and we'll show you that if we have time and what it's meant to do and how you can do some really cool stuff with it but for purposes of kind of the low-level

conversation that we've started here you know it's the info hook implementation and unlike the way previous versions of Drupal have done this where a single module might have many of these sitting in its info hook implementation each one of these generally

stands alone and we'll cover that topic a little bit as well you don't feel free to jump in on visit anytime once the meta data is returned back to discovery we have a methodology through which we can wrap decorators around the discovery mechanism

in the metadata that comes back we are in process of kind of disassembling some of those right now in favor of more direct establishment of what we want to happen inside the manager so a great example of this is who and here is used an ultra hook amen brother

okay yeah so yeah yeah exactly um so we have an alter decorator that takes all of the various collected in metadata and gives you an ultra hook for it and we're probably going to kill that before it's all out and you'll be able to just in your

manager do that and we're going to provide a default manager that does that and if you want to use it then great the default manager works for you another example of this might be cashing or derivatives which is a topic that we may lightly cover but this

this concept exists at least where we're likely to reduce it down as much as possible in favor of letting the manager handle most of that which means probably just derivatives as a decorator but we'll see what actually happens come release and then

we have a factory this again is the managers responsibility the the three things that will be close to the manager are all its responsibilities and the factory is really just plain old PHP who hears done enough oo that you've ever written a factory for

instantiating classes yeah this is it is exact same thing and so the manager can either use a factory class that exists where it can be a factory class itself I'm not going to get into that topic because it's mildly contentious but it can happen and

what happens from there is you instantiate a plug-in woohoo or perhaps multiple plugins and this is again plain old PHP we are just instantiating a class generally speaking all plugins of a type are instantiated the same way there are some plug-in types in

Drupal who code around this in certain ways we probably won't cover that topic unless some of those people are here and want to discuss it further but we will show you some examples of exactly how this happens and most importantly plugin and metadata for

virtually all not all but virtually all plugins in Drupal 8 right now those are the same class so the class that you are instantiating also has the metadata on it in the form of annotations okay and finally there's this thing called a mapper the mappers

really just business logic you can hand say an array of values to it and it can parse that array of values and determine which plugin configured how should be handed back to you and we do have an example of that actually in core at this point yeah it is we

have one that is actively used now archiver yeah I am gay chicks and so quick code example and we were really close to the end of my slides so we are going to be digging into questions real quick here um I have two managers here I just grabbed code snippets

from two different managers this one doesn't actually work this way if you look in head right now i reformatted it so that it would fit on my slide but this is the block manager and that is the entirety of the code in the block manager from class beginning

to class end it has one function that's the construct method wherein it sets the various discovery and discovery decorators it needs and sets the particular factory needs their methods implemented on the managers which are in the interface that do the

active discovery when you asked for it and do the class instantiation when you asked for it and mapping if you ever have need for that we aren't really going to cover that today but I want you to be aware that it exists and by contrast this is the archiver

manager it's a little bit larger it uses the create instance method here which you may or may not be able to read the font was a little bit smaller for this one because there's more code and it also has to get instance these are the two the two methods

that do factory instantiation and napping accordingly so with that there are a whole bunch of plugin managers in court on these are all but one of them excluding the test ones editors there's two editor managers and I didn't really feel like trying

to differentiate them on the screen but there are two and they're used for totally different things whoa the Edit module is what for inline editing and they're going to rename it the in-place editor module and the other ones editor which is for WYSIWYG

and yeah they both have the same quite they both have editor manager it's one of the more confusing things when you're debugging so they'll fix it but this is that's a good list so so we wrote this just the system actually like a year ago it

got in maybe at this point something like that and we had no clue whether core was really going to use it obviously core did and this actually this isn't even every plug-in type if we go through here views plugins and views handlers are to plug-in managers

that actually handle multiple plug-in types 22 it's a lot it's a double digit number which would like double what i have on screen here and so they did some interesting things there so that they only had to write one manager and they can get away with

some some cool stuff there so within all of these you have quite a list of cool stuff to kind of dig through and see how people went amended it not everybody implemented stuff the way I would have wanted them to but plenty are implemented very nicely and work

very well I'm sure contributing that make me unhappy too but who cares we have an awesome system so um with that I think yeah no no you're on this panel but you can't talk so there's also some that aren't on here yet like for example image

effects are not on this list but could be actions text filters text filters my name said yay I guess I didn't pull from head sorry so yes if anyone here is you know inspire to wanna kind of convert whatever is left in core that can use plugins that isn't

[ ... ]

Nota: se han omitido las otras 5.102 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.