Problem/Motivation

Symfony services can have arrays as arguments. They can converted to \Symfony\Component\DependencyInjection\Argument\IteratorArgument by the ContainerBuilder. They are not supported by \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::dumpValue().

Proposed resolution

Convert \Symfony\Component\DependencyInjection\Argument\IteratorArgument to an array so we can dump it.

Remaining tasks

User interface changes

None

API changes

No change.

Data model changes

None

Issue fork drupal-2961380

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

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new1.09 KB
alexpott’s picture

Issue tags: -Needs tests
StatusFileSize
new1.47 KB
new2.58 KB

Had to move the fix.

The last submitted patch, 3: 2961380-3.test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 3: 2961380-3.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new910 bytes
new3.47 KB
borisson_’s picture

I only found one nit to pick on this.

+++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
@@ -336,6 +337,13 @@ public function getDefinitionsDataProvider() {
+          'arguments' => [new IteratorArgument([new Reference('bar')])],
+          'arguments_count' => 1,
+          'arguments_expected' => $this->getCollection([$this->getCollection([$this->getServiceCall('bar')])]),
+        ] + $base_service_definition;

The indentation here looks off.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

joachim’s picture

Do you mean the + being on the same line as the closing array bracket?

+        ] + $base_service_definition;

I'm sure I've seen that before in core for that pattern of adding defaults to an array.

borisson_’s picture

No, I mean that the items in the array are intented +4 spaces instead of +2.

joachim’s picture

Status: Needs review » Needs work

Oh that’s definitely wrong.

Sorry, was doing patch reviews while the baby was keeping me up at night!

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bonrita’s picture

StatusFileSize
new5.1 KB

Adding support for ServiceClosureArgument too.

ravi.shankar’s picture

Status: Needs work » Needs review
alexpott’s picture

StatusFileSize
new1.11 KB
new3.46 KB

@bonrita a better way forward here is to review this issue and create a separate issue for ServiceClosureArgument as you've added on something new without updating the issue title or summary. I would have fixed the issue summary and title and left your changes in but commenting out your changes to OptimizedPhpArrayDumper and running OptimizedPhpArrayDumperTest show that the test coverage you've added is not sufficient as the test you've added does not fail.

Anyway, here is a patch the fixes the coding standard errors noted in #7. Perhaps @bonrita can review this issue and open a new issue with a failing test that shows that ServiceClosureArgument is not supported.

bonrita’s picture

Hi @alexpott thanks for the advice. l have created a new issue concerning ServiceClosureArgument.
l will also add a failing test in the patch that goes with that issue.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new146 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

borisson_’s picture

Issue tags: +Needs reroll

patch in #16 needs a reroll.

manishsaharan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.2 KB

Rerolled #16 for 10.1.x

borisson_’s picture

Looks solid, we have test coverage, so now need a change record.

smustgrave’s picture

Status: Needs review » Needs work
manishsaharan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.55 KB
new3.55 KB

Tried to fix #26.

Status: Needs review » Needs work

The last submitted patch, 29: SupportIteratorArgument-2961380-29.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

finne’s picture

I did a reroll of the patch for 11.x. It should be in the merge request.

finne’s picture

hide patch files, using merge request

finne’s picture

finne’s picture

Status: Needs work » Needs review
znerol’s picture

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

Added a change record. Reroll looks good. Same restrictions apply as in #3108020: Support ServiceClosureArgument in \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::dumpValue:

This feature is not supported in the custom YamlFileLoader Drupal is currently using. But for service definitions built programmatically, this patch still brings some benefits.

znerol’s picture

(also added a change record)

quietone’s picture

Status: Reviewed & tested by the community » Needs work

The diff no longer applies. Can someone update the MR?

I read the issue summary and comments. All questions have been answered. The only thing I don't see is a failing test.

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

elber’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ran the tests without the fix and got

Symfony\Component\DependencyInjection\Exception\RuntimeException : Unable to dump a service container if a parameter is an object without _serviceId.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Checking back in. I read the IS and the comments since my last comment. I didn't find any unanswered questions.

This time I read the change record. The CR title should be a clue to the reader of what the change is. This title should be more specific, perhaps state what now supports and IteratorArgument. The body itself should, ideally, begin with the benefit of this change and when the benefits will be seen. Because of this I am tagging for CR updates and setting back to needs work. Fortunately, that shouldn't take much time for anyone familiar with this change.

Leaving at RTBC.

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Updated the CR title and description to make it clearer what the benefits of this change are.

kim.pepper’s picture

Might need reviews of that CR especially whether it allows the !tagged_iterator argument type now 🤔

kim.pepper’s picture

longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed 8b6814e and pushed to 11.x. Thanks!

Updated the change record to reference 10.3.0 and published it.

  • longwave committed 8b6814e4 on 11.x
    Issue #2961380 by alexpott, manishsaharan, borisson_, kim.pepper, znerol...
znerol’s picture

I removed the services.yml example from the CR. The !tagged_iterator notation still doesn't work. This issue here only changed the container array dumper/loader and not the yaml part (see also #38).

Attempting to use the !tagged_iterator notation results in the following exception:

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The file "core/modules/mailer/mailer.services.yml" does not contain valid YAML: Tags support is not enabled. Enable the "Yaml::PARSE_CUSTOM_TAGS" flag to use "!tagged_iterator" at line 42 (near "arguments: [!tagged_iterator mailer.transport_factory]"). in Drupal\Core\DependencyInjection\YamlFileLoader->loadFile() (line 426 of /home/lo/src/drupal/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php).

Drupal\Core\DependencyInjection\YamlFileLoader->loadFile('core/modules/mailer/mailer.services.yml') (Line: 71)
Drupal\Core\DependencyInjection\YamlFileLoader->load('core/modules/mailer/mailer.services.yml') (Line: 1303)
Drupal\Core\DrupalKernel->compileContainer() (Line: 941)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 496)
Drupal\Core\DrupalKernel->boot() (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
require('/home/lo/src/drupal/index.php') (Line: 48)
kim.pepper’s picture

#50 I believe we need #3108309: Support Yaml::PARSE_CUSTOM_TAGS in \Drupal\Component\Serialization\YamlSymfony::decode for the Yaml loader to support it.

We need to update our own YamlParser to support it.

kim.pepper’s picture

Status: Fixed » Closed (fixed)

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

mrconnerton’s picture

StatusFileSize
new3.56 KB

Reroll for 10.5.x for those interested. I'm sorry I uploaded the wrong patch.

mrconnerton’s picture

mrconnerton’s picture

StatusFileSize
new2.81 KB

Here is reroll for 10.5.x