SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
Desarrolladores:
Bienvenidos a Drupal 7
Drupalcamp Spain 2011, Sevilla 1-2 Octubre
Sobre mí
●   Desarrollador Drupal
    en Commerce Guys.
●   Miembro hiperactivo
    de la comunidad
    drupalera de habla     Pedro Cambra
                            @pcambra
    hispana.
Drupal 7
Drupal 7 incorpora gran cantidad de novedades a
nivel de diseño, usabilidad pero quizás el mayor
 cambio que se ha producido entre las versiones
          6x y 7x es a nivel desarrollo.
Entidades en Core
 Las entidades en Drupal añaden una nueva
capa de abstracción basada en objetos sobre
los datos que permite que todo el contenido
comparta API y workflow.

 Nodos, usuarios, términos de taxonomía,
vocabularios, comentarios, ficheros... son ahora
entidades
Entidades en Core

 “Everything is a node”
           vs
“Nodes are entities too”
Ejemplo #1: Entity Controllers
class CommerceProductEntityController extends
DrupalCommerceEntityController {
(..)
  public function create(array $values = array()) {
     return (object) ($values + array(
       'product_id' => '',
       'is_new' => TRUE,
       'sku' => '',
       'title' => '',
       'uid' => '',
       'status' => 1,
       'created' => '',
       'changed' => '',
     ));
  }
(..)
}
Ejemplo #2: EntityFieldQuery
function
commerce_product_reference_commerce_product_can_delete($product) {
  // Use EntityFieldQuery to look for line items referencing this
  // product and do not allow the delete to occur if one exists.
  $query = new EntityFieldQuery();

    $query
      ->entityCondition('entity_type', 'commerce_line_item', '=')
      ->entityCondition('bundle', 'product', '=')
      ->fieldCondition('product', 'product_id',
           $product->product_id, '=')
      ->count();

    return $query->execute() > 0 ? FALSE : TRUE;
}
Entity API
●   El módulo Entity API se crea para facilitar el
    acceso a las entidades y para rellenar los
    huecos que le faltan al core de Drupal.
●   Añade elementos muy interesantes como
    propiedades, exportables, interfaz de
    administración o los metadata wrappers
●   También proporciona un controlador de CRUD
    estándar para la mayoría de entidades.
Ejemplo#1: Entity Metadata Wrapper
function commerce_line_items_quantity($line_items, $type = '') {
  // Sum up the quantity of all matching line items.
  $quantity = 0;

    foreach ($line_items as $line_item) {
      if (!is_a($line_item, 'EntityMetadataWrapper')) {
        $line_item = entity_metadata_wrapper('commerce_line_item',
            $line_item);
      }

        if (empty($type) || $line_item->type->value() == $type) {
          $quantity += $line_item->quantity->value();
        }
    }

    return $quantity;
}
Ejemplo#2: Entity Properties
/**
 * Implements hook_entity_property_info().
 */
function commerce_product_entity_property_info() {
  $info = array();

  // Add meta-data about the basic commerce_product properties.
  $properties = &$info['commerce_product']['properties'];
(..)
  $properties['sku'] = array(
     'label' => t('SKU'),
     'description' => t('The human readable product SKU.'),
     'type' => 'text',
     'setter callback' => 'entity_property_verbatim_set',
     'required' => TRUE,
     'schema field' => 'sku',
  );
Field API
●   Parte del módulo CCK se ha refactorizado y es
    ahora el Field API de Drupal 7.
●   Los nuevos campos generados por Field API se
    pueden adjuntar a cualquier entidad que tenga
    la propiedad fieldable.
●   Se ha facilitado en gran medida la forma de
    crear campos personalizados y se han añadido
    y estandarizado gran cantidad de nuevas
    opciones.
Extendiendo Field API
Field API incorpora gran cantidad de hooks,
ejemplos curiosos:
●   hook_field_attach_* - controlan los formularios y
    acciones cuando un campo se adjunta a una
    entidad (y operaciones CRUD).
●   hook_field_storage_* - controlan la forma en la que
    se almacena el campo (NoSQL?)
●   hook_field_extra_fields* - Permiten exponer
    “pseudo campos” en las entidades.
Form API
●   #states                    ●   Vertical Tabs
●   #ajax                      ●   machine_name
●   #attached                  ●   tableselect
●   hook_form_alter()          ●   managed_file
    desde plantilla            ●   Elementos HTML5 a
●   #title_display                 través del módulo
●   #limit_validation_errors       Elements
Ejemplo: #attached & Vertical Tabs
  $form['additional_settings'] = array(
     '#type' => 'vertical_tabs',
     '#weight' => 99,
  );
(..)
  // Add a section to update the status and leave a log message.
  $form['order_status'] = array(
     '#type' => 'fieldset',
     '#title' => t('Order status'),
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
     '#group' => 'additional_settings',
     '#attached' => array(
       'js' => array(
         drupal_get_path('module', 'commerce_order') . '/commerce_order.js',
         array(
            'type' => 'setting',
            'data' => array('status_titles' => commerce_order_status_get_title()),
         ),
       ),
     ),
     '#weight' => 20,
  );
DBTNG
El proyecto DBTNG ha reformado la capa de abstracción
de Drupal para acercarla a un modelo OOP.
 $result = db_query("SELECT n.nid, u.name
                     FROM {node} n
                     WHERE n.type = '%s'
                     AND n.status = %d",
                                            Drupal 6
           array('page', 1));

  $product_count = db_select('commerce_product', 'cp')
    ->fields('cp', array('product_id'))
    ->countQuery()
    ->execute()
                                               Drupal    7
    ->fetchField();
Render arrays
Los render arrays son los elementos utilizados
a partir de Drupal 7 para construir las páginas.
Estos elementos proporcionan una flexibilidad
enorme y dan la posibilidad de alterar cómo se
generan las páginas con la misma facilidad que
alteramos un formulario.
Novedad: hook_page_alter().
Ejemplo: render arrays
$note = array(
   '#title' => t('Render Array Example'),
   '#items' => $items,
   // The functions in #pre_render get to alter the actual data before it
   // gets rendered by the various theme functions.
   '#pre_render' => array('render_example_change_to_ol'),
   // The functions in #post_render get both the element and the rendered
   // data and can add to the rendered data.
   '#post_render' => array('render_example_add_hr'),
   // The #theme theme operation gets the first chance at rendering the
   // element and its children.
   '#theme' => 'item_list',
   // Then the theme operations in #theme_wrappers can wrap more around
   // what #theme left in #chilren.
   '#theme_wrappers' => array('render_example_add_div',
                                'render_example_add_notes'),
   '#weight' => -9999,
);
$page['sidebar_first']['render_array_note'] = $note;
$page['sidebar_first']['#sorted'] = FALSE;
Cache
  ●   Se introduce drupal_static() que reemplaza la
      llamada PHP 'static'.
  ●   Integración con los render arrays:
    t('cache demonstration') => array(
       '#markup' => t('The current time was %time when this was cached. Updated every
%interval seconds', array('%time' => date('r'), '%interval' => $interval)),
       '#cache' => array(
          'keys' => array('render_example', 'cache', 'demonstration'),
          'bin' => 'cache',
          'expire' => time() + $interval,
          'granularity' => DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE,
       ),
    ),

                      http://www.lullabot.com/articles/beginners-guide-caching-data-drupal-7
Novedades Js
    Drupal 7 incorpora muchas novedades técnicas
    para fomentar la flexibilidad y control del
    javascript en nuestros proyectos.
●   drupal_add_js() permite peso y ficheros
    externos.
●   hook_js_alter()
●   Jquery 1.4.4 y jQuery UI 1.8
●   Mejoras en los behaviors.
Ejemplo js
$form['attributes'][$field_name] = array(
   '#type' => 'select',
   '#title' => check_plain($data['instance']['label']),
   '#options' => array_intersect_key($data['options'],
          drupal_map_assoc($used_options[$field_name])),
   '#default_value' => $default_product_wrapper->{$field_name}
          ->value(),
   '#weight' => $data['instance']['widget']['weight'],
   '#ajax' => array(
       'callback' =>
          'commerce_cart_add_to_cart_form_attributes_refresh',
              ),
);
File API
    El nuevo interfaz de ficheros de Drupal 7
    permite acceder a cualquier recurso como si
    fuera un fichero.
●   Introducción de streams: public:// private://
    temporary://
●   file_unmanaged_* (copy, move, delete) permite
    tratar ficheros sin grabarlos en base de datos.
Code registry
En Drupal 7 se introduce el registro de
código, para inventariar los ficheros y clases
que se deben cargar en cada momento.
El único fichero que se carga automáticamente
es el .module, el resto de ficheros, plugins,
includes, tests, etc... deben declararse en el
array files[] del fichero .info.
info files
●   Se pueden añadir css y js usando las propiedades
    stylesheets y scripts.
●   La propiedad files fuerza el auto load de los ficheros
    declarados.
●   dependencies soporta versiones.
●   La propiedad configure expone el path de configuración
    del módulo
●   required fuerza que un módulo o theme sea obligatorio y
    no pueda ser deshabilitado
                                             http://drupal.org/node/542202
Queue API
Drupal 7 incorpora una nueva API para
gestionar colas basada en objetos.
Varios componentes del core como Aggregator,
Batch API o Cron ya la implementan de base.
Permite guardar los elementos en memoria o
en base de datos, y es totalmente configurable
según el caso de uso que necesitemos.
                 http://www.slideshare.net/philipnorton42/drupal-7-queues
Ejemplo queue
$queue = DrupalQueue::get('tofu_sandwich');
$queue->createQueue(); // no-op.
$things = array('bread', 'tofu', 'provolone', 'sprouts');
foreach ($things as $item) {
  $queue->createItem($item);
}

$items = array();
while ($item = $queue->claimItem()) {
  $message .= $item->item_id . ':' . $item->data    . '; ';
  $items[] = $item;
}
drupal_set_message('Queue contains: ' . check_plain($message));
foreach ($items as $item) {
  $queue->releaseItem($item);
}

                             http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
Cambios en Schema
A partir de Drupal 7, declarar hook_schema en
el fichero .install es suficiente para instalar y
desinstalar tablas en la base de datos, no hay
que hacerlo explícitamente con hook_install y
hook_uninstall.
hook_field_schema() se encarga de los
esquemas de datos para campos.

http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_schema/7
Simpletest en core
●   Drupal 7 incorpora el módulo Simpletest en su
    núcleo y tiene unit testing e integration
    testing en todos los componentes por defecto.
●   Tener los elementos verificados proporciona
    seguridad y calidad en los componentes.
    http://drupal.org/simpletest-tutorial-drupal7
Libros   ¡Recomendado!
¿Preguntas?
●   @pcambra
●   cambrico.net
●   Perfil en Drupal.org
We're hiring!
¡Muchas gracias!

Mais conteúdo relacionado

Mais procurados

Funciones store proc_triggers
Funciones store proc_triggersFunciones store proc_triggers
Funciones store proc_triggers
Luis Jherry
 
Desarrollando aplicaciones web usando Catalyst y jQuery
Desarrollando aplicaciones web usando Catalyst y jQueryDesarrollando aplicaciones web usando Catalyst y jQuery
Desarrollando aplicaciones web usando Catalyst y jQuery
Javier P.
 
IntroduccióN A Sql Server 2005
IntroduccióN A Sql Server 2005IntroduccióN A Sql Server 2005
IntroduccióN A Sql Server 2005
oswchavez
 

Mais procurados (20)

Web2py: Pensando en grande
Web2py: Pensando en grandeWeb2py: Pensando en grande
Web2py: Pensando en grande
 
J query
J queryJ query
J query
 
53 Php. Clases Y Objetos
53 Php. Clases Y Objetos53 Php. Clases Y Objetos
53 Php. Clases Y Objetos
 
Java beans en jsp
Java beans en jspJava beans en jsp
Java beans en jsp
 
Entidades en drupal 8
Entidades en drupal 8Entidades en drupal 8
Entidades en drupal 8
 
El Mal Odiado Javascript
El Mal Odiado JavascriptEl Mal Odiado Javascript
El Mal Odiado Javascript
 
Funciones store proc_triggers
Funciones store proc_triggersFunciones store proc_triggers
Funciones store proc_triggers
 
Entidades en drupal 8
Entidades en drupal 8Entidades en drupal 8
Entidades en drupal 8
 
Desarrollo de aplicaciones web usando Catalyst y jQuery
Desarrollo de aplicaciones web usando Catalyst y jQueryDesarrollo de aplicaciones web usando Catalyst y jQuery
Desarrollo de aplicaciones web usando Catalyst y jQuery
 
PHP - MYSQL
PHP - MYSQLPHP - MYSQL
PHP - MYSQL
 
08 i18 n
08 i18 n08 i18 n
08 i18 n
 
Presentación charla puppet madrid devops 2012
Presentación charla puppet madrid devops 2012Presentación charla puppet madrid devops 2012
Presentación charla puppet madrid devops 2012
 
Desarrollando aplicaciones web usando Catalyst y jQuery
Desarrollando aplicaciones web usando Catalyst y jQueryDesarrollando aplicaciones web usando Catalyst y jQuery
Desarrollando aplicaciones web usando Catalyst y jQuery
 
Wp config.php
Wp config.phpWp config.php
Wp config.php
 
Clase 6 objetos de javaScript
Clase 6 objetos de javaScriptClase 6 objetos de javaScript
Clase 6 objetos de javaScript
 
P2C2 Introducción a JEE5
P2C2 Introducción a JEE5P2C2 Introducción a JEE5
P2C2 Introducción a JEE5
 
Clase 7 objetos globales de javaScript
Clase 7 objetos globales de javaScriptClase 7 objetos globales de javaScript
Clase 7 objetos globales de javaScript
 
IntroduccióN A Sql Server 2005
IntroduccióN A Sql Server 2005IntroduccióN A Sql Server 2005
IntroduccióN A Sql Server 2005
 
Clase 5 funciones en javaScript
Clase 5 funciones en javaScriptClase 5 funciones en javaScript
Clase 5 funciones en javaScript
 
Clase 15
Clase 15Clase 15
Clase 15
 

Destaque

Further Resources - Drupal training
Further Resources - Drupal trainingFurther Resources - Drupal training
Further Resources - Drupal training
Pedro Cambra
 
Contributions: what they are and how to find them
Contributions: what they are and how to find themContributions: what they are and how to find them
Contributions: what they are and how to find them
Pedro Cambra
 
Distribuciones drupal
Distribuciones drupalDistribuciones drupal
Distribuciones drupal
Pedro Cambra
 

Destaque (18)

DrupalCommerce Lisbon presentation
DrupalCommerce Lisbon presentationDrupalCommerce Lisbon presentation
DrupalCommerce Lisbon presentation
 
Mainstreaming the Disruption: Up-skilling for Online Learning
Mainstreaming the Disruption: Up-skilling for Online LearningMainstreaming the Disruption: Up-skilling for Online Learning
Mainstreaming the Disruption: Up-skilling for Online Learning
 
Further Resources - Drupal training
Further Resources - Drupal trainingFurther Resources - Drupal training
Further Resources - Drupal training
 
Movie making
Movie makingMovie making
Movie making
 
Drupal Commerce: A perfect match for your e-commerce needs
Drupal Commerce: A perfect match for your e-commerce needsDrupal Commerce: A perfect match for your e-commerce needs
Drupal Commerce: A perfect match for your e-commerce needs
 
Contributions: what they are and how to find them
Contributions: what they are and how to find themContributions: what they are and how to find them
Contributions: what they are and how to find them
 
Community Engagement and Social-Ecological Resilience: How You Choose to Live...
Community Engagement and Social-Ecological Resilience: How You Choose to Live...Community Engagement and Social-Ecological Resilience: How You Choose to Live...
Community Engagement and Social-Ecological Resilience: How You Choose to Live...
 
Strategic Thinking for Sustainable Enterprise
Strategic Thinking for Sustainable EnterpriseStrategic Thinking for Sustainable Enterprise
Strategic Thinking for Sustainable Enterprise
 
Introduction to drupal
Introduction to drupalIntroduction to drupal
Introduction to drupal
 
The Indian International University 2017: A Retrospective
The Indian International University 2017: A RetrospectiveThe Indian International University 2017: A Retrospective
The Indian International University 2017: A Retrospective
 
The democratisation of education: Will technology live up to the promise?
The democratisation of education: Will technology live up to the promise?The democratisation of education: Will technology live up to the promise?
The democratisation of education: Will technology live up to the promise?
 
Import and synchronize Drupal commerce content using Commerce feeds
Import and synchronize Drupal commerce content using Commerce feedsImport and synchronize Drupal commerce content using Commerce feeds
Import and synchronize Drupal commerce content using Commerce feeds
 
Are you a life-long learner?
Are you a life-long learner?Are you a life-long learner?
Are you a life-long learner?
 
The MOOC Phenomenon: What Does it Mean for Business Schools?
The MOOC Phenomenon: What Does it Mean for Business Schools?The MOOC Phenomenon: What Does it Mean for Business Schools?
The MOOC Phenomenon: What Does it Mean for Business Schools?
 
Distribuciones drupal
Distribuciones drupalDistribuciones drupal
Distribuciones drupal
 
Drupal Commerce contributed modules overview
Drupal Commerce contributed modules overviewDrupal Commerce contributed modules overview
Drupal Commerce contributed modules overview
 
SAIBSA keynote
SAIBSA keynoteSAIBSA keynote
SAIBSA keynote
 
The Discourse on Quality in Early Childhood Education: What Can We Agree On?
The Discourse on Quality in Early Childhood Education: What Can We Agree On?The Discourse on Quality in Early Childhood Education: What Can We Agree On?
The Discourse on Quality in Early Childhood Education: What Can We Agree On?
 

Semelhante a Drupal7 para desarrolladores

Informe grupal f_arinango_ cuenca
Informe grupal f_arinango_ cuencaInforme grupal f_arinango_ cuenca
Informe grupal f_arinango_ cuenca
paulcuenca9
 

Semelhante a Drupal7 para desarrolladores (20)

Drupal 7 a través Drupal Commerce
Drupal 7 a través Drupal CommerceDrupal 7 a través Drupal Commerce
Drupal 7 a través Drupal Commerce
 
Jquery parte 1
Jquery parte 1Jquery parte 1
Jquery parte 1
 
9.laravel
9.laravel9.laravel
9.laravel
 
Presentacion YII
Presentacion YIIPresentacion YII
Presentacion YII
 
Jquery para principianes
Jquery para principianesJquery para principianes
Jquery para principianes
 
J M E R L I N P H P
J M E R L I N P H PJ M E R L I N P H P
J M E R L I N P H P
 
El universo JavaScript en Drupal 7
El universo JavaScript en Drupal 7El universo JavaScript en Drupal 7
El universo JavaScript en Drupal 7
 
Parte II. Notas Rapidas (sticky notes) App W8: MVVM y SQLite.
Parte II. Notas Rapidas (sticky notes) App W8: MVVM y SQLite.Parte II. Notas Rapidas (sticky notes) App W8: MVVM y SQLite.
Parte II. Notas Rapidas (sticky notes) App W8: MVVM y SQLite.
 
Doctrine2 sf2Vigo
Doctrine2 sf2VigoDoctrine2 sf2Vigo
Doctrine2 sf2Vigo
 
Desarrollo de aplicaciones web usando Catalyst y jQuery
Desarrollo de aplicaciones web usando Catalyst y jQueryDesarrollo de aplicaciones web usando Catalyst y jQuery
Desarrollo de aplicaciones web usando Catalyst y jQuery
 
Introducción a DJango
Introducción a DJangoIntroducción a DJango
Introducción a DJango
 
Persistencia de un modelo de objetos
Persistencia de un modelo de objetosPersistencia de un modelo de objetos
Persistencia de un modelo de objetos
 
Informe grupal f_arinango_ cuenca
Informe grupal f_arinango_ cuencaInforme grupal f_arinango_ cuenca
Informe grupal f_arinango_ cuenca
 
EXAMEN
EXAMENEXAMEN
EXAMEN
 
Migrate, una herramienta de trabajo y desarrollo
Migrate, una herramienta de trabajo y desarrolloMigrate, una herramienta de trabajo y desarrollo
Migrate, una herramienta de trabajo y desarrollo
 
Introducción al desarrollo Web: Frontend con Angular 6
Introducción al desarrollo Web: Frontend con Angular 6Introducción al desarrollo Web: Frontend con Angular 6
Introducción al desarrollo Web: Frontend con Angular 6
 
Código mantenible, en Wordpress.
Código mantenible, en Wordpress.Código mantenible, en Wordpress.
Código mantenible, en Wordpress.
 
Symfony en Drupal 8 - DrupalCamp Spain
Symfony en Drupal 8 - DrupalCamp Spain Symfony en Drupal 8 - DrupalCamp Spain
Symfony en Drupal 8 - DrupalCamp Spain
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
MODELO VISTA CONTROLADOR EN PHP
MODELO VISTA CONTROLADOR EN PHPMODELO VISTA CONTROLADOR EN PHP
MODELO VISTA CONTROLADOR EN PHP
 

Mais de Pedro Cambra (9)

Drupal Themes
Drupal ThemesDrupal Themes
Drupal Themes
 
Drupal Commerce: Presente y futuro del comercio electrónico con Drupal
Drupal Commerce: Presente y futuro del comercio electrónico con DrupalDrupal Commerce: Presente y futuro del comercio electrónico con Drupal
Drupal Commerce: Presente y futuro del comercio electrónico con Drupal
 
Drupal commerce
Drupal commerceDrupal commerce
Drupal commerce
 
Drupal commerce
Drupal commerceDrupal commerce
Drupal commerce
 
Introduccion técnica a Drupal
Introduccion técnica a DrupalIntroduccion técnica a Drupal
Introduccion técnica a Drupal
 
Introducción general a Drupal
Introducción general a DrupalIntroducción general a Drupal
Introducción general a Drupal
 
Programacion basica de módulos
Programacion basica de módulosProgramacion basica de módulos
Programacion basica de módulos
 
Comercio electrónico con drupal
Comercio electrónico con drupalComercio electrónico con drupal
Comercio electrónico con drupal
 
Presentacion Drupal Ccrtv
Presentacion Drupal CcrtvPresentacion Drupal Ccrtv
Presentacion Drupal Ccrtv
 

Último

redes informaticas en una oficina administrativa
redes informaticas en una oficina administrativaredes informaticas en una oficina administrativa
redes informaticas en una oficina administrativa
nicho110
 

Último (11)

PROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
PROYECTO FINAL. Tutorial para publicar en SlideShare.pptxPROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
PROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
 
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptxEVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
 
Avances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estosAvances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estos
 
Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21
 
investigación de los Avances tecnológicos del siglo XXI
investigación de los Avances tecnológicos del siglo XXIinvestigación de los Avances tecnológicos del siglo XXI
investigación de los Avances tecnológicos del siglo XXI
 
How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.
 
Buenos_Aires_Meetup_Redis_20240430_.pptx
Buenos_Aires_Meetup_Redis_20240430_.pptxBuenos_Aires_Meetup_Redis_20240430_.pptx
Buenos_Aires_Meetup_Redis_20240430_.pptx
 
redes informaticas en una oficina administrativa
redes informaticas en una oficina administrativaredes informaticas en una oficina administrativa
redes informaticas en una oficina administrativa
 
Guia Basica para bachillerato de Circuitos Basicos
Guia Basica para bachillerato de Circuitos BasicosGuia Basica para bachillerato de Circuitos Basicos
Guia Basica para bachillerato de Circuitos Basicos
 
Avances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvanaAvances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvana
 
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
 

Drupal7 para desarrolladores

  • 1. Desarrolladores: Bienvenidos a Drupal 7 Drupalcamp Spain 2011, Sevilla 1-2 Octubre
  • 2. Sobre mí ● Desarrollador Drupal en Commerce Guys. ● Miembro hiperactivo de la comunidad drupalera de habla Pedro Cambra @pcambra hispana.
  • 3. Drupal 7 Drupal 7 incorpora gran cantidad de novedades a nivel de diseño, usabilidad pero quizás el mayor cambio que se ha producido entre las versiones 6x y 7x es a nivel desarrollo.
  • 4. Entidades en Core Las entidades en Drupal añaden una nueva capa de abstracción basada en objetos sobre los datos que permite que todo el contenido comparta API y workflow. Nodos, usuarios, términos de taxonomía, vocabularios, comentarios, ficheros... son ahora entidades
  • 5. Entidades en Core “Everything is a node” vs “Nodes are entities too”
  • 6. Ejemplo #1: Entity Controllers class CommerceProductEntityController extends DrupalCommerceEntityController { (..) public function create(array $values = array()) { return (object) ($values + array( 'product_id' => '', 'is_new' => TRUE, 'sku' => '', 'title' => '', 'uid' => '', 'status' => 1, 'created' => '', 'changed' => '', )); } (..) }
  • 7. Ejemplo #2: EntityFieldQuery function commerce_product_reference_commerce_product_can_delete($product) { // Use EntityFieldQuery to look for line items referencing this // product and do not allow the delete to occur if one exists. $query = new EntityFieldQuery(); $query ->entityCondition('entity_type', 'commerce_line_item', '=') ->entityCondition('bundle', 'product', '=') ->fieldCondition('product', 'product_id', $product->product_id, '=') ->count(); return $query->execute() > 0 ? FALSE : TRUE; }
  • 8. Entity API ● El módulo Entity API se crea para facilitar el acceso a las entidades y para rellenar los huecos que le faltan al core de Drupal. ● Añade elementos muy interesantes como propiedades, exportables, interfaz de administración o los metadata wrappers ● También proporciona un controlador de CRUD estándar para la mayoría de entidades.
  • 9. Ejemplo#1: Entity Metadata Wrapper function commerce_line_items_quantity($line_items, $type = '') { // Sum up the quantity of all matching line items. $quantity = 0; foreach ($line_items as $line_item) { if (!is_a($line_item, 'EntityMetadataWrapper')) { $line_item = entity_metadata_wrapper('commerce_line_item', $line_item); } if (empty($type) || $line_item->type->value() == $type) { $quantity += $line_item->quantity->value(); } } return $quantity; }
  • 10. Ejemplo#2: Entity Properties /** * Implements hook_entity_property_info(). */ function commerce_product_entity_property_info() { $info = array(); // Add meta-data about the basic commerce_product properties. $properties = &$info['commerce_product']['properties']; (..) $properties['sku'] = array( 'label' => t('SKU'), 'description' => t('The human readable product SKU.'), 'type' => 'text', 'setter callback' => 'entity_property_verbatim_set', 'required' => TRUE, 'schema field' => 'sku', );
  • 11. Field API ● Parte del módulo CCK se ha refactorizado y es ahora el Field API de Drupal 7. ● Los nuevos campos generados por Field API se pueden adjuntar a cualquier entidad que tenga la propiedad fieldable. ● Se ha facilitado en gran medida la forma de crear campos personalizados y se han añadido y estandarizado gran cantidad de nuevas opciones.
  • 12. Extendiendo Field API Field API incorpora gran cantidad de hooks, ejemplos curiosos: ● hook_field_attach_* - controlan los formularios y acciones cuando un campo se adjunta a una entidad (y operaciones CRUD). ● hook_field_storage_* - controlan la forma en la que se almacena el campo (NoSQL?) ● hook_field_extra_fields* - Permiten exponer “pseudo campos” en las entidades.
  • 13. Form API ● #states ● Vertical Tabs ● #ajax ● machine_name ● #attached ● tableselect ● hook_form_alter() ● managed_file desde plantilla ● Elementos HTML5 a ● #title_display través del módulo ● #limit_validation_errors Elements
  • 14. Ejemplo: #attached & Vertical Tabs $form['additional_settings'] = array( '#type' => 'vertical_tabs', '#weight' => 99, ); (..) // Add a section to update the status and leave a log message. $form['order_status'] = array( '#type' => 'fieldset', '#title' => t('Order status'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#group' => 'additional_settings', '#attached' => array( 'js' => array( drupal_get_path('module', 'commerce_order') . '/commerce_order.js', array( 'type' => 'setting', 'data' => array('status_titles' => commerce_order_status_get_title()), ), ), ), '#weight' => 20, );
  • 15. DBTNG El proyecto DBTNG ha reformado la capa de abstracción de Drupal para acercarla a un modelo OOP. $result = db_query("SELECT n.nid, u.name FROM {node} n WHERE n.type = '%s' AND n.status = %d", Drupal 6 array('page', 1)); $product_count = db_select('commerce_product', 'cp') ->fields('cp', array('product_id')) ->countQuery() ->execute() Drupal 7 ->fetchField();
  • 16. Render arrays Los render arrays son los elementos utilizados a partir de Drupal 7 para construir las páginas. Estos elementos proporcionan una flexibilidad enorme y dan la posibilidad de alterar cómo se generan las páginas con la misma facilidad que alteramos un formulario. Novedad: hook_page_alter().
  • 17. Ejemplo: render arrays $note = array( '#title' => t('Render Array Example'), '#items' => $items, // The functions in #pre_render get to alter the actual data before it // gets rendered by the various theme functions. '#pre_render' => array('render_example_change_to_ol'), // The functions in #post_render get both the element and the rendered // data and can add to the rendered data. '#post_render' => array('render_example_add_hr'), // The #theme theme operation gets the first chance at rendering the // element and its children. '#theme' => 'item_list', // Then the theme operations in #theme_wrappers can wrap more around // what #theme left in #chilren. '#theme_wrappers' => array('render_example_add_div', 'render_example_add_notes'), '#weight' => -9999, ); $page['sidebar_first']['render_array_note'] = $note; $page['sidebar_first']['#sorted'] = FALSE;
  • 18. Cache ● Se introduce drupal_static() que reemplaza la llamada PHP 'static'. ● Integración con los render arrays: t('cache demonstration') => array( '#markup' => t('The current time was %time when this was cached. Updated every %interval seconds', array('%time' => date('r'), '%interval' => $interval)), '#cache' => array( 'keys' => array('render_example', 'cache', 'demonstration'), 'bin' => 'cache', 'expire' => time() + $interval, 'granularity' => DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE, ), ), http://www.lullabot.com/articles/beginners-guide-caching-data-drupal-7
  • 19. Novedades Js Drupal 7 incorpora muchas novedades técnicas para fomentar la flexibilidad y control del javascript en nuestros proyectos. ● drupal_add_js() permite peso y ficheros externos. ● hook_js_alter() ● Jquery 1.4.4 y jQuery UI 1.8 ● Mejoras en los behaviors.
  • 20. Ejemplo js $form['attributes'][$field_name] = array( '#type' => 'select', '#title' => check_plain($data['instance']['label']), '#options' => array_intersect_key($data['options'], drupal_map_assoc($used_options[$field_name])), '#default_value' => $default_product_wrapper->{$field_name} ->value(), '#weight' => $data['instance']['widget']['weight'], '#ajax' => array( 'callback' => 'commerce_cart_add_to_cart_form_attributes_refresh', ), );
  • 21. File API El nuevo interfaz de ficheros de Drupal 7 permite acceder a cualquier recurso como si fuera un fichero. ● Introducción de streams: public:// private:// temporary:// ● file_unmanaged_* (copy, move, delete) permite tratar ficheros sin grabarlos en base de datos.
  • 22. Code registry En Drupal 7 se introduce el registro de código, para inventariar los ficheros y clases que se deben cargar en cada momento. El único fichero que se carga automáticamente es el .module, el resto de ficheros, plugins, includes, tests, etc... deben declararse en el array files[] del fichero .info.
  • 23. info files ● Se pueden añadir css y js usando las propiedades stylesheets y scripts. ● La propiedad files fuerza el auto load de los ficheros declarados. ● dependencies soporta versiones. ● La propiedad configure expone el path de configuración del módulo ● required fuerza que un módulo o theme sea obligatorio y no pueda ser deshabilitado http://drupal.org/node/542202
  • 24. Queue API Drupal 7 incorpora una nueva API para gestionar colas basada en objetos. Varios componentes del core como Aggregator, Batch API o Cron ya la implementan de base. Permite guardar los elementos en memoria o en base de datos, y es totalmente configurable según el caso de uso que necesitemos. http://www.slideshare.net/philipnorton42/drupal-7-queues
  • 25. Ejemplo queue $queue = DrupalQueue::get('tofu_sandwich'); $queue->createQueue(); // no-op. $things = array('bread', 'tofu', 'provolone', 'sprouts'); foreach ($things as $item) { $queue->createItem($item); } $items = array(); while ($item = $queue->claimItem()) { $message .= $item->item_id . ':' . $item->data . '; '; $items[] = $item; } drupal_set_message('Queue contains: ' . check_plain($message)); foreach ($items as $item) { $queue->releaseItem($item); } http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
  • 26. Cambios en Schema A partir de Drupal 7, declarar hook_schema en el fichero .install es suficiente para instalar y desinstalar tablas en la base de datos, no hay que hacerlo explícitamente con hook_install y hook_uninstall. hook_field_schema() se encarga de los esquemas de datos para campos. http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_schema/7
  • 27. Simpletest en core ● Drupal 7 incorpora el módulo Simpletest en su núcleo y tiene unit testing e integration testing en todos los componentes por defecto. ● Tener los elementos verificados proporciona seguridad y calidad en los componentes. http://drupal.org/simpletest-tutorial-drupal7
  • 28. Libros ¡Recomendado!
  • 29. ¿Preguntas? ● @pcambra ● cambrico.net ● Perfil en Drupal.org