Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
core.services.yml marks form_cache
as a private service:
form_cache:
class: Drupal\Core\Form\FormCache
arguments: [...]
public: false # Private to form_builder
Drupal\Core\Form\FormCacheInterface: '@form_cache'
form_cache
is private, but the Drupal\Core\Form\FormCacheInterface
alias is public:
> \Drupal::service('form_cache');
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException You have requested a non-existent service "form_cache". Did you mean this: "views.exposed_form_cache"?
> \Drupal::service('Drupal\Core\Form\FormCacheInterface');
= Drupal\Core\Form\FormCache {#9939}
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3432957
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 #3
longwaveMR reuses the visibility of the aliased service, unsure if this is the correct approach but seems to work.
Comment #4
longwaveSome test failures to sort out.
Comment #5
longwaveFixed some tests.
backend_overridable
backend services must follow the visibility of the service being overridden. JSON:API had a public alias to a private service in a test, which was relying on this behaviour; worked around this by adding another compiler pass to the test to make the service public again.Comment #6
longwaveAlternatively maybe we should just explicitly copy the visibility of the original alias in autowired service aliases? AutowireTest could be extended to check for this.
But if we do want to move more towards private-by-default then I think this is a good step.