Drupal 8 simple page: Mi primer proyecto en Drupal 8.
-
Upload
samuel-solis-fuentes -
Category
Software
-
view
481 -
download
3
Transcript of Drupal 8 simple page: Mi primer proyecto en Drupal 8.
![Page 1: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/1.jpg)
Drupal 8 simple pageY otras historias
![Page 2: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/2.jpg)
• Y otras historias
Y este soy yo… @estoyausente
![Page 3: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/3.jpg)
• Y otras historias
Y este soy yo… @estoyausente
Gasolina vital
![Page 4: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/4.jpg)
• Y otras historias
Y este soy yo… @estoyausente
Gasolina vital
![Page 5: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/5.jpg)
Drupal 7
![Page 6: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/6.jpg)
Drupal 8
![Page 7: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/7.jpg)
Un pequeño paso para el hombre …
![Page 8: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/8.jpg)
Esta presentación contiene ejemplos que funcionan
basados sólo en mi experiencia
para más información consulte las APIs
![Page 9: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/9.jpg)
Vamos a ver1. Configuration manager
2. Routing
3. Formularios
4. Servicios
5. Theming
![Page 10: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/10.jpg)
Configuration managerImpresiones
1. ¡Funciona!
2. ¡Funciona bien!
3. …
4. Aún no lo veo para algunas cosas.
![Page 11: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/11.jpg)
Configuration manager
![Page 12: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/12.jpg)
Configuration manager
![Page 13: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/13.jpg)
Configuration manager
![Page 14: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/14.jpg)
Configuration manager
![Page 15: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/15.jpg)
Configuration manager
![Page 16: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/16.jpg)
Configuration managerPara explorar
1. https://www.drupal.org/project/config_tools
2. https://www.drupal.org/project/config_update
3. https://www.drupal.org/project/config_sync
4. https://www.drupal.org/project/config_devel
5. https://www.drupal.org/project/features ????
![Page 17: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/17.jpg)
Mi primer módulo
Drupal generate:module
![Page 18: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/18.jpg)
Routing
example_dyb_landing_content: path: '/landing-my-awsome-path' defaults: _controller: '\Drupal\example_dyb_landing\Controller\LandingContentController::pageContent' requirements: _access: 'TRUE'
example_dyb_landing/example_dyb_landing.routing.yml
![Page 19: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/19.jpg)
Controller
namespace Drupal\example_dyb_landing\Controller;use Drupal\Core\Controller\ControllerBase;use Drupal\Core\Url;class LandingContentController extends ControllerBase { public function pageContent() { $content = []; //Render array return $content; }}
example_dyb_landing/src/Controllers/LandingContentController.php
![Page 20: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/20.jpg)
Pausa para gato
![Page 21: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/21.jpg)
Forms
namespace Drupal\example_dyb_landing\Form;use Drupal\Core\Form\FormBase;use Drupal\Core\Form\FormStateInterface;class ContactForm extends FormBase { public function getFormId() { return 'contact_form'; }
example_dyb_landing/src/Form/ContactForm.php
![Page 22: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/22.jpg)
Forms
public function buildForm(array $form, FormStateInterface $form_state) { $form['mail'] = array( '#type' => 'email', '#title' => $this->t('Email'), '#required' => TRUE, '#attributes' => ['class' => ['formcontrol']], );
return $form; }
example_dyb_landing/src/Form/ContactForm.php
![Page 23: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/23.jpg)
Forms
public function validateForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); if(!\Drupal::service('email.validator')->isValid($values['mail'])) { $form_state->setErrorByName('mail', $this->t('The email address %mail is not valid.', array('%mail' => $values['mail']))); } }
example_dyb_landing/src/Form/ContactForm.php
![Page 24: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/24.jpg)
Forms
public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); $to = \Drupal::config('system.site')->get('mail'); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); \Drupal::service('plugin.manager.mail')->mail('example_dyb_landing', 'contact_message', $to, $language_interface, $values, 'no-replyđ@mail.com'); drupal_set_message($this->t('Thank for contact us. Your message has been sent correctly.'));}
example_dyb_landing/src/Form/ContactForm.php
![Page 25: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/25.jpg)
Forms
$output['bottom']['form'] = [ '#type' => 'container', '#attributes' => ['class' => ['left']], 'form' => \Drupal::formBuilder()->getForm('Drupal\example_dyb_landing\Form\ContactForm'), ];
example_dyb_landing/src/Form/ContactForm.php
![Page 26: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/26.jpg)
Forms
$output['bottom']['form'] = [ '#type' => 'container', '#attributes' => ['class' => ['left']], 'form' => \Drupal::formBuilder()->getForm('Drupal\example_dyb_landing\Form\ContactForm'), ];
example_dyb_landing/src/Form/ContactForm.php
![Page 27: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/27.jpg)
Servicios
services: rest_client.client: class: Drupal\rest_client\RestClient
example_dyb_landing/rest_client.services.yml
![Page 28: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/28.jpg)
Servicios
namespace Drupal\rest_client;/** * Class RestClient * @package Drupal\rest_client */ class RestClient{ protected $url; public function __construct() { $this->url = 'myserver.com'; }
example_dyb_landing/src/RestClient.php
![Page 29: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/29.jpg)
Servicios
public function getSpecialities($country = 'ES') { $cid = 'rest_client_getSpecialities_' . $country; if ($cache = \Drupal::cache()->get($cid)) { return $cache->data; }
//$output = getSomeStuff();
\Drupal::cache()->set($cid, $output); return $output; } return [];}
example_dyb_landing/src/RestClient.php
![Page 30: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/30.jpg)
Servicios
public function getSpecialities($country = 'ES') { $cid = 'rest_client_getSpecialities_' . $country; if ($cache = \Drupal::cache()->get($cid)) { return $cache->data; }
//$output = getSomeStuff();
\Drupal::cache()->set($cid, $output); return $output; } return [];}
example_dyb_landing/src/RestClient.php
![Page 31: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/31.jpg)
Inyección de dependencias
dependencies: - rest_client
example_dyb_landing/example_dyb_landing.info.yml
![Page 32: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/32.jpg)
Inyección de dependencias
namespace Drupal\register_form\Form;use Drupal\rest_client\RestClient;
class RegisterForm extends FormBase{ protected $client; public function __construct(RestClient $client) { $this->client = $client; } public static function create(ContainerInterface $container) { return new static( $container->get('rest_client.client'), ); }
example_dyb_landing/src/Form/RegisterForm.php
![Page 33: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/33.jpg)
Inyección de dependencias
public function buildForm(array $form, FormStateInterface $form_state) {
$form['speciality'] = [ '#type' => 'select', '#options' => $this->client->getSpecialities(), '#title' => $this->t('Speciality'), '#required' => TRUE, '#attributes' => ['class' => ['formcontrol']],]; return $form;
}
example_dyb_landing/src/Form/RegisterForm.php
![Page 34: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/34.jpg)
Pausa para meme
![Page 35: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/35.jpg)
Mi primer theme
Drupal generate:theme
![Page 36: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/36.jpg)
name: publictype: themedescription: Public theme.package: Othercore: 8.xlibraries: - public/global-stylingbase theme: classyregions: content: Content header: Header footer: Footer
public/public.info.yml
Mi primer theme
![Page 37: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/37.jpg)
global-styling: version: 1.x css: theme: css/style.css: {} js: js/public.js: {} dependencies: - core/jquery - core/drupal - core/drupalSettings
public/public.libraries.yml
Añadir css/js
![Page 38: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/38.jpg)
function public_preprocess_breadcrumb(&$variables){ //Add current page to breadcrumb. $request = \Drupal::request(); $route_match = \Drupal::routeMatch(); $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject()); $variables['breadcrumb'][] = array( 'text' => $page_title, );}
public/public.theme
Preprocess
![Page 39: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/39.jpg)
{% if breadcrumb %} <nav class="breadcrumbs" role="navigation" aria-labelledby="system-breadcrumb"> <h2 class="visually-hidden">{{ 'Breadcrumb'|t }}</h2> <ol class="itemlistbread"> {% for item in breadcrumb %} <li class="itembread"> {% if item.url %} <a href="{{ item.url }}" class="itembread__link">{{ item.text }}</a> {% else %} <span>{{ item.text }}</span> {% endif %} </li> {% endfor %} </ol> </nav> {% endif %}
public/templates/elements/breadcrumb.html.twig
Twig
![Page 40: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/40.jpg)
<?php db_query('DROP TABLE {users}’);
?>
![Page 41: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/41.jpg)
<?php db_query('DROP TABLE {users}’);
?>
![Page 42: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/42.jpg)
twig.config: debug: true
sites/default/default.services.yml
Twig debug
![Page 43: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/43.jpg)
Pausa para chiste
![Page 44: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/44.jpg)
Deberes• Caché
• Composer
• REST
• Migrate
• … Infinitas cosas.
![Page 45: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/45.jpg)
Drupalcamp 2016
Granada del 19 al 24 de Abril
![Page 46: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/46.jpg)
¿Preguntas?
![Page 47: Drupal 8 simple page: Mi primer proyecto en Drupal 8.](https://reader030.fdocuments.net/reader030/viewer/2022020213/58a4f4101a28abd8548b6cdd/html5/thumbnails/47.jpg)
Buenas gracias y muchas tardes
@estoyausenteSamuel Solís