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 usingEntityTypeManagerandRenderer(call sites stop passing those manually).name_user_format_name_alter_preload()— config + entity load; small dedicated service.name_element_validate()— usesModuleHandler(e.g.inline_form_errors); implement in a service, expose a static method onDrupal\name\Element\Name(or similar) that forwards to the service for the#element_validatecallable.
- Static methods (Form API
#process,#after_build, and pure structure / emptiness checks):name_element_expand(),name_element_render_component()— align with existingName::preRender(): static process + private/protected static helper.name_component_description_after_build_label_alter()— static#after_buildcallback.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.ymland 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
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
Comment #4
sagar2106 commentedI 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!
Comment #5
meet.h.thakkar commentedI 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.
Comment #6
jcandan commentedThe lint and code standards tests need to pass, but good work so far.
Comment #7
meet.h.thakkar commentedI 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.
Comment #10
bluegeek9 commentedComment #12
bluegeek9 commentedComment #13
liam morlandComment #15
bluegeek9 commentedComment #17
bluegeek9 commentedComment #19
bluegeek9 commented