DrupalCon Prague 2013

Actualizando tu código JavaScript para Drupal 8

Théodore Biadala  · 




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

well good afternoon I hope you're not too sleepy after lunch so I tried to make it quick for the actual interesting part so I'm going to talk about what you need to do as a module maintainer as a custom module writer to port your JavaScript from Drupal

7 to Drupal 8 as my name is to da ba da da I goodbye note on drupal.org I'm a JavaScript meant enough for Drupal core so I've been meant enough for a year and a half or something I'm also technical consultant with aquia so you know I'm not

just in the you I also know and see what's happening to project are not tight deadlines and the kind of horrible thing that happens during those times and and just before we start I just want to know a bit about how familiar you are because that's

a beginner session so who can write custom module yeah that's great who knows about render our ways that's great we knows about attached yeah well well done who knows about hook library yeah little bit less all right so i will need 10 minutes of your

time just pay attention at the new country so the first thing you need to do with your javascript do drupal 7 javascript is such and replace so you need to search for drupal that settings and replace that by drupal settings that's a global variable that

we use in Drupal 8 i'll go into the why afterwards but for now just bear with me search and replace second thing you need to search and replace is Drupal that same but prototype now it's just Drupada team so that might be a bit less common but surprise

c'mon a fairly uncommon one is when you implement custom each article back you need to implement the Drupal functor javascript function and usually it's under Drupal that Ajax that prototype that command but now it's under Drupal that Ajax commands

that prototype I mean they are several reason for that if you want to know I can go into it but not for now and for the JavaScript that's all you need to do and you JavaScript would work on Drupal 8 but for the PHP there's a few things that change

what we see usually in module is that you use Drupal at GS to put your script file on the page all that you use the scripts functionality of the info file these for Drupal 8 don't do that because that's going to be broken and actually right now in

Drupal 8 you can't insult a javascript file from the info file anymore we remove the functionality so what do you I mean what can you use to do that as you need to use attached so whenever you have an elemental form element r and r away that need some

javascript to walk well use attached to insert the javascript five with it and then the oop library in 2 / 7 is renamed to cook library info so for those who are not familiar with hook library this is what it looks like basically it just says my script needs

those other things to work so first you have the my script so that's the key you will be using to reference that in other places of the code so when you use attached for example then you say my script is this file it can be several files you can have CSS

files as well that depends that are included by your library and then you have the dependencies so this one I'm going to go back to it afterwards that's very very important in Drupal 7 the libraries you can suppose are available on the page are jquery

drupal drupal settings and jquery dot ones so when you declare you live with your library like that it's just like it was in Drupal 7 now bit more concrete example let's say I have a page that's a callback for some menu hook somewhere but not a

menu who can do polite but where do you get what I mean so that's in Drupal 7 I do drupal Jess my module past scripta Jess and boom my script is on the page but that you shouldn't be doing anymore because I'd bright several things why can't

I tell them if you want but I'm not going to go into details what you need to do now is declare the my module library info look say okay my javascript file is modulus square Jess my dependencies are jquery Drupal Drupal setting and decorate at once and

then in the my page function you are you would use attached with library and my module my script as so it's you know nested array is that very Drupal can't really go around that is everything clear so far all right now there's a patch to make this

a bit more user-friendly because writing PHP array that's not very fun we have your file and if this page gets in you will be able to declare your libraries in the y ml file so that's still science fiction for now but hopefully that will be you know

what will happen by the end of the week or two weeks maybe I mean if you want to fix that that'll sprint on friday so so the EML files would look like that so you have the my script and javascript dependencies same kind of thing we will move one array

[ ... ]

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