Acquia Developer Portal Blog: How to work with Code Studio Automated Code Updates

Planet Drupal - Thu, 2023/04/13 - 8:46pm

As a developer, we’ve all experienced the time it takes to maintain a Drupal application, let alone 100s. Pulling the latest code changes, creating a new feature branch, syncing the DB from PROD to grab the latest content, updating composer, exporting configuration and pushing back up. Even if you are already set up with a local or Cloud IDE, this can take some time. Yes, there are tools we can use to speed up this process, drush, hosting CLIs, automated scripts… but again, this is just more to maintain and update to newer versions, when PHP or other software gets released. 

As you know, a CI/CD pipeline is also one of the most valuable tools a team can use to ensure the code is scanned for governance, standards and security. Acquia CI/CD Pipelines has been the solution for many of our clients in order to build

Categories:

Chromatic Insights: Drupal 7 End-of-Life Podcast - Episode 04

Planet Drupal - Thu, 2023/04/13 - 3:59pm
Irina Zaks joins us! Irina is a web developer, open-source evangelist, and the co-founder of the Drupal 7 Soft Landing Initiative. Irina, Chris, and Mark discuss Drupal 7 end-of-life, Backdrop, and how to give Drupal 7 users a soft landing.
Categories:

LN Webworks: Pros and Cons of Choosing Drupal for Your Large eCommerce Website

Planet Drupal - Thu, 2023/04/13 - 12:16pm
There are many options available to you when it comes to designing and developing your website. One of the most popular choices is Drupal, a powerful and easy-to-use CMS tool that has grown into a robust web development platform. Drupal is used in over 200 countries and available in 182 languages. Big brands like Harvard, Ubuntu, The Economist, Sony Music, and even the White House, trust Drupal to power their websites. With its advanced features and user-friendly admin interface, Drupal is a favorite among website developers and owners. Drupal ecommerce development services offer numerous benefits for businesses looking to create a large ecommerce website. But, how do you know if Drupal is the right choice for your ecommerce website? We have prepared a list of pros and cons of using Drupal for an ecommerce platform that can assist you to form a right decision. 
Categories:

LN Webworks: Looking Ahead: Navigating Drupal in 2023 and Beyond

Planet Drupal - Thu, 2023/04/13 - 11:44am
Drupal is one of the most popular Open-source CMS technologies available out there. As a business owner, it is common to feel uncertain about technologies implemented into the business process. But here’s the good news: Drupal is here to stay, thrive, and help businesses provide superior digital experiences in 2023 and beyond. In this article, you will learn not only about the future scope of Drupal but also ‘why’ organizations Hire Drupal Developers, and hopefully this will help you make better decisions. 
Categories:

The Drop Times: Best 7 Places to Visit in Pittsburgh for DrupalCon

Planet Drupal - Thu, 2023/04/13 - 11:40am
The event is from June 05 to 08. Outside the venue, Pittsburgh awaits to be explored. Whether you have visited the city or not, it holds a treasure of experiences to take away. A stroll through the ‘Steel City’ would take the visitor through the present’s beauty and the past’s glory. 
Categories:

The Drop Times: How We Built a Newsletter System on Drupal with Mailchimp Integration

Planet Drupal - Thu, 2023/04/13 - 11:30am
Learn how TheDropTimes successfully implemented a newsletter system for their editor's pick and jobs newsletters on their Drupal website, integrated with Mailchimp's RSS to Newsletter feature.
Categories:

Gizra.com: How AI Tools Streamline Everyday Tasks for Developers

Planet Drupal - Thu, 2023/04/13 - 2:00am

The world of software development is constantly evolving, and with the recent advancements in AI technologies, developers now have powerful tools at their disposal to help with everyday tasks. In this blog post, we will discuss how AI tools like ChatGPT and GitHub CoPilot have made a significant impact on our workflow, increasing productivity and improving the quality of our work.

GitHub CoPilot: The AI-Powered Assistant for Developers

I have been using GitHub CoPilot since August 2022, and it has proven to be an invaluable asset. It has provided the following benefits:

Speeding Up Smaller Tasks

GitHub CoPilot has significantly sped up smaller tasks such as creating demo content in CSV files, updating hooks, and managing dependency injections. This has allowed our developers to focus more on complex tasks and problem-solving.

Dependency Injection is a fundamental part of Drupal development, and it’s a chore that we need to do over and over again. Here’s how CoPilot speeds it up for an existing class:

Your browser does not support the video tag. Injecting renderer service into an existing class

Demo content is essential for our way of developing and it also makes testing much easier. But the creation of such content was, well, boring. Here’s how CoPilot speeds it up:

Your browser does not support the video tag. Generating meaningful demo content in CSV files
Categories:

Drupal Association blog: 5 Fun Things to do in Pittsburgh for DrupalCon 2023

Planet Drupal - Wed, 2023/04/12 - 7:24pm

Have you saved the date yet? The beautiful city of Pittsburgh, PA, will host the next DrupaCon North America from 5th through 8th June 2023. I know it feels like just yesterday that DrupalCon North America 2022 zipped by, and we’re already talking about DrupalCon 2023!

Famously known as the “Steel City” (the largest steel-producing city in the world) and “City of Bridges” (a staggering 446 bridges!), Pittsburgh is one of the top most liveable cities in the United States. When you’re here, you will be surrounded by warm and kind Pittsburghers (as they like to call themselves), world-class breweries and distilleries, green spaces, and some gorgeous views. Need more reasons to visit Pittsburgh?

What's hot in The 'Burgh 1. Carnegie Museums

Explore the marvels of art, natural history, and science at the world-renowned Carnegie museums. Featuring four dynamic and diverse museums, including the Carnegie Museum of Art, the Carnegie Museum of Natural History, the Carnegie Science Center, and the Andy Warhol Museum, Carnegie museum has something to appeal to everyone. While you’re here, don’t miss checking out the first fossil of the Tyrannosaurus rex dinosaur on display, the PaleoLab, where paleontologists prepare specimen for display, contemporary American and European artwork at the Hall of Sculptures and the Scaife gallery, and their constant changing art and science exhibitions. You can find more information about visiting the museum here.


Image source

2. Phipps Conservatory

If you enjoy the beauty and serenity of nature and the green outdoors, Phipps conservatory is the perfect place to visit. While it opened its doors to the public way back in 1890, its greenhouse production facility is a fantastic example of cutting-edge and sustainable innovation. It is the first to receive the Platinum LEED certification, a globally recognized symbol of sustainability achievement. When you’re here, you can stroll around the enchanting outdoor garden, check out the impressive glasshouses, explore the Tropical forest conservatory, and learn about their green innovation initiatives at the Center for sustainable landscapes. Before you plan your trip, visit their website to find out more about their immersive rotating exhibitions for that month.

​​


Image Source

3. Duquesne Incline

Take a ride back in time and explore one of Pittsburgh’s best panoramic views from a funicular railway (incline) experience. The Duquesne incline glides 400 feet above Pittsburgh’s rivers (the Ohio, Monongahela, and Allegheny) and is the only other remaining funicular in the country. While on the ride, you will climb (or descend) the hillside of Mount Washington. At the top station of the incline, you can explore the Observation deck and also dig deeper into its history and operation. The great part about the experience is that there’s a ride every 5 minutes, which means no waiting! No pre-booking is needed, but make sure you have the exact change for the quick ride.


Image source

4. Heinz History Center

Want to ‘ketchup’ on the history of Pittsburgh? Then you must visit the Senator John Heinz History Center located in the Strip District. It has something for every history buff, be it about the first settlers of Pittsburgh, the revolutionary war, the industrial revolution, sports, pop culture, and much more. It highlights the contributions of Pittsburgh’s locals to mankind, like the first polio vaccine, the Ferris wheel, revolutionary public TV broadcasting, and also the Big Mac! One of the most interesting attractions (and obviously) is the Heinz exhibit that displays everything you wanted to know about how they started way back in the 1900s to where they are today. Go plan your visit!


Image source

5. Rivers of Steel - Uniquely Pittsburgh Sightseeing Tour

It would probably be a sin to miss a river cruise when you're in the city of rivers and bridges. Especially when it gives you a unique, historical experience of the rich heritage of southwestern Pennsylvania. The Uniquely Pittsburgh sightseeing tour by the Rivers of Steel offers an informative tour to enlighten tourists about the past and present of the beautiful city. You can also find various vantage points for the best views and to click amazing photographs with a backdrop of Pittsburgh. Find out more about this 90-minute river tour here.

​​


Image Source

And that’s not all! There’s so much more to explore in the ‘Burgh while you’re here for DrupalCon North 2023. As spring transitions into summer, June is one of the best months to visit Pittsburgh, with many interesting outdoor events taking place around the city.

But don’t take our word for it. Our Drupal Pittsburgh Local Ambassador, Bill Renk, “Pittsburgh is the perfect fit for DrupalCon because Pittsburgh not only embraces Drupal, as seen by Drupal's adoption by its two major universities (Carnegie Mellon and the University of Pittsburgh), but Pittsburgh is a reflection of the Drupal community itself – friendly, welcoming and hard-working!”

Categories:

The Drop Times: The Dutch Drupal Foundation Welcomes Three New Board Members

Planet Drupal - Wed, 2023/04/12 - 4:28pm
Esmeralda Braad-Tijhoff, Björn Brala and Bart Vreugdenhil has been inducted to the new board of directors of the Dutch Drupal Foundation. Bert Boerland is the new chairman of the board.
Categories:

Lucius Digital: Drupal Theming: how to remove all 'filter tips & guidelines' in Drupal 10 core theme 'Claro'

Planet Drupal - Wed, 2023/04/12 - 4:23pm

So I'd like to keep the admin UI as clean as possible for clients, and since they only use one text format at the moment, all filter guidelines and tips are cluttering the Drupal administration interface too much. So in previous Drupal versions there where modules to fix this, but for 10 not (yet) available.

Also, I'd like to keep overhead to a minimum and 'every module counts', so here is a simple solution.

  • Create a subtheme for Claro
  • Add an extra theme library
  • Let that library contain a css file, that hides filter tips

Also mighty handy for all kinds of additional Drupal administration theme tweaks and optimizations!

Here's the code:

 

Categories:

The Drop Times: TDT Is a Media Partner for DrupalCamp Finland

Planet Drupal - Wed, 2023/04/12 - 3:35pm
TDT is thrilled to share that we are Media Partners for DrupalCamp Finland 2023! DrupalCamp will return to Helsinki in 2023 as a live event on April 28th, 2023.
Categories:

MidCamp - Midwest Drupal Camp: MidCamp Dates, Tickets, and Opportunities

Planet Drupal - Wed, 2023/04/12 - 3:25pm
MidCamp Dates, Tickets, and Opportunities

For those who celebrate, we hope you had a wonderful holiday weekend.

Below are dates to note and read about leading up to MidCamp at the end of this month. We look forward to seeing you!

Important Upcoming Dates Regular Ticket Pricing - Extended to April 21

As always, we are very excited about our line up. All sessions on April 26th and April 27th are included in the price of your registration. Get ready for learning, fun, and reconnecting!

Here are more specifics:

Get your tickets now!


Wednesday Social: Cubs Game

We're taking MidCamp to the friendly confines for Padres @ Cubs. The game begins at 6:40pm. We're asking attendees to buy a ticket through ti.to so that we can have an accurate count of attendees. Your ticket price will be refunded as concessions voucher once you claim your baseball ticket in person.

If you've already got a MidCamp ticket, please go back and add on a ticket to the game. Camp registration is required to attend this event.

More details to come!

Wanted: Day-of Event Volunteers

Want to give back to the Drupal Community without writing a line of code? Volunteer to help out at MidCamp. We’re looking for amazing people to help with all kinds of tasks throughout the event.

Sponsorship Opportunities

We still have sponsorship opportunities available. Here are the basics:

  • Core Sponsor — $4,000

    • Highest access to all MidCamp attendees
    • Venue table on Wednesday and Thursday during sessions
    • Guaranteed session slot
    • Naming rights for any piece of camp on which you'd like to put your name
  • Supporting Sponsor — $1,500

    • A great way to get your name out to attendees
    • We’ll spread the word on the web, email, and at the event, and you'll get free tickets
    • Purchase naming rights for any piece of camp you'd like to put your name on
  • Community Sponsor — $600

    • We'll share your support through the website, social media, and on the opening/closing slides
    • Join us for a great event
Thanks to our Core Sponsors

Wouldn’t it be great to have your logo here?

Stay In The Loop

Join the MidCamp Slack and come hang out with the community online. We will be making announcements there from time to time. We’re also on Twitter and Mastodon.

We can’t wait to see you soon! Don’t forget, cancel all those other plans and make MidCamp the only thing happening on your calendar from April 26-28, 2023.

Categories:

LN Webworks: Why Drupal Commerce is the Future of Ecommerce Website Development

Planet Drupal - Wed, 2023/04/12 - 1:05pm
Are you looking for a robust and versatile eCommerce CMS to take your business to new heights? Look no further than Drupal Commerce!  As eCommerce continues to evolve and businesses strive to stay ahead of the curve, a comprehensive and customizable CMS is more essential than ever before. From contactless payments to millions of product options, the world of eCommerce demands a cutting-edge approach to digital marketing. Why choose Drupal Commerce for eCommerce website development Drupal commerce is a popular Ecommerce CMS that offers powerful customization capabilities for developing an online store that perfectly fits your needs. Whether you're starting a new online store or revamping an existing one, Drupal Ecommerce is an excellent choice for robust and flexible Ecommerce website development. We’ll explore the benefits of Drupal Commerce and why it may be the perfect fit for your online business needs. So, let's dive in!
Categories:

LN Webworks: Why Drupal CMS is Ideal for Your Business?

Planet Drupal - Wed, 2023/04/12 - 12:03pm
Drupal, a widely popular and robust Content Management System (CMS), has emerged as a preferred choice for businesses of all sizes. Its unmatched flexibility and reliability make it a calculated risk for organizations aiming to create successful businesses. A notable aspect of Drupal's credibility is evident from its adoption by industry giants, such as Tesla, GE, Harvard University, and others, for their web content and functions. The CMS framework's ability to offer high-quality web content and functionalities is a testament to its exceptional capabilities. Considering the trust and confidence bestowed upon Drupal by the aforementioned organizations, it is worth delving into the reasons why Drupal can be an ideal fit for businesses looking to streamline their digital presence.
Categories:

Evolving Web: Drupal for Government Websites: 6 Reasons Why It’s the Best Option

Planet Drupal - Wed, 2023/04/12 - 10:42am

Government websites have come a long way since the Clinton administration in the US launched the White House website July 1994—one of the first of its kind on the web in July 1994. Today’s government websites have to do it all for everyone within their jurisdiction, whether that’s a small town of 5,000 people or an entire country. They’re expected to serve as appealing digital front doors, offer a wide range of online services with the utmost efficiency, and provide an inclusive and accessible experience for all—as we saw in our recent blog post on the best government websites of 2023.

Governments are also expected to be responsible with the taxpayer dollars they spend on building and maintaining these websites. When a Government of Canada web overhaul ran over-budget by over $7 million in 2016, the media had a field day with the story.

It’s little surprise that many government websites struggle to keep up with the tall orders placed upon them. A whopping 80% of US federal agencies ranked “poor” or “very poor” compared with just 14% of private sector brands, according to Forrester’s 2019 US Federal Customer Experience Index. While COVID-19 helped accelerate the move towards e-government, the public sector still has a lot of catching up to do.

What Matters Most for Governments

Creating an optimal website for a municipality, region, or federal department means checking off a lot of boxes. Key priorities include:

  • Flexibility – Government websites are expected to facilitate a wide range of public services. This helps reduce the burden on government employees, whether in person at offices or on phone lines.
  • Scalability – Government websites need to be able to expand and evolve alongside the services that they provide access to.
  • Accessibility – Governments are held to the world’s highest standards when it comes to web accessibility for people with disabilities. In a growing number of jurisdictions, compliance with WCAG 2.0 level AA and beyond is required by law.
  • Security – Government websites are particularly vulnerable to cyber attacks, ranging from ransomware and data breaches to election security and unemployment fraud.
  • Transparency – Governments are expected to be transparent in their use of public money for expenditures such as website development and maintenance.
The Popularity of Drupal for Government Websites

When it comes to government websites, Drupal is everywhere. As of 2021, roughly 56% of the world’s government websites used it. Several countries—including Australia, Estonia, France, Germany, India, and South Africa—house their central government portals on Drupal, while nearly every other national government uses it for at least some agencies. Whitehouse.gov famously lived on Drupal from 2009 to 2017, an early move by the Obama administration aimed at showing transparency.

Some of the other major jurisdictions on Drupal include London, Los Angeles, Washington DC, Buenos Aires, New York State, New South Wales, Western Australia, and Northern Ireland to name a few.

Among international bodies, 78 out of a total of 117 organizations within the United Nations and World Bank used Drupal as of November 2022, including un.org itself and the International Criminal Court.

Some 25% of all government websites in Canada now live on Drupal. These include the:

  • Office of the Prime Minister
  • Royal Canadian Mounted Police (RCMP)
  • Canadian Security Intelligence Service (CSIS)
  • Open Data Canada
  • Government of Ontario
Why Do Governments Choose Drupal?

There are many reasons for Drupal’s outsized presence globally among government websites. Here are a few of them.

1. Transparency and accountability

There are clear cost advantages to opting for an open-source CMS like Drupal versus a proprietary one, as highlighted by the Government of Canada’s expensive misadventure with Adobe Corp. While Drupal sites aren’t free to build, the costs are much easier to manage due to the lack of licence fees associated with the platform. This is especially true when expanded across dozens, if not hundreds, of government departments.

Drupal also makes cost management easier after the sites have been built. Prior to their consolidation under Canada.ca, the Government of Canada maintained a fleet of unique websites on different CMSs, making for complex and costly maintenance and upgrades. By contrast, Drupal makes it easy for government departments to share existing customizable website code and replicate designs, features, and functionality.

Furthermore, as an open-source platform, Drupal makes it relatively easy for organizations to migrate their sites to a different platform (in the unlikely event they want to!). This isn’t the case with proprietary platforms, whose customers have the choice of either sticking with the provider or starting again from scratch—as proved to be the case with Canada.ca and Adobe.

From a taxpayer accountability standpoint, the choice is clear—open source is the way to go.

2. Performance under pressure

How important is performance optimization? For high-traffic websites like many government sites are, immensely. In 2018 the BBC found it was losing some 10% of its audience for every extra second it took their site to load. For government websites, delays in loading mean frustrated constituents at best, and at worst can jeopardize the relaying of vital information.

Government websites may not be high traffic all the time, but they need to be ready to manage massive spikes in traffic.

  • Federal revenue agencies are pushed to their limit at tax time. 
  • Disaster relief agencies must be ready for major surges in traffic at any time. 
  • National and regional health authorities were caught off guard during the pandemic. 

Even small municipalities should have the digital capabilities to respond to an unexpected crisis—as we explained in our recent blog: Surviving Snowmageddon: Is Your Comms Strategy Emergency-Ready?

When it comes to performance under pressure, Drupal significantly outperforms other open source platforms such as WordPress. Drupal was created from the very beginning to be highly efficient and capable of managing heavy traffic loads. Drupal also has built-in caching and file aggregation mechanisms that allow site managers to speed up page loading time and save the data transfer.

3. Security

There’s no truth to the widely held belief that proprietary websites are more secure than open-source ones, as we discussed in our recent open source myth-busting blog post. While open-source code is available to anyone, including bad actors, Drupal has a veritable army of contributors working behind the scenes to identify and patch up weaknesses in the platform’s armour.

Drupal’s popularity among government agencies attests to its peerless security. Drupal beats WordPress in its handling of complex security situations such as PCI compliance, which requires database encryption, while WordPress’ greater reliance on third-party extensions makes it more vulnerable. There’s also the simple fact that there are far more WordPress sites out there than Drupal sites, which means WordPress gets targeted more frequently than Drupal. Of course, it’s worth remembering that any CMS is a sitting duck when not properly updated. 

A further advantage of Drupal for governments is its handling of sensitive data. WordPress is notably vulnerable in this area. It stores files in the /wp-content/uploads/[YEAR]/[MONTH] directory, meaning it’s fairly straightforward for someone with basic knowledge of WordPress (and a bit of luck) to gain unauthorized access to files. Drupal is much more secure in this regard: it only grants access to these types of files if the user has appropriate permissions.

According to a recent analysis, WordPress accounts for nearly three quarters (74%) of all hacked websites, while representing around 64% of the web. Drupal, by contrast, represents around 2% of all cyber attacks. Considering its share of over 10% of the top 10,000 sites, those are pretty good odds.

4. Flexibility and scalability

Another important need for government websites is an ability to adapt and expand alongside government services. Your site must be both flexible and scalable, whether you’re introducing a new bus pass system, rolling out pandemic protocols, amalgamating with a neighbouring municipality, or adding services in a new language.

The open-source model of Drupal means you’re never really stuck with what you’ve got. Its vast community of developers contributes to an ever-expanding library of plug-and-play-ready modules—nearly 50,000 as of mid-February 2023—meaning there’s very little Drupal can’t do. Meanwhile, the lack of licensing fees makes expanding your site significantly less costly than it would be on a proprietary platform.

Drupal is overall a more flexible platform than WordPress and thus a better option for deep customization. It offers a flexible and extensive taxonomy system that makes it better suited to handling large volumes of content. And it has built-in multi-language support—a must for many jurisdictions. Drupal is also more flexible than WordPress on the back end. With advanced user permissions for unlimited roles, it’s better suited to marketing and IT teams whose numbers are liable to expand.

Government services and personnel are forever adapting with the times, and you need a CMS that is similarly adaptable. Drupal is that CMS.

5. Accessibility

One of the inherent strengths of open source platforms like Drupal is their ongoing commitment to inclusivity and the diversity of their contributing communities. This has made open source platforms the major driving force behind web accessibility.

Proprietary vendors will get you to bare minimum level of accessibility—WCAG 2.0 AA for most government websites. But anything beyond that in terms of customization for web accessibility will quickly get very expensive. By contrast, Drupal is constantly introducing new accessible components that teams can easily use to expand their sites while ensuring accessibility throughout.

While Drupal isn’t inherently more accessible than any other platform, its customizability and the sheer volume of its contributed accessible modules make it the logical choice for governments.

6. Personalization

Governments have been slower to embrace digital personalization than the private sector, but some have made noteworthy advances in this area. Personalization enables governments to foster 1:1 online relationships with citizens. And it helps site visitors navigate the enormous volume of information typically housed on government websites by promoting content that’s relevant to individual users.

When it comes to personalization, Drupal leaves all other open-source platforms in the dust. Its capacity for deep customization includes a range of built-in and contributed personalization modules. Meanwhile, its close partners at Acquia offer a cloud-based, Drupal-optimized personalization platform that provides state-of-the-art personalization across multiple channels.

Bonus for Canadian government agencies

If you’re a Canadian federal government agency—or simply want your website to have the look and feel of the Government of Canada—Drupal has you covered. The Web Experience Toolkit (WxT) is a version of Drupal tailored for the Canada.ca design system as well as other government sites, covering similar requirements regarding accessibility, usability, interoperability, and bilingualism.

For more information on how to install WxT and its many features, read our recent blog post on the subject.

Want to Master the Fundamentals of Drupal?

We’re experts in applying open source power and flexibility to the dynamic needs of a Government’s website.

//-->

+ more awesome articles by Evolving Web
Categories:

Opensource.com: 7 open source modules to make your website accessible

Planet Drupal - Wed, 2023/04/12 - 9:00am
7 open source modules to make your website accessible neerajskydiver Wed, 04/12/2023 - 03:00

Use these Drupal modules to make your website accessible to everyone.

As website accessibility continues to be a growing concern, website owners and developers need to ensure that their websites comply with the Americans with Disabilities Act…

Categories:

The Drop Times: Owning It, Giving Back and Building It Better: Interview with John Doyle

Planet Drupal - Wed, 2023/04/12 - 8:38am
Follow through with TDT's interview with John Doyle Founder Digital Polygon and how the idea for his company came about.
Categories:

Specbee: Revitalize Your Forms: Enhancing User Experience with Drupal's Form API

Planet Drupal - Tue, 2023/04/11 - 8:41am
Revitalize Your Forms: Enhancing User Experience with Drupal's Form API Nitin Lama 11 Apr, 2023 Subscribe to our Newsletter Now Subscribe Leave this field blank

Did you know “form fatigue” is a thing?! It’s a feeling of exhaustion when you have to fill out too many forms. But forms are an integral part of a website and no site owner can (or should) do without them. So how can you make sure your website helps reduce form fatigue? Easy! Keep it simple and short, offer clear and concise instructions, break up long forms, and use autofill. Most important of all, make sure you’re offering a breezy user experience to fill them out.

Drupal’s Form API offers a way to create easily customizable and themeable forms to blend well with any website. It provides developers with a set of functions and APIs to create, validate and process forms in Drupal. Take a deeper dive into the amazing Drupal Form API and find out how you can implement it in your next project.

Why Form API

As you know, forms are a crucial part of every website because they allow users to interact with them by submitting data. Using Drupal's Form API, developers can create unique forms for various purposes, including contact, login, and registration. A few reasons why you should consider Form API:

  1. It is easy to use and does not require much coding experience. You can create forms using a set of simple and intuitive functions.
  2. It provides built-in validation functions that allow you to validate form data easily. 
  3. Comes with built-in security features that help prevent attacks like cross-site scripting (XSS) and cross-site request forgery (CSRF).
  4. It is highly customizable and can be used to create complex forms with multiple fields, buttons, and actions.
  5. Form APIs are themeable, so developers can change CSS and HTML to make their forms look however they want.
  6. It can be easily integrated with other Drupal APIs.
Things you need to know before building forms

There are various kinds of forms that are often used in Drupal. Each contains a base class that you can extend in a unique module of your own design.

First, identify the type of form you need to build:

  • A generic form. Extend FormBase.
  • A configuration form that enables administrators to update a module's settings. Extend ConfigFormBase.

Any form that has FormBase in its hierarchy must implement the following methods since FormBase implements FormInterface.

To create a generic custom form with the Form API, you'll need to define a function that returns an array of form elements inside buildForm(). The key of each element is the name of the form element, and the value is an array of properties that define the element. For example, to create a text field, you would define an element like this:

$form['emp_name'] = [ '#type' => 'textfield', '#title' => $this->t('Enter Name'), '#required' => TRUE, ]; Adding validation

Form API also provides a way to validate user input. You can add validation functions to your form definition that will be called when the form is submitted. If a validation function returns an error message, the form submission will be prevented and the error message will be displayed to the user.

To add a validation function, you will need to implement a validateForm().

Processing form submissions

When a form is submitted, Drupal calls a submission function that you define. The submission function can perform any necessary processing of the form data, such as saving it to the database

To define a submission function, you will need to implement a submitForm()

Integrate the form in a request

To integrate this form into a Drupal site's URI structure, use a route like the following:

example.form: path: '/example-form' defaults: _title: 'Example form' _form: '\Drupal\example\Form\ExampleForm' requirements: _permission: 'access content'

The _form key tells the routing system that the provided class name is a form class to be instantiated and handled as a form.

Creating a custom form with Drupal Form API

Follow these easy step to begin the process of creating a custom form with Drupal’s Form API:

  1. Create a .info.yml inside a custom module. (As we are creating a separate module for custom forms, this step is not required for adding forms in an existing module).
  2. Create a form class for returning the form array. (custom_module/src/Form/Registration.php
  3. Create a .routing.yml file
  4. Create a .module and hook_form_alter() and/or hook_form_FORM_ID_alter() to alter the form (If needed).

Here is a complete example of an employee registration form:

Folder structure:

 

1. employee_registration.info.yml

name: Employee Registration Form type: module description: Custom module for implementing custom employee registration form. core_version_requirement: ^9 || ^10 package: Custom

2. src/Form/Registration.php

<?php namespace Drupal\employee_registration\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; /** * Implements a custom form. */ class Registration extends FormBase { /** * {@inheritdoc} */ public function getFormId() { return 'employee_registration_form'; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['emp_name'] = [ '#type' => 'textfield', '#title' => $this->t('Enter Name'), '#required' => TRUE, ]; $form['emp_no'] = [ '#type' => 'textfield', '#title' => $this->t('Enter Employee Number'), '#required' => TRUE, ]; $form['emp_mail'] = [ '#type' => 'email', '#title' => $this->t('Enter Email ID'), '#required' => TRUE, ]; $form['emp_phone'] = [ '#type' => 'tel', '#title' => $this->t('Enter Contact Number'), ]; $form['emp_dob'] = [ '#type' => 'date', '#title' => $this->t('Enter DOB'), '#required' => TRUE, ]; $form['emp_gender'] = [ '#type' => 'select', '#title' => $this->t('Select Gender'), '#options' => [ 'Male' => $this->t('Male'), 'Female' => $this->t('Female'), 'Other' => $this->t('Other'), ], ]; $form['submit'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary', ]; return $form; } /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { if (strlen($form_state->getValue('emp_phone')) < 10) { $form_state->setErrorByName('emp_phone', $this->t('The phone number is too short. Please enter a full phone number.')); } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Processing form data. $this->messenger()->addMessage($this->t("Employee Registration Done!!")); foreach ($form_state->getValues() as $key => $value) { $this->messenger()->addMessage($key . ': ' . $value); } } }

3. employee_registration.routing.yml

employee_registration.form: path: '/registration-form' defaults: _title: 'Employee Registration' _form: '\Drupal\employee_registration\Form\Registration' requirements: _permission: 'access content'

Result:

 

Final Thoughts

Form API lets you create complex and customized forms with validation and processing functions in Drupal. When you use Form API, you can be sure that your forms are consistent and easy to use for your users. Looking for a Drupal agency to help you build a user-friendly experience for your audience? Talk to our Drupal experts today!

Author: Nitin Lama

Meet Nitin Lama, a backend Drupal Developer at Specbee who believes progressing one day at a time could go a long way. Swimming is his hobby, but he’s a huge music lover and enjoys producing and exploring new music. Music and cooking act as therapy for him. Space and tech are his best conversation starters when meeting new people. If dreams came true, he’d be traveling to a Voyager station!

Email Address Subscribe Leave this field blank Drupal Drupal Module Drupal Development Drupal Planet

Leave us a Comment

  Recent Blogs Image Revitalize Your Forms: Enhancing User Experience with Drupal's Form API Image Cheat Codes in Music - Nitin Lama’s Life in a Mirage Image Customizing Content Display in Drupal: A Guide to Display Modes Want to extract the maximum out of Drupal? TALK TO US Featured Case Studies

Upgrading the web presence of IEEE Information Theory Society, the most trusted voice for advanced technology

Explore

A Drupal powered multi-site, multi-lingual platform to enable a unified user experience at SEMI

Explore

Great Southern Homes, one of the fastest growing home builders in the US, sees greater results with Drupal

Explore
View all Case Studies
Categories:

Talking Drupal: Talking Drupal #394 - Open Source in K-12 Education

Planet Drupal - Mon, 2023/04/10 - 8:00pm

Today we are talking about Open Source in K-12 Education with Stu Keroff.

For show notes visit: www.talkingDrupal.com/394

Topics
  • What is the Penguin Corp
  • Why is Open Source important
  • How can educators bring open soiurce to their classroom
  • How difficult is it to change from closed to open source
  • What are some resources
  • Youtube Channel
  • Hurdles to introducing open source
  • Types of software you’ve introduced
  • Sourcing hardware
  • What to say to the question: Why is this important?
  • Video games
  • Statistics
  • Homeschooling
  • How to help
Resources Guests

Stu Keroff - @studoeslinux

Hosts

Nic Laflin - www.nLighteneddevelopment.com @nicxvan John Picozzi - www.epam.com @johnpicozzi Kat Shaw - drupal.org/u/katannshaw @katannshaw

MOTW Correspondent

Martin Anderson-Clutz - @mandclu H5P Provides a toolset for adding HTML5 rich content to your site: interactive videos, presentations, quizzes, games, and more.

Categories:

The Drop Times: The Pleasure of Reporting Drupal

Planet Drupal - Mon, 2023/04/10 - 11:28am

Journalism, in essence, is the job of painting a picture in the readers’ minds. Unlike actual painting, we don’t use colours. Instead, languages, words and letters fill our palette. We use it to report the facts that lie before us to a broader audience. The process of creating a news story is indeed complex. It requires us to go through layers of verification, self-doubt and delivering near-perfect write-ups within the deadline. If the work fails to entice pleasure or provide enjoyment, it becomes a meaningless burden.

At TheDropTimes (TDT), our journalistic work revolves around Drupal. Day in and day out, we fix our eyes on Drupal-related developments around the globe. We know there is a thriving community waiting for more news about Drupal. That’s the first stimulus of pleasure in reporting—Drupal is not just software. Drupal is a microcosm of human endeavour. The Free and Open-Source platform stands in the middle, surrounded by an ecosystem relentlessly working to improve it. The freedom that Drupal hands down to its users is yet another pleasure trigger. Who in the world dislikes space? Liberty opens the skies and lets magic rain. The same is happening with Drupal. In short, though reflecting upon the jargon-rich Drupal is a challenge for the soft-hearted, it gives us meaningful pleasure—the pleasure of reporting Drupal.

Check out the hand-picked stories from the past week:

To start with, TDT has launched a new series of blogs on its behind-the-scene tales. The first of the series, written by Vimal Joseph, throws light on the technology that powers TDT. Read how Drupal and Thunder distribution light up TheDropTimes.

Dries Buytaert, Drupal’s founder, has published a new blog post about the evolution of Drupal’s composability. This article introduces the readers to Dries’ blog and points out how Drupal will provide an ‘App-Store’ like experience. Dries’ earlier blog post was a myth-buster questioning the assertion that Static Site generators are faster than Content Management Systems.

To know about the automation of an e-commerce order on Drupal, read our take on the blog published by ComputerMinds. This article will be helpful for anyone interested in ‘Microsites’ developed by LocalGov Drupal and its ability to handle multiple sites. Also, see why Danny Bluestone thinks Drupal is the best enterprise choice.

The Drop Times is now a media partner for upcoming events like the Stanford WebCamp, Drupal Developer Days, Vienna and DrupalCamp Ruhr.

Drupal4Gov is hosting an in-person half-day event on the 18th. DrupalJam has opened the call for speakers. Drupal Diversity and Inclusion Camp dates are declared. The Melbourne Drupal Group is organizing another meetup on 13 April 2023. Florida DrupalCamp organizers have announced the dates for the 2024 edition of the camp.

Please read the article about Drupal Associations’ call to find community at DrupalCon Pittsburgh. Drupal Swag Shop is pursuing promoting sustainability through its products.

SpecBee’s new blog post offers readers a comprehensive guide to understanding display modes and their applications in Drupal. To clear any doubts regarding adding a JavaScript Library to an Emulsify component, refer to this tutorial. Any Drupal developer who wants to take their skills to the next level must not miss this online training scheduled on the 11th. A11yTalks has announced its upcoming meetup on 12 April 2023 at 6:00 PM EDT. The topic of the meetup is ‘Shifting Left: How CMS Accessibility Can Help.’

Global digital transformation services and product engineering company, EPAM, has been named a Top IT Sourcing Vendor in the Nordics by the independent research organization Whitelane Research. The Australian Web Industry Association has declared the finalists for the Australian Web Awards 2023. Morpht and other Drupal-based service providers have secured a place in the final list. Read the article to know more about the awards and the finalists.

A group of developers seeks responses from the Drupal community regarding the Field UI. Don’t forget to fill it out and help them improve Field UI’s performance.

Sincerely,
Thomas Alias K.
Sub-Editor

Categories: