SlideShare a Scribd company logo
Custom Forms and Configuration Forms:
examples of Drupal 8 objected oriented APIs
@ItaloMairoItalo Mairo
Drupal.org username: itamair
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
Engineer - Freelance
More than 15 years of working experience 

in Digital Communication, Multimedia, Digital
Cartography, Web & Web GIS 2.0 Opensource
Applications.
Experienced Drupal Developer

more than 5 years of full-time work experience
collaboration with several Drupal Italian Web Agencies
Individual Member of Drupal Association
Personal website: www.italomairo.com
Linkedin Profile: italomairo
Who I am …
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
About this talk …
Presents a practical application of building a

Custom Form and its Configuration Form, according

to new Drupal 8 Form Object Oriented APIs.
Inspired by Best practices and patterns, applied in the
context of an advanced Drupal 8 project run as
member of the team of 

Wellnet Drupal Agency (DDD Gold Sponsor).
Special thanks, for his mentoring about Drupal 8 OOP,
to Luca Lusso (@ lussoluca),
Wellnet Tech Lead,
Webprofiler creator & Devel Module maintainer
and more …
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
Form API in Drupal 8
Is largely similar to the Drupal 7 Form API.
Forms are defined by implementing the 

DrupalCoreFormFormBuilderInterface
and the basic workflow of a form is defined by
• getFormId
• buildForm
• validateForm
• submitForm
Check out https://api.drupal.org/api/drupal/elements 

for all the core provided elements.
There are new HTML 5 elements (like ‘tel', 'email', 'number', ‘date', ‘url’) 

and specific others (‘details’, ‘language_select’, ‘dropbutton & operations’, etc).
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
Drupal 8 provides extendable base classes for easy form
creation.
FormBase - The most generic base class for generating forms 

(implements FormInterface, use FormStateInterface)
ConfirmFormBase - For providing users with a form to confirm
an action such as deleting a piece of content.
ConfigFormBase - For creating system configuration forms,
provides additional functionality for improved interaction with the
configuration system.
Form API in Drupal 8
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
Form API in Drupal 8
Integrate the form in a Route request
The routing system takes care of instantiating the form class and invoking the proper methods.
ddd_forms_talk.ddd_form:

path: '/ddd_form'

defaults:

_form: 'Drupalddd_forms_talkFormDddForm'

_title: 'DDD - Example Form'

requirements:

_permission: 'access content'
Adding further parameters -> Using parameters in routes
Retrieving this form outside of routes
The routing system allows form classes to be provided as route handlers, in which case the
route system takes care of instantiating this class and invoking the proper methods.
$form = Drupal::formBuilder()->getForm(‘Drupalddd_forms_talkFormDddForm’, $extra_params);
(corresponds to the D7 drupal_get_form($form_id) function)
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
Form API #states
Form API #states allow us to create form elements that change
state (show, hide, enable, disable, etc.) depending on certain
conditions—for example, disabling one field based on the
contents of another.
For most common Form UI tasks, the #states system eliminates
the need to write custom JavaScript. It eliminates inconsistencies
by translating simple form element properties into standardized
JavaScript code.
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
Dependency Injection for a Form
namespace Drupalddd_forms_talkForm;



use DrupalCoreFormFormBase;

use DrupalCoreFormFormStateInterface;

use SymfonyComponentDependencyInjectionContainerInterface;

use DrupalCoreRenderRendererInterface;
class DddForm extends FormBase* {


public function __construct(RendererInterface $renderer) {

$this->renderer = $renderer;

}



public static function create(ContainerInterface $container) {

return new static(

$container->get('renderer')

);

}
… (omissis)
Note*: abstract class FormBase implements FormInterface, ContainerInjectionInterface
Forms that require a Drupal service or a custom service should access the service
using dependency injection.
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
To trigger an Ajax response:
• Add property '#ajax' to a form element in your form array,
• Write an Ajax callback to process the input and respond.
The #ajax property for a form element is an array, with specific elements, all of which are optional:
• callback: The callback to invoke to handle the server side of the Ajax event.
• wrapper: The HTML 'id' attribute of the area where the content returned by the callback should be placed. Note
that callbacks have a choice of returning content or JavaScript commands; 'wrapper' is used for content returns.
• method: The jQuery method for placing the new content (used with 'wrapper')
• effect: The jQuery effect to use when placing the new HTML (used with 'wrapper')
• speed: The effect speed to use (used with 'effect' and 'wrapper')
• event: The JavaScript event to respond to. This is selected automatically for the type of form element; provide a
value to override the default.
• prevent: A JavaScript event to prevent when the event is triggered.
• progress: An array indicating how to show Ajax processing progress. Can contain one or more of these:
• type: Type of indicator: 'throbber' (default) or 'bar'.
• message: Translated message to display.
• url: For a bar progress indicator, URL path for determining progress.
• interval: For a bar progress indicator, how often to update it.
Ajax Responses in forms
Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair)
References for further information
• Form API in Drupal 8: https://www.drupal.org/node/2117411

• Form and render elements: https://api.drupal.org/api/drupal/elements

• Dependency Injection for a Form: 

https://www.drupal.org/node/2203931 

• Form API #states: https://www.lullabot.com/articles/form-api-states

• Ajax API:

https://api.drupal.org/api/drupal/core%21core.api.php/group/ajax/
8.1.x
Custom Forms and Configuration Forms in Drupal 8

More Related Content

What's hot

Drupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin SystemDrupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin System
Acquia
 
Style guides in drupal development workflows
Style guides in drupal development workflowsStyle guides in drupal development workflows
Style guides in drupal development workflows
Kalin Chernev
 
Decoupled drupal DcRuhr
Decoupled drupal DcRuhrDecoupled drupal DcRuhr
Decoupled drupal DcRuhr
Ahmad Hassan
 
Drupal Webinar
Drupal WebinarDrupal Webinar
Drupal Webinar
Maxwell Pearl
 
Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...
Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...
Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...
sbclapp
 
Drupal
DrupalDrupal
DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT
DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT
DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT
Shri Prakash Pandey
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
Marcos Labad
 
Architecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampArchitecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal Camp
Dipen Chaudhary
 
Media handling in Drupal (Drupalcamp Leuven 2013)
Media handling in Drupal (Drupalcamp Leuven 2013)Media handling in Drupal (Drupalcamp Leuven 2013)
Media handling in Drupal (Drupalcamp Leuven 2013)
Sven Decabooter
 
Quickly Customizing Alfresco
Quickly Customizing AlfrescoQuickly Customizing Alfresco
Quickly Customizing Alfresco
Alfresco Software
 
Zope and Plone in the DSD
Zope and Plone in the DSDZope and Plone in the DSD
Zope and Plone in the DSD
brighteyes
 
Content management system
Content management systemContent management system
Content management system
giri5624
 
Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014
Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014
Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014
Howard Greenberg
 
Drupal and Winona360
Drupal and Winona360Drupal and Winona360
Drupal and Winona360
Jose de Leon
 
Lab 5a) create a struts application
Lab 5a) create a struts applicationLab 5a) create a struts application
Lab 5a) create a struts applicationtechbed
 

What's hot (19)

Drupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin SystemDrupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin System
 
Style guides in drupal development workflows
Style guides in drupal development workflowsStyle guides in drupal development workflows
Style guides in drupal development workflows
 
Decoupled drupal DcRuhr
Decoupled drupal DcRuhrDecoupled drupal DcRuhr
Decoupled drupal DcRuhr
 
Drupal Webinar
Drupal WebinarDrupal Webinar
Drupal Webinar
 
Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...
Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...
Drupal is from Mars, Wordpress is from Venus: Finding your library's CMS soul...
 
Drupal
DrupalDrupal
Drupal
 
DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT
DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT
DIPLOMA IN DESIGNING AND WEBSITE DEVELOPMENT
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
 
Architecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal CampArchitecture of Drupal - Drupal Camp
Architecture of Drupal - Drupal Camp
 
Media handling in Drupal (Drupalcamp Leuven 2013)
Media handling in Drupal (Drupalcamp Leuven 2013)Media handling in Drupal (Drupalcamp Leuven 2013)
Media handling in Drupal (Drupalcamp Leuven 2013)
 
Quickly Customizing Alfresco
Quickly Customizing AlfrescoQuickly Customizing Alfresco
Quickly Customizing Alfresco
 
Zope and Plone in the DSD
Zope and Plone in the DSDZope and Plone in the DSD
Zope and Plone in the DSD
 
Content management system
Content management systemContent management system
Content management system
 
72d5drupal
72d5drupal72d5drupal
72d5drupal
 
Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014
Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014
Creating a Great XPages User Interface, TLCC Teamstudio Webinar - Feb, 2014
 
Drupal and Winona360
Drupal and Winona360Drupal and Winona360
Drupal and Winona360
 
Drupal presentation
Drupal presentationDrupal presentation
Drupal presentation
 
Lab 5a) create a struts application
Lab 5a) create a struts applicationLab 5a) create a struts application
Lab 5a) create a struts application
 
Open Source CMS
Open Source CMSOpen Source CMS
Open Source CMS
 

Viewers also liked

Poster presentation
Poster presentationPoster presentation
Poster presentationLorainemoore
 
A2 blog checklist landscape
A2 blog checklist landscapeA2 blog checklist landscape
A2 blog checklist landscape
jonreigatemedia
 
Altruistic project E-Newsletter
Altruistic project E-NewsletterAltruistic project E-Newsletter
Altruistic project E-Newsletter
Lorainemoore
 
Mr Eng Project
Mr Eng ProjectMr Eng Project
Mr Eng Project
Kelly Vu
 
Exam technique fm4 a
Exam technique fm4 aExam technique fm4 a
Exam technique fm4 a
jonreigatemedia
 
Areas that may come up in the exam
Areas that may come up in the examAreas that may come up in the exam
Areas that may come up in the exam
jonreigatemedia
 
SEO For Bloggers
SEO For BloggersSEO For Bloggers
SEO For Bloggers
Alicia Magda
 
8-Peta Titi (Bridge Map)
8-Peta Titi (Bridge Map)8-Peta Titi (Bridge Map)
8-Peta Titi (Bridge Map)
Faizura Damia
 
WJEC Fm2 (c) american comparative study 2
WJEC Fm2 (c) american comparative study 2WJEC Fm2 (c) american comparative study 2
WJEC Fm2 (c) american comparative study 2
jonreigatemedia
 
3-Peta Buih Berganda (Double Bubble)
3-Peta Buih Berganda (Double Bubble)3-Peta Buih Berganda (Double Bubble)
3-Peta Buih Berganda (Double Bubble)
Faizura Damia
 
Media language social
Media language socialMedia language social
Media language social
jonreigatemedia
 
G325 question 1b revision ideas
G325 question 1b revision ideasG325 question 1b revision ideas
G325 question 1b revision ideas
jonreigatemedia
 

Viewers also liked (12)

Poster presentation
Poster presentationPoster presentation
Poster presentation
 
A2 blog checklist landscape
A2 blog checklist landscapeA2 blog checklist landscape
A2 blog checklist landscape
 
Altruistic project E-Newsletter
Altruistic project E-NewsletterAltruistic project E-Newsletter
Altruistic project E-Newsletter
 
Mr Eng Project
Mr Eng ProjectMr Eng Project
Mr Eng Project
 
Exam technique fm4 a
Exam technique fm4 aExam technique fm4 a
Exam technique fm4 a
 
Areas that may come up in the exam
Areas that may come up in the examAreas that may come up in the exam
Areas that may come up in the exam
 
SEO For Bloggers
SEO For BloggersSEO For Bloggers
SEO For Bloggers
 
8-Peta Titi (Bridge Map)
8-Peta Titi (Bridge Map)8-Peta Titi (Bridge Map)
8-Peta Titi (Bridge Map)
 
WJEC Fm2 (c) american comparative study 2
WJEC Fm2 (c) american comparative study 2WJEC Fm2 (c) american comparative study 2
WJEC Fm2 (c) american comparative study 2
 
3-Peta Buih Berganda (Double Bubble)
3-Peta Buih Berganda (Double Bubble)3-Peta Buih Berganda (Double Bubble)
3-Peta Buih Berganda (Double Bubble)
 
Media language social
Media language socialMedia language social
Media language social
 
G325 question 1b revision ideas
G325 question 1b revision ideasG325 question 1b revision ideas
G325 question 1b revision ideas
 

Similar to Custom Forms and Configuration Forms in Drupal 8

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Joaquim Rocha
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
Arjan
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Antonio Peric-Mazar
 
Ctools presentation
Ctools presentationCtools presentation
Ctools presentationDigitaria
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ..."Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
DrupalCamp Kyiv
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8
Philip Norton
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
Manuel Lemos
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfoliocummings49
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
fantabulous2024
 
E-Bazaar
E-BazaarE-Bazaar
E-Bazaar
ayanthi1
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
Siddhesh Bhobe
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
dharisk
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
Sagar Arlekar
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial IntroPamela Fox
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutes
Loiane Groner
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
C#Portfolio
C#PortfolioC#Portfolio
C#Portfolio
Jeriel_Mikell
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web Framework
David Gibbons
 

Similar to Custom Forms and Configuration Forms in Drupal 8 (20)

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
 
Ctools presentation
Ctools presentationCtools presentation
Ctools presentation
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ..."Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8
 
Forms With Ajax And Advanced Plugins
Forms With Ajax And Advanced PluginsForms With Ajax And Advanced Plugins
Forms With Ajax And Advanced Plugins
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
E-Bazaar
E-BazaarE-Bazaar
E-Bazaar
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutes
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
C#Portfolio
C#PortfolioC#Portfolio
C#Portfolio
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web Framework
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 

Custom Forms and Configuration Forms in Drupal 8

  • 1. Custom Forms and Configuration Forms: examples of Drupal 8 objected oriented APIs @ItaloMairoItalo Mairo Drupal.org username: itamair
  • 2. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) Engineer - Freelance More than 15 years of working experience 
 in Digital Communication, Multimedia, Digital Cartography, Web & Web GIS 2.0 Opensource Applications. Experienced Drupal Developer
 more than 5 years of full-time work experience collaboration with several Drupal Italian Web Agencies Individual Member of Drupal Association Personal website: www.italomairo.com Linkedin Profile: italomairo Who I am …
  • 3. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) About this talk … Presents a practical application of building a
 Custom Form and its Configuration Form, according
 to new Drupal 8 Form Object Oriented APIs. Inspired by Best practices and patterns, applied in the context of an advanced Drupal 8 project run as member of the team of 
 Wellnet Drupal Agency (DDD Gold Sponsor). Special thanks, for his mentoring about Drupal 8 OOP, to Luca Lusso (@ lussoluca), Wellnet Tech Lead, Webprofiler creator & Devel Module maintainer and more …
  • 4. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) Form API in Drupal 8 Is largely similar to the Drupal 7 Form API. Forms are defined by implementing the 
 DrupalCoreFormFormBuilderInterface and the basic workflow of a form is defined by • getFormId • buildForm • validateForm • submitForm Check out https://api.drupal.org/api/drupal/elements 
 for all the core provided elements. There are new HTML 5 elements (like ‘tel', 'email', 'number', ‘date', ‘url’) 
 and specific others (‘details’, ‘language_select’, ‘dropbutton & operations’, etc).
  • 5. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) Drupal 8 provides extendable base classes for easy form creation. FormBase - The most generic base class for generating forms 
 (implements FormInterface, use FormStateInterface) ConfirmFormBase - For providing users with a form to confirm an action such as deleting a piece of content. ConfigFormBase - For creating system configuration forms, provides additional functionality for improved interaction with the configuration system. Form API in Drupal 8
  • 6. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) Form API in Drupal 8 Integrate the form in a Route request The routing system takes care of instantiating the form class and invoking the proper methods. ddd_forms_talk.ddd_form:
 path: '/ddd_form'
 defaults:
 _form: 'Drupalddd_forms_talkFormDddForm'
 _title: 'DDD - Example Form'
 requirements:
 _permission: 'access content' Adding further parameters -> Using parameters in routes Retrieving this form outside of routes The routing system allows form classes to be provided as route handlers, in which case the route system takes care of instantiating this class and invoking the proper methods. $form = Drupal::formBuilder()->getForm(‘Drupalddd_forms_talkFormDddForm’, $extra_params); (corresponds to the D7 drupal_get_form($form_id) function)
  • 7. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) Form API #states Form API #states allow us to create form elements that change state (show, hide, enable, disable, etc.) depending on certain conditions—for example, disabling one field based on the contents of another. For most common Form UI tasks, the #states system eliminates the need to write custom JavaScript. It eliminates inconsistencies by translating simple form element properties into standardized JavaScript code.
  • 8. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) Dependency Injection for a Form namespace Drupalddd_forms_talkForm;
 
 use DrupalCoreFormFormBase;
 use DrupalCoreFormFormStateInterface;
 use SymfonyComponentDependencyInjectionContainerInterface;
 use DrupalCoreRenderRendererInterface; class DddForm extends FormBase* { 
 public function __construct(RendererInterface $renderer) {
 $this->renderer = $renderer;
 }
 
 public static function create(ContainerInterface $container) {
 return new static(
 $container->get('renderer')
 );
 } … (omissis) Note*: abstract class FormBase implements FormInterface, ContainerInjectionInterface Forms that require a Drupal service or a custom service should access the service using dependency injection.
  • 9. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) To trigger an Ajax response: • Add property '#ajax' to a form element in your form array, • Write an Ajax callback to process the input and respond. The #ajax property for a form element is an array, with specific elements, all of which are optional: • callback: The callback to invoke to handle the server side of the Ajax event. • wrapper: The HTML 'id' attribute of the area where the content returned by the callback should be placed. Note that callbacks have a choice of returning content or JavaScript commands; 'wrapper' is used for content returns. • method: The jQuery method for placing the new content (used with 'wrapper') • effect: The jQuery effect to use when placing the new HTML (used with 'wrapper') • speed: The effect speed to use (used with 'effect' and 'wrapper') • event: The JavaScript event to respond to. This is selected automatically for the type of form element; provide a value to override the default. • prevent: A JavaScript event to prevent when the event is triggered. • progress: An array indicating how to show Ajax processing progress. Can contain one or more of these: • type: Type of indicator: 'throbber' (default) or 'bar'. • message: Translated message to display. • url: For a bar progress indicator, URL path for determining progress. • interval: For a bar progress indicator, how often to update it. Ajax Responses in forms
  • 10. Custom Forms and Configuration Forms in Drupal 8 - Italo Mairo (itamair) References for further information • Form API in Drupal 8: https://www.drupal.org/node/2117411 • Form and render elements: https://api.drupal.org/api/drupal/elements • Dependency Injection for a Form: 
 https://www.drupal.org/node/2203931 • Form API #states: https://www.lullabot.com/articles/form-api-states • Ajax API:
 https://api.drupal.org/api/drupal/core%21core.api.php/group/ajax/ 8.1.x