Problem/Motivation

Symfony's dependency injection container should allow you to shorthand aliases:

services:
  service1: '@service2'

This functionality is broken due to the rewrites in Drupal\Core\Component\DependencyInjection\YamlFileLoader::parseDefinitions() that add a 'provider' tag to a service definition.

Error: Cannot use string offset as an array in Drupal\Core\DependencyInjection\YamlFileLoader->parseDefinitions() (line 123 of core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php).

Proposed resolution

Verify that the service definition is an array definition, and not a shorthand alias, before attempting to add the 'provider' tag.

Remaining tasks

Patch attached to this issue.

User interface changes

N/A

API changes

N/A, however you are now able to use shorthand aliases in your container YAML's.

Data model changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

GroovyCarrot created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, dependency-injection-file-loader.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

Testbot failure, resetting status due to https://www.drupal.org/node/2828045

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We should certainly add some test coverage, otherwise we might break things again.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Sweetchuck’s picture

Status: Needs work » Needs review
Issue tags: +Drupalaton 2017
FileSize
1.97 KB
dawehner’s picture

Nice bug report, things are tricky!

+++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
@@ -120,7 +120,10 @@ private function parseDefinitions($content, $file)
-            $service['tags'][] = ['name' => '_provider', 'provider' => $provider];
+            if (is_array($service)) {
+                $service['tags'][] = ['name' => '_provider', 'provider' => $provider];
+            }

Shouldn't we still add the provider, even if it is this kind of alias?

Sweetchuck’s picture

It is depend on what is the purpose of the "provider" key.
Do you want tack that who provides the alias or who provides the service definition?

The problem is that the alias definition which refers to another service is a simple key-value pair where the value is a string. So you can't attach additional information, such as the "tags".

I don't how a service definition parsed and processed and when will be an alias resolved to the referred service. So I can't help more.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mxr576’s picture

It is depend on what is the purpose of the "provider" key.
Do you want tack that who provides the alias or who provides the service definition?

bump :)

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

raman.b’s picture

Version: 8.9.x-dev » 9.2.x-dev
FileSize
2.46 KB
3.15 KB

Re-roll for 9.2.x

mxr576’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

The patch looks good to me, rtbc.

  • catch committed e770d3e on 9.2.x
    Issue #2828099 by raman.b, GroovyCarrot, Sweetchuck, dawehner, mxr576:...

  • catch committed 6ff63e2 on 9.1.x
    Issue #2828099 by raman.b, GroovyCarrot, Sweetchuck, dawehner, mxr576:...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

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