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

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review

MR reuses the visibility of the aliased service, unsure if this is the correct approach but seems to work.

> \Drupal::service('Drupal\Core\Form\FormCacheInterface');

   Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException  You have requested a non-existent service "Drupal\Core\Form\FormCacheInterface".

> unserialize(Drupal::service("kernel")->getCachedContainerDefinition()['services']['form_builder']);
= [
    "class" => "Drupal\Core\Form\FormBuilder",
    "arguments" => {#7337
      +"type": "collection",
      +"value": [
        {#7341
          +"type": "service",
          +"id": "form_validator",
          +"invalidBehavior": 1,
        },
        {#7339
          +"type": "service",
          +"id": "form_submitter",
          +"invalidBehavior": 1,
        },
        {#7338
          +"type": "private_service",
          +"id": "private__G8Uu4hTcUgjMeXKACab9jV6Lz0_L84M9F590Ayb57E0",
          +"value": [
            "class" => "Drupal\Core\Form\FormCache",
            "public" => false,
            "arguments" => {#7336
...
longwave’s picture

Status: Needs review » Needs work

Some test failures to sort out.

longwave’s picture

Status: Needs work » Needs review

Fixed 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.

longwave’s picture

Alternatively 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.