1 of 27

desarrollo de módulos�en drupal 7

Miguel Manzano - @mmanzano�IRC: nesimo�http://mmanzano.com

-Basado en el trabajo de Rubén y Samuel-

Drupal Day Murcia 2015�#DDayMurcia2015

2 of 27

¿Quién Ha instalado alguna vez un cms?

Drupal Day Murcia 2015�#DDayMurcia2015

3 of 27

¿Quién Ha instalado alguna vez drupal 7?

Drupal Day Murcia 2015�#DDayMurcia2015

4 of 27

¿Quién Ha programado alguna vez?

Drupal Day Murcia 2015�#DDayMurcia2015

5 of 27

¿Quién Ha programado en php?

Drupal Day Murcia 2015�#DDayMurcia2015

6 of 27

¿Quién Ha programado en drupal?

Drupal Day Murcia 2015�#DDayMurcia2015

7 of 27

¿Qué vamos a ver?

Drupal Day Murcia 2015�#DDayMurcia2015

8 of 27

estándares - herramientas�organización ficheros�hooks - api render - API FORM - api database

contribuir

Drupal Day Murcia 2015�#DDayMurcia2015

9 of 27

¿ESTÁNDARES?

Drupal Day Murcia 2015�#DDayMurcia2015

  • Reglas sobre cómo escribir código

  • Legibilidad

  • Coder - https://www.drupal.org/project/coder

10 of 27

herramientas

Drupal Day Murcia 2015�#DDayMurcia2015

  • Devel - https://www.drupal.org/project/devel

  • Drush - https://github.com/drush-ops/drush

  • xDebug - http://xdebug.org/

11 of 27

Organización ficheros

Drupal Day Murcia 2015�#DDayMurcia2015

  • ¡Cuántas carpetas! y ¿Ahora qué?

  • Todo nuestro trabajo se va a desarrollar en:

sites/all/modules/custom

12 of 27

Organización ficheros

Drupal Day Murcia 2015�#DDayMurcia2015

  • La casa de los tres cerditos: /sites/all/modules/custom/mibicho
    • mibicho.info
    • mibicho.install
    • mibicho.module

13 of 27

mibicho.info

Drupal Day Murcia 2015�#DDayMurcia2015

name = Mi bicho

description = Mi primer bicho

core = 7.x

14 of 27

mibicho.module

Drupal Day Murcia 2015�#DDayMurcia2015

  • hooks

  • hooks

  • hooks

15 of 27

¿Hooks?

Drupal Day Murcia 2015�#DDayMurcia2015

  • ¿Cambiamos código del núcleo de Drupal?

  • Nos permiten interactuar con el núcleo

16 of 27

Hooks

Drupal Day Murcia 2015�#DDayMurcia2015

  • api.drupal.org -> Drupal 7

  • search -> hook

  • Código de ejemplo de implementación

17 of 27

creemos una ruta

hook_menu

Drupal Day Murcia 2015�#DDayMurcia2015

function mibicho_menu() {

$items = array();

$items[‘cerdito’] = array(

‘title’ => ‘Bienvenido a mi casita’,

‘page callback’ => ‘cerdito_page’,

);

return $items;

}

18 of 27

API RENDER

Drupal Day Murcia 2015�#DDayMurcia2015

function cerdito_page() {

$content = array();

$content[‘texto’] = array(

‘#type’ => ‘markup’,

‘#markup’ => ‘Hola y bienvenido a mi página’,

);

return $content;

}

19 of 27

API RENDER

Drupal Day Murcia 2015�#DDayMurcia2015

  • Drupal se encarga

  • Arrays rendereables

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7

20 of 27

FORM API

Drupal Day Murcia 2015�#DDayMurcia2015

  • Drupal se encarga ;P

  • drupal_get_form(‘nombre_formulario’)

  • Validación // submit

21 of 27

FORM API

Drupal Day Murcia 2015�#DDayMurcia2015

  • function nombre_formulario

  • Devuelve un array rendereable

22 of 27

FORM API

Drupal Day Murcia 2015�#DDayMurcia2015

  • function nombre_formulario_validate

  • form_set_error(‘campo’, t(‘mensaje’))

23 of 27

FORM API

Drupal Day Murcia 2015�#DDayMurcia2015

  • function nombre_formulario_submit

  • Sólo se llega aquí después de pasar validate sin errores

24 of 27

database API

Drupal Day Murcia 2015�#DDayMurcia2015

  • PHP Data Objects (PDO)

  • db_select
  • db_update // db_insert // db_merge
  • db_delete

25 of 27

mibicho.install

Drupal Day Murcia 2015�#DDayMurcia2015

  • hook_install

  • hook_schema

  • hook_update_N

26 of 27

Contribuir

Drupal Day Murcia 2015�#DDayMurcia2015

  • https://www.drupal.org/novice

  • https://drupalize.me/videos/getting-started-issue-queue

27 of 27

Muchas Gracias

Miguel Manzano - @mmanzano�IRC: nesimo�http://mmanzano.com

-Basado en el trabajo de Rubén y Samuel-

Drupal Day Murcia 2015�#DDayMurcia2015