Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Desarrollo de módulos para Drupal

4,808 views

Published on

Extracto de la descripción original del Codemotion:
Drupal es actualmente uno de los proyectos OpenSource más exitosos gracias a su numerosa comunidad y a lo increíblemente sencillo que es ampliar y personalizar la funcionalidad de la plataforma a traves de su sistema de módulos. Esta charla se plantea como una introducción a la arquitectura de Drupal y la creación de módulos exponiendo los recursos disponibles para hacerlo:

- Arquitectura Drupal.
- Drupal como sistema de Hooks y su manera de entender la "Inversión de Control"
- La documentación del desarrollador Drupal
- La API de Drupal
- Crear módulos a partir de "Examples module"

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • ..............ACCESS that WEBSITE Over for All Ebooks ................ ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ...................................ALL FOR EBOOKS................................................. Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Desarrollo de módulos para Drupal

  1. 1. Desarrollo de Módulos Drupal(con examples.module)Alessandro Mascherpa (@ALMADEWEB)alessandro@almadeweb.esAsiciación Española de Drupal Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 1 /29
  2. 2. Personal http://asociaciondrupal.es/• Desarrollador web freelance.• Administrador del grupo de usuarios de Drupal de Castellón, #DrupalCS: http://groups.drupal.org/castellon Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 2 /29
  3. 3. • Consideraciones previas• Arquitectura Drupal• Drupal como sistema de Hooks y su manera de entender la "Inversión de Control"• La documentación del desarrollador Drupal• La API de Drupal• Crear módulos a partir de "Examples module"• Referencias Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 3 /29
  4. 4. Consideraciones previas• Entorno de desarrollo – Apache (u otro http_server) – MySQL (u otro sist. de gestión de bases de datos) – PHP (o PHP) – IDE o editor para hacer código (según gustos): • http://drupal.cocomore.com/blog/using-eclipse-pdt-drupal-deve – Instalación de Drupal Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 4 /29
  5. 5. Consideraciones extras• Entorno de desarrollo II – Módulos auxiliares: coder, devel, devel_themer... – Drush: http://drupal.org/project/drush – GIT: http://drupal.org/node/711070• Coding standards Drupal – http://drupal.org/coding-standards• Conocer la comunidad Drupal y el workflow de desarrollo (issue queues,etc.)... Comprobar que lo que vayas a hacer no esté ya hecho Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 5 /29
  6. 6. Hooks: Inversión de control... Drupal-way El flujo habitual se da cuando es el código del usuario quien invoca a un procedimiento de una biblioteca. La inversión de control sucede cuando es la biblioteca la que invoca el código del usuario. Wikipedia http://martinfowler.com/bliki/InversionOfControl.html http://es.wikipedia.org/wiki/Inversi%C3%B3n_de_control• Drupal lo implementa mediate los patrones de diseño Observer y Visitor http://drupalwatchdog.com/1/1/design-patterns-of-drupal Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 6 /29
  7. 7. Arquitecturahttp://lin-clark.com/sites/default/files/sequence-diagram_get-field-types.png Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 7 /29
  8. 8. Documentación• Crear módulos para Drupal 7: http://drupal.org/node/1074360• Libros: https://www.packtpub.com/drupal-7-module-development/book• drupal.org, groups.drupal.org, IRC Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 8 /29
  9. 9. Drupal core API• User/Permissions/Node_access• DBTNG (PDO adaptado a Drupal) y SchemaAPI• MenuAPI• FormAPI• BlockAPI• Drupal Mail System Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 9 /29
  10. 10. Drupal core API• Entities, FieldAPI y Content• FileAPI• Theme System• JavaScript, AJAX y LibraryAPI• Perfiles de instalación• SimpleTest• Search System... Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 10 /29
  11. 11. Drupal contrib APIS• Views• EntityAPI• SearchAPI• Rules• Commerce• UserPoints, etc...• Drush Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 11 /29
  12. 12. Documentación de la API• Core: – http://api.drupal.org/ – Comentarios Doxygen: http://drupal.org/node/1354 – Descripciones, ejemplos y comentarios (en ocasiones): http://api.drupal.org/api/drupal/includes%21menu.inc/group/menu/7• Contrib: – http://drupalcontrib.org/api/drupal/7 – http://api.drush.org/api/functions – http://api.worldempire.ch/api/userpoints – http://api.drupalcommerce.org/ Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 12 /29
  13. 13. Estructura de un módulo• sites/{all o misite}/modules/{custom/}mi_modulo• Tiene seguro – .info – .module• Muy probable que tenga también – .install – .tests• Podría tener varios .inc, .css, .js ... Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 13 /29
  14. 14. User/Permissions/Node_access• Administración de usuarios, roles y permisos• Control de acceso• hook_permission Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 14 /29
  15. 15. hook_permisionfunction node_access_example_permission() { return array( access codemotion table => array( title => t(Access codemotion table), description => t(May view the table withde results of codemotion_example table.), ), );} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 15 /29
  16. 16. Menu System• Sistema de routing de Drupal (maneja la url)• Mantenimiento y consulta de datos relativos a los menús del sistema• Renderizado de menús• Diferentes tipos de menú según donde se muestre el enlace (si se muestra)• Control de acceso incluido• hook_menu() y hook_menu_alter Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 16 /29
  17. 17. hook_menu (menu_example)function codemotion_menu() { $items[codemotion/table] = array( title => TableSort example, description => Page with a sortable table, page callback =>codemotion_tablesort_example_page, access arguments => array(access codemotiontable), type => MENU_NORMAL_ITEM, menu_name => main-menu, ); return $items;} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 17 /29
  18. 18. Renderizando una página (tablesort_example)function codemotion_tablesort_example_page() { $header = array( array(data => t(Numbers), field => t.numbers), array(data => t(Letters), field => t.alpha), array(data => t(Mixture), field => t.random), ); $query = db_select(codemotion_example, t)->extend(TableSort); $query->fields(t); $result = $query->orderByHeader($header)->execute(); $rows = array(); foreach ($result as $row) {$rows[] = array(data => (array) $row);} $build[tablesort_table] = array( #theme => table, #header => $header, #rows => $rows, ); return $build;} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 18 /29
  19. 19. SchemaAPI• Capa de abstracción de la base de datos basada en PDO• Muchos plugins• Definición del schema de datos• Hooks para definir operaciones durante instalación y desinstalación de módulos• Hooks para definir operaciones durante activación y desactivación de módulos Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 19 /29
  20. 20. hook_schema (dbtng_example)function codemotion_schema() { $schema[codemotion_example] = array( description => Stores some values for sorting fun., fields => array( numbers => array(description => This column, type => varchar,length => 10,not null => TRUE, ), random => array( description => This column simply holds random, type => varchar,length => 128,not null => TRUE, ), ), primary key => array(numbers), ); return $schema;} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 20 /29
  21. 21. hook_install y hook_uninstall (dbtng_example)function codemotion_install() { $rows = array( array(numbers => 1, alpha => e, random => 912cv21), array(numbers => 2, alpha => a, random => 0kuykuh), array(numbers => 4, alpha => w, random => 80jsv772), array(numbers => 6, alpha => s, random => au832), array(numbers => 7, alpha => e, random => t982hkv), ); if (db_table_exists(codemotion_example)) { foreach ($rows as $row) { db_insert(codemotion_example)->fields($row)->execute(); } }} function codemotion_uninstall() { db_drop_table(codemotion_example); } Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 21 /29
  22. 22. FormAPI• Definir formularios a traves de arrays asociativos dentro de la función miform_form• Renderizar formularios: drupal_get_form()• Form validation: miform_form_validate• Form submision: miform_form_submit• hook_form_alter Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 22 /29
  23. 23. _for (form_example)function form_codemotion_form($form, &$form_state) { $form[alpha] = array( #type => select, #title => t(Other value), #options => array(web => t(Web),hello=>t(Hello)), ); $form[random] = array( #type => textarea, #title => t(What standardized tests did you take?), #default_value => Un poco de random?, ); $form[submit] = array( #type => submit, #value => Enviar, ); return $form;} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 23 /29
  24. 24. _form_validate y _form_submitfunction form_codemotion_form_validate($form, &$form_state) { if(!is_numeric($form_state[values][numbers])) { form_set_error(numbers, t(Numbers must be a number)); }}function form_codemotion_form_submit($form, &$form_state) { drupal_set_message(t(MyVal: @values,array(@values=>$form_state[values][myvalue]))); $row = array(numbers => $form_state[values][numbers], ...); db_insert(codemotion_example)->fields($row)->execute(); codemotion_mail_send($form_state[values]);} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 24 /29
  25. 25. Blocks• Fragmentos de contenido.• Se pueden distribuir en cualquier región definida en el tema a traves de la UI• Definidos con hook_block_info• Renderizados con hook_block_view• Otros hooks para modificar el comportamiento de los existentes en otros módulos Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 25 /29
  26. 26. hook_block_info (block_example)function codemotion_block_info() { $blocks[codemotion] = array( info => t(Codemotion Data), status => TRUE, region => sidebar_first, visibility => BLOCK_VISIBILITY_LISTED, pages => node/*, ); $blocks[codemotiontext] = array( info => t(Codemotion Text), ); return $blocks;} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 26 /29
  27. 27. hook_block_view (block_example)/** * Implements hook_block_view(). */function codemotion_block_view($delta = ) { switch ($delta) { case codemotion: $block[subject] = t(Codemotion Data Block); $block[content] = codemotion_tablesort_example_page(); break; case codemotiontext: $block[codemotiontext] = codemotiontext; break; } return $block;} Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 27 /29
  28. 28. A partir de aquí... http://groups.drupal.org/madridhttp://2012.drupalday.es Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 28 /29
  29. 29. ¿Preguntas? ...… comentarios ...… críticas ... Gracias :) Alessandro Mascherpa @ALMADEWEB Alessandro Mascherpa (@ALMADEWEB) alessandro@almadeweb.es – Asociación Española de Drupal 29 /29

×