Desarrollo rápido con Drupal 8

Joaquín Bravo (@jackbravo) - Axai.mx

Instalar composer

# https://getcomposer.org/download/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

# https://getcomposer.org/doc/00-intro.md#globally
sudo mv composer.phar /usr/local/bin/composer
composer --version

Crear un nuevo proyecto

composer create-project drupal/drupal taller-drupal --prefer-dist
# taller-drupal es el nombre de la carpeta
# --prefer-dist = baja .zip en lugar de git

# si tu Internet es lento
wget -c https://ftp.drupal.org/files/projects/drupal-8.3.2.tar.gz
mv drupal-8.3.2 taller-drupal

# si estás es un taller con MUUUCHA gente
wget http://joaquin.axai.mx/taller-drupal.tar.gz
tar -zxf taller-drupal.tar.gz

# Finalmente
cd taller-drupal

Crear repositorio de git

git init
cp example.gitignore .gitignore

git add .
git commit -m "Initial commit"

Don't Hack Core!

Si quieres usar parches al core o a módulos, usa https://github.com/cweagans/composer-patches

y así las modifcaciones viven en composer.json

Agregar Drupal Console

composer require drupal/console:~1.0
./vendor/drupal/console/bin/drupal check
alias drupal=./vendor/drupal/console/bin/drupal
drupal list

# Esto modifico composer.json y composer.lock
git status
git add composer.*
git commit -m "Add drupal console"

Instalar Drupal!

drupal site:install
drupal server

Exportar la configuración

# En sites/default/settings.php

# Modificar la última línea
$config_directories['sync'] = 'sites/default/files/config_HASH/sync';
# Con 
$config_directories['sync'] = 'sites/default/sync';

# Después correr en la consola:
chmod u+w sites/default
mkdir sites/default/sync
chmod u-w sites/default
drupal config:export
git status
git add sites/default/sync
git commit -m "Agregar configuracion a git"

Descargar módulos

composer require drupal/admin_toolbar
composer require drupal/restui

git status
git diff
git add composer.* modules/contrib
git commit -m "Agregar módulos de image_url_formatter y admin_toolbar"

Instalar y exportar config

# Desde la interfaz web o...
drupal module:install restui basic_auth
drupal module:install admin_toolbar

drupal config:export

git status
git diff
git add sites/default/sync
git commit -m "Habilitar modulos (rest, admin_toolbar)"

Habilitar REST para node

# Desde la interfaz web
http://127.0.0.1:8088/admin/config/services/rest

Habilitar GET para "Content" con:
- json
- basic_auth

drupal config:export
git add sites/default/sync
git commit -m "Habilitar GET para contenido"

Crear contenido

drupal create:nodes

# https://github.com/jakubroztocil/httpie
sudo apt-get install httpie
http "http://127.0.0.1:8088/node/1?_format=json"
http 127.0.0.1:8088/node/1 _format==json

Crear vista

http 127.0.0.1:8088/rest/views/articles _format==json
http -a admin:admin 127.0.0.1:8088/rest/views/articles _format==json

Exportar la vista

# Recuerden, por curiosidad:
git status
git diff

# Para exportar
drupal config:export
git status
git add sites/default/sync
git commit -m "Exportar vista REST a la configuración"

Crear mi propio Módulo

drupal generate:module
 // Welcome to the Drupal module generator
 Enter the new module name:
 > FliSol

drupal generate:plugin:rest:resource
 // Welcome to the Drupal Plugin Rest Resource generator
 Enter the module name [admin_toolbar]:
 > flisol
 Enter the plugin rest resource name [DefaultRestResource]:
 > ArticleRestResource

drupal module:install flisol

drupal rest:enable
 Rest ID [entity:action]:
 > articles

http -a admin:admin 127.0.0.1:8088/rest/articles _format==json

Referencias

Drupal Development 8.x

By jackbravo

Drupal Development 8.x

  • 661