This simple module is provided as a workaround for https://www.drupal.org/project/webform/issues/3278864.

It changes the UX of the out-of-the-box Webform configuration for the telephone element type. If you install this module, you can add US phone numbers like 1012 345 6789 or 012 345 6789 and are accepted.

The user @luke.leber created the project initially, but I'm the main maintainer at the moment, given that he's pretty busy at the moment.

Project link

https://www.drupal.org/project/webform_intl_tel_national_mode

Comments

danrod created an issue. See original summary.

avpaderno’s picture

Thank you for applying!

Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

The important notes are the following.

  • If you have not done it yet, enable GitLab CI for the project, and fix what reported from the phpcs job. This help to fix most of what reviewers would report.
  • For the time this application is open, only your commits are allowed. No other people, including other maintainers/co-maintainers can make commits.
  • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application.
  • Nobody else will get the permission to opt projects into security advisory policy. If there are other maintainers/co-maintainers who will to get that permission, they need to apply with a different module.
  • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

To the reviewers

Please read How to review security advisory coverage applications, Application workflow, What to cover in an application review, and Tools to use for reviews.

The important notes are the following.

  • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
  • Reviewers should show the output of a CLI tool only once per application. The configuration used for these tools needs to be the same configuration used by GitLab CI, stored in the GitLab Templates repository.
  • It may be best to have the applicant fix things before further review.

For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues.

vishal.kadam’s picture

Status: Needs review » Needs work

1. FILE: webform_intl_tel_national_mode.info.yml

core_version_requirement: ^9 || ^10 || ^11

FILE: composer.json

    "require": {
        "drupal/core": "^9 || ^10 || ^11",

A new project should not declare itself compatible with a Drupal release that is no longer supported. No site should be using Drupal 8 nor Drupal 9, and people should not be encouraged to use those Drupal releases.

2. FILE: webform_intl_tel_national_mode.libraries.yml

version: VERSION

VERSION is only used by Drupal core modules. Contributed modules should use a literal string that does not change with the Drupal core version a site is using.

3. FILE: webform_intl_tel_national_mode.module

/**
 * @file
 * Implements webform intl tel national mode.
 */

The usual description for a .module file is “Hook implementations for the [module name] module”, where [module name] is the module name given in the .info.yml file.

danrod’s picture

Thanks @vishal.kadam

I addressed the issues you pointed out, and can be reviewed in the DEV version now:

https://www.drupal.org/project/webform_intl_tel_national_mode/releases/1...
https://git.drupalcode.org/project/webform_intl_tel_national_mode

danrod’s picture

Status: Needs work » Needs review
avpaderno’s picture

Assigned: Unassigned » avpaderno
avpaderno’s picture

Assigned: avpaderno » Unassigned
Status: Needs review » Needs work
  • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
  • A specific point may just be an example and may apply in other places
  • A review is about code that does not follow the coding standards, contains possible security issue, or does not correctly use the Drupal API
  • The single review points are not ordered, not even by importance

webform_intl_tel_national_mode.info.yml

The dependencies follow the format <project name>:<module name>. What used for the Webform module is not correct.

webform_intl_tel_national_mode.module

For a new module that aims to be compatible with Drupal 10 and Drupal 11, I would rather implement hooks as class methods as described in Support for object oriented hook implementations using autowired services.
It would require increasing the minimum Drupal 10 version supported, but Drupal 10.1 is no longer supported.

      $output .= '<p>' . t('This module is provided as a workaround for  <a href=":link">project page</a>.', [':link' => 'https://www.drupal.org/project/webform_intl_tel_national_mode']) . t(' To submit bug reports and feature suggestions, or track changes
        visit the <a href=":link">project issue page</a>.', [':link' => 'https://www.drupal.org/project/issues/webform_intl_tel_national_mode']) . '</p>';
      return $output;

    default:

Before <a href=":link">project page</a> there is an extra space that needs to be removed.
I would rather use use a single translated string instead of two strings, but really the second string is providing information the README.md file already provides.
The first string should be more specific than saying the module provides a workaround. This module changes the UX of the out-of-the-box Webform configuration for the telephone element type. is more descriptive. Yes, it repeats what the README.md file says, but the description of the module can be repeated. (It helps administrators to remember which modules the site has.) What hook_help() implementations should not do is repeating everything the README.md file says.

The help says This module is provided as a workaround for project page which is not correct because:

  • The workaround is not for a project page, but for a project, so the sentence should say for which project the workaround is
  • The provided link is for the project providing the workaround

composer.json

The Drupal core restrictions have not been updated, but really providing that is not necessary, since the composer.json file provide by drupal.org will automatically add the drupal/core line when the composer.json file does not provide it.

Also, the restrictions provided for the Webform module should be provided also in the .info.yml file, so that Drupal core does not install the module with a different version of the Webform module.

Drupal 10 requires at least PHP 8.1; the PHP requirement is not necessary.

danrod’s picture

Thanks @avpaderno

I addressed the issues you pointed out, and can be reviewed in the 1.0.x branch now: https://git.drupalcode.org/project/webform_intl_tel_national_mode

danrod’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work

webform_intl_tel_national_mode.module

There are still hooks in the .module file which have not been converted.

Since the module is declared compatible with Drupal 10.3, removing the function implementing the hook is not possible. The function still needs to be defined, but it calls the method defined by the service class, as described in Support for object oriented hook implementations using autowired services (Backwards-compatible Hook implementation for Drupal versions from 10.1 to 11.0).

There are PHP_CodeSniffer warnings/errors which need to be fixed.

danrod’s picture

Hello @avpaderno

Sorry for the delay on the fixes, I think I addressed all of them, please have a look and let me know if you have more questions.

I also fixed the PHPCS / PHPSTAN errors, I'll move this to review again.

danrod’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work

webform_intl_tel_national_mode.module

function webform_intl_tel_national_mode_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the webform_intl_tel_national_mode module.
    case 'help.page.webform_intl_tel_national_mode':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This module changes the UX of the out-of-the-box Webform configuration for the telephone element type. This module fixes <a href=":link">this issue</a> for this element type.', [':link' => 'https://www.drupal.org/project/webform/issues/3278864']);

      return $output;

    default:
  }
}

/**
 * Implements hook_library_info_alter().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
// phpcs:ignore
function webform_intl_tel_national_mode_library_info_alter(&$libraries, $extension) {
  if ($extension === 'webform') {
    if (isset($libraries['webform.element.telephone'])) {
      if (isset($libraries['webform.element.telephone']['js']['js/webform.element.telephone.js'])) {

        unset($libraries['webform.element.telephone']['js']['js/webform.element.telephone.js']);

        /** @var \Drupal\Core\Extension\ModuleExtensionList $module_extension_list */
        $module_extension_list = \Drupal::service('extension.list.module');

        $js_path = implode(DIRECTORY_SEPARATOR, [
          '',
          $module_extension_list->getPath('webform_intl_tel_national_mode'),
          'js',
          'webform.element.telephone.js',
        ]);

        $css_path = implode(DIRECTORY_SEPARATOR, [
          '',
          $module_extension_list->getPath('webform_intl_tel_national_mode'),
          'css',
          'webform.element.telephone.css',
        ]);

        $libraries['webform.element.telephone']['js'][$js_path] = [];
        $libraries['webform.element.telephone']['css']['theme'][$css_path] = [];
      }
    }
  }
}

The functions are correctly using attributes. They need to call the service methods, instead of duplicating their code.
Once the module is only compatible with Drupal 11 or higher versions, the procedural implementation of the hooks can be removed, together the definition of the Drupal\webform_intl_tel_national_mode\Hook\WebformIntlTelNationalModeHooks service in the webform_intl_tel_national_mode.services.yml file.

avpaderno’s picture

For example, in a module I maintain, the hook implementations change to the following ones.

/**
 * Implements hook_cron().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
function user_restrictions_cron(): void {
  Drupal::service(UserRestrictionsCronHooks::class)->cron();
}

/**
 * Implements hook_help().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
function user_restrictions_help($route_name, RouteMatchInterface $route_match): string {
  return Drupal::service(UserRestrictionsHelpHooks::class)->help($route_name, $route_match);
}

/**
 * Implements hook_form_alter().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
function user_restrictions_form_alter(&$form, &$form_state, $form_id): void {
  Drupal::service(UserRestrictionsFormHooks::class)->userFormAlter($form, $form_state, $form_id);
}
danrod’s picture

Hello @avpaderno,

Thanks a lot, I didn't realise this and I think I have the same problem (duplicate code instead of call to service methods) in some of the modules that I maintain, and of course I'll fix that too.

Meanwhile, I removed the duplicate code here and replaced it with the corresponding calls to the service methods, please review again.

Thanks a lot for your help and guidance, much appreciated. I also tested this on a D10.5.4 instance and worked like a charm.

Thanks!

danrod’s picture

Status: Needs work » Needs review
avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Reviewed & tested by the community

As a side note, I found https://www.drupal.org/node/3442349#comment-16224531, which explains that including the PHPStan directive inside the documentation comment avoids PHP_CodeSniffer complains about the comment between the documentation comment and the function.

/**
 * Implements hook_cron().
 *
 * @phpstan-ignore-next-line
 */
function user_restrictions_help(($route_name, RouteMatchInterface $route_match): string {
  return Drupal::service(UserRestrictionsHelpHooks::class)->help($route_name, $route_match);
}

Thank you for your contribution and for your patience with the review process!

I am going to update your account so you can opt into security advisory coverage any project you create, including the projects you already created.

These are some recommended readings to help you with maintainership:

You can find more contributors chatting on Slack or IRC in #drupal-contribute. So, come hang out and stay involved!
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank also all the reviewers for helping with these applications.

avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

danrod’s picture

Thanks a bunch @avpaderno !!
For sure I will help the review process. Have a great evening !!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.