Re-write Ip2CountrySettingsForm to eliminate JavaScript

Created on 5 November 2022, about 2 years ago
Updated 8 September 2024, 5 months ago

Problem/Motivation

The Ip2CountrySettingsForm is the main administration page for this module. It allows you to configure the module but it also provides a way to manually update the Ip2Country database and manually look up IP addresses. It also allows you to turn on debugging and set debugging preferences.

This form uses jQuery and Ajax to provide dynamic elements. This jQuery and Ajax was written back in Feb 2009 for use in Drupal 5 when this module was first published, and it has not changed since then. As long as it remained working (and it did) I saw no reason to mess with it.

However, Drupal core has drastically improved, and there are now simple ways to add these dynamic elements without using explicit JavaScript code - this can all be done within the Form API. Additionally, jQuery is deprecated for use in Drupal. Changing Ip2Country to use these new Form API methods and to get rid of our old jQuery code makes the module more maintainable and require less code. With the move to GitLab CI and new testing tools and coding standards (including JavaScript coding standards), the time has come to re-write this functionality to bring it up to current standards and best practices.

Proposed resolution

Remove the jQuery code. Rewrite Ip2CountrySettingsForm to use #states and #ajax for the dynamic elements. Update CSS files. Preserve old controller class, as it still may be useful, but return proper JsonResponse objects.

Original issue

Problem/Motivation

With jquery removed from core in 9.0, we should also stop requiring it for this module.
What do you think?

📌 Task
Status

Fixed

Version

2.1

Component

Code

Created by

🇮🇹Italy trickfun

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024