Como aprender Drupal 8

David Flores

Linux, Drupal, Symfony, Silex, BackEnd, Seguridad, Python, ...sometimes #Nerd Speaker

david@indava.com

@dmouse

http://bit.ly/guate-how-to-d8

Disclaimer

Drupal esta cambiando

Y tú ¿Qué estas haciendo?

Necesitamos desarrolladores  preparados

Cambios en el código de Drupal 8

  • Orientación a objetos
  • Patrones de diseño
  • Código de terceros
  • Componentes Symfony 
  • Estándares en estructura
  • Pruebas unitarias
  • Middleware

¿Donde esta la documentación?

  • https://www.drupal.org/drupal-8.0
  • https://api.drupal.org/api/drupal/8
  • https://github.com/hechoendrupal/drupal8-links
  • https://twitter.com/search?q=drupal%208
  • Google / Blogs / Podcast

Aprende del código y de las pruebas

Todo esta en el core

<?php

/**
 * @file
 * Contains \Drupal\search\Plugin\Block\SearchBlock.
 */

namespace Drupal\search\Plugin\Block;

// ...

/**
 * Provides a 'Search form' block.
 *
 * @Block(
 *   id = "search_form_block",
 *   admin_label = @Translation("Search form"),
 *   category = @Translation("Forms")
 * )
 */
class SearchBlock extends BlockBase {
  // ...
}

Unit Test

<?php

/**
 * @file
 * Contains \Drupal\search\Tests\SearchBlockTest.
 */

namespace Drupal\search\Tests;

class SearchBlockTest extends SearchTestBase {

// ...
    protected function testSearchFormBlock() {
        // Test a normal search via the block form, from the front page.
        $terms = array('keys' => 'test');
        $this->submitGetForm('', $terms, t('Search'));
        $this->assertResponse(200);
        $this->assertText('Your search yielded no results');
    }
// ...

}

Implementa Interfaces

<?php

/**
 * @file
 * Contains \Drupal\Core\DependencyInjection\ContainerInjectionInterface.
 */

namespace Drupal\Core\DependencyInjection;

interface ContainerInjectionInterface {

  public static function create(ContainerInterface $container);

}

Usa comandos de linux =)

$ cd core/modules

$ ls */src/Form  -ld

$ ls -d */src/Plugin/* | \
grep -v ".php" | \
awk '{ split($1, folders, "/"); print folders[4]; }' | \
sort | \
uniq

Controller

El 50% de los módulos del core tiene un controller


$ ls */src/Controller/ -dl
<?php

/**
 * @file
 * Contains \Drupal\help\Controller\HelpController.
 */

namespace Drupal\help\Controller;

// ...

class HelpController extends ControllerBase {

  // ...
  
  public function helpMain() {
    $output = array(
      '#attached' => array(
        'css' => array(drupal_get_path('module', 'help') . '/css/help.module.css'),
      ),
      '#markup' => '<h2>' . $this->t('Help topics') . '</h2><p>' . $this->t('Help is available ... :') . '</p>' . $this->helpLinksAsList(),
    );
    return $output;
  }

}

Como aprender Drupal 8

By David Flores

Como aprender Drupal 8

  • 1,428