Problem/Motivation

The following procedural functions are not marked with an underscore prefix:

name_component_description_after_build_label_alter()
name_element_expand()
name_element_render_component()
name_element_validate()
name_element_validate_is_empty()
name_get_additional_component()
name_get_custom_format_options()
name_get_custom_list_format_options()
name_get_format_by_machine_name()
name_user_format_name_alter_preload()
name_widget_layouts()

While not a code-standards requirement, an underscore prefix is sometimes used in procedural code to signal “internal” helpers vs hook implementations. Those globals are still part of the global function namespace and can be mistaken for public API.

This issue will not add new underscore-prefixed global functions. Prefer moving logic into namespaced classes: @internal services and static methods (including Form API callables), with optional thin deprecated procedural wrappers only where backward compatibility is required—wrappers should delegate to the class or service, not to another global.

Proposed resolution

Refactor internal helpers into services and static methods so “internal” is expressed by visibility and PHPDoc, not by _name_* functions.

  • Services (dependency injection, entity storage, cache, hooks):
    • name_widget_layouts() — cache + ModuleHandler::invokeAll('name_widget_layouts').
    • name_get_custom_format_options(), name_get_custom_list_format_options(), name_get_format_by_machine_name() — config entity storage; can live on one focused service or alongside existing providers (e.g. name.options_provider).
    • name_get_additional_component() — move body to a service using EntityTypeManager and Renderer (call sites stop passing those manually).
    • name_user_format_name_alter_preload() — config + entity load; small dedicated service.
    • name_element_validate() — uses ModuleHandler (e.g. inline_form_errors); implement in a service, expose a static method on Drupal\name\Element\Name (or similar) that forwards to the service for the #element_validate callable.
  • Static methods (Form API #process, #after_build, and pure structure / emptiness checks):
    • name_element_expand(), name_element_render_component() — align with existing Name::preRender(): static process + private/protected static helper.
    • name_component_description_after_build_label_alter() — static #after_build callback.
    • name_element_validate_is_empty() — static (or protected static) on the element class; no container needed.

Document replacements with @internal where appropriate. Keep deprecated global wrappers that delegate to the new API until the next major, per existing policy—without introducing underscore-prefixed globals.

Remaining tasks

  • Add or extend services in name.services.yml and implement the extracted logic with constructor injection.
  • Move Form API callables to [Name::class, 'methodName'] (or equivalent) and update tests that assert string callback names.
  • Replace internal calls in the module with services/static methods; keep deprecated procedural functions only as thin delegators if documented API requires it.
  • Update developer docs that reference the old function names.

API changes

Procedural helpers are deprecated in favor of the new class/service API and removed in the next major release. No new _name_* global functions are introduced.

Note: name_element_pre_render() is already deprecated in favor of Drupal\name\Element\Name::preRender(); follow the same pattern for the other element callbacks.

Issue fork name-3555260

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jcandan created an issue. See original summary.

sagar2106 made their first commit to this issue’s fork.

sagar2106’s picture

Status: Active » Needs review

I have updated the underscores, deprecated function calls and have placed the deprecation notices. The previous push had a duplicate function error and an infinite loop, which are now resolved. The pipeline is now passing. It is ready for review!

meet.h.thakkar’s picture

I provided @sagar2106 with mentoring and technical guidance during the development of this fix, including helping diagnose and resolve an initial CI pipeline failure, and I have checked https://git.drupalcode.org/project/name/-/merge_requests/63 , which looks good to me.

jcandan’s picture

Status: Needs review » Needs work

The lint and code standards tests need to pass, but good work so far.

meet.h.thakkar’s picture

Status: Needs work » Needs review

I have addressed the lint and coding standard issues. The only remaining PHPStan warning is in NameNodeTokenReplaceTest.php for the node_add_body_field() method. Since this function is deprecated in Drupal 11.3.0 and removed in 12.0.0 with no direct replacement, I wanted to flag this for review.

bluegeek9 made their first commit to this issue’s fork.

bluegeek9 changed the visibility of the branch 8.x-1.x to hidden.

bluegeek9’s picture

Title: Prefix procedural functions with an underscore » Refactor procedural functions insto services, or static methods
Issue summary: View changes
Issue tags: -good first issue

bluegeek9 changed the visibility of the branch 3555260-fix to hidden.

bluegeek9’s picture

Status: Needs review » Active
liam morland’s picture

Title: Refactor procedural functions insto services, or static methods » Refactor procedural functions into services or static methods

bluegeek9’s picture

Status: Active » Needs review

  • bluegeek9 committed c47d2c46 on 8.x-1.x
    feat: #3555260 Refactor procedural functions into services or static...
bluegeek9’s picture

Status: Needs review » 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.

bluegeek9’s picture

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:

Status: Fixed » Closed (fixed)

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