Upload
javier-gomez
View
161
Download
4
Embed Size (px)
Citation preview
Anatomía de un módulo en Drupal 8
Javier Gómez
Drupal Backend Developer (EUIPO)www.codigoweb.es
@fjgomez2
Drupal 7
• Hooks
Drupal 8
• AlgunosHooks• Symfony
Drupal 9
• Symfony
Evolución del código en Drupal
Symfony y Drupal 8ComponentesheredadosdeSymfony2:• Routing• HttpFoundation• Debug• DependencyInjection• Validator• Yaml• Serializer• Twig• EventDispatcher• ClassLoader• HttpKernel
Estructura Básica
• {drupal_path}/modules• {drupal_path}/sites/all/modules
Archivos y Carpetas
Info
{path_module}/test3.info.yml{path_module}/test3.info
• Archivodeinstalación• Contienelainformaciónbásicadelmódulo• Muysimilarenambasversiones
Menús, alias y rutas
• test3.routing.yml• Test3.module• Hook_menu()
hook_menu vs routing
• test3.links.menu.yml
Routing module_name.routing.yml
• Ruta• Path• Controller• Permisos• Formulario
test3.routing.yml
Controller
• Src/Controller/Test3Controller.php
• test3.routing.yml• Namespace\Class::Method
Configuración
• Formulario• ParecidoaController (namespace/class)• {module_path}/src/Form/{class_name}.php
• test3.routing.yml
• Formulario(Callback function)
• Hook_menu()
Configuración
• getFormId()• Lousamosparaespecificarelidalformulario.
• getEditableConfigNames()• Leeelnombredevariabledeconfiguraciónqueseráeditable.
• submitForm(array &$form,FormStateInterface $form_state)
• buildForm(array $form,FormStateInterface $form_state)
• validateForm(array &$form,FormStateInterface $form_state)
ConfigFormBaseFormStateInterface
• $form_id
• form_submit()
• hook_form()
• form_validate()
Configuración Formulario
• getFormId()
• getEditableConfigNames()
• validateForm()
• submitForm()
Configuración Formulario
• buildForm()
Configuración Formulario
Permisos
• Test3.permissions.yml
• test3.routing.yml• Permisoscustom
• Hook_permission()
• Hook_menu()• Permisoscustom
Ayuda
• hook_help() en{module_name}.module • hook_help() en{module_name}.module
DEMO
https://github.com/codigoweb-org/Drupal-8-Hello-World
Preguntas?
• https://www.drupal.org/docs/8/creating-custom-modules• https://www.drupal.org/docs/8/converting-drupal-7-modules-to-drupal-8
Documentación
Gracias!!
Javier GómezDrupal Backend Developer (EUIPO)
www.codigoweb.es@fjgomez2
www.linkedin.com/in/codigoweb