Skip to content
Snippets Groups Projects
Verified Commit a64662a3 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3293926 by kingdutch, geekygnr, godotislate, m4olivei, longwave: Error...

Issue #3293926 by kingdutch, geekygnr, godotislate, m4olivei, longwave: Error decorating non-existent service when inner service's module not installed

(cherry picked from commit c0053e63)
parent 659b8eae
No related branches found
No related tags found
2 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!9944Issue #3483353: Consider making the createCopy config action optionally fail...
Pipeline #320227 passed with warnings
Pipeline: drupal

#320257

    Pipeline: drupal

    #320244

      Pipeline: drupal

      #320233

        +1
        ......@@ -390,10 +390,32 @@ private function parseDefinition(string $id, $service, string $file, array $defa
        $definition->addTag($name, $tag);
        }
        if (isset($service['decorates'])) {
        if (null !== $decorates = $service['decorates'] ?? null) {
        if ('' !== $decorates && '@' === $decorates[0]) {
        throw new InvalidArgumentException(\sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s").', $id, $service['decorates'], substr($decorates, 1)));
        }
        $decorationOnInvalid = \array_key_exists('decoration_on_invalid', $service) ? $service['decoration_on_invalid'] : 'exception';
        if ('exception' === $decorationOnInvalid) {
        $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
        }
        elseif ('ignore' === $decorationOnInvalid) {
        $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
        }
        elseif (null === $decorationOnInvalid) {
        $invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
        }
        elseif ('null' === $decorationOnInvalid) {
        throw new InvalidArgumentException(\sprintf('Invalid value "%s" for attribute "decoration_on_invalid" on service "%s". Did you mean null (without quotes) in "%s"?', $decorationOnInvalid, $id, $file));
        }
        else {
        throw new InvalidArgumentException(\sprintf('Invalid value "%s" for attribute "decoration_on_invalid" on service "%s". Did you mean "exception", "ignore" or null in "%s"?', $decorationOnInvalid, $id, $file));
        }
        $renameId = $service['decoration_inner_name'] ?? null;
        $priority = $service['decoration_priority'] ?? 0;
        $definition->setDecoratedService($service['decorates'], $renameId, $priority);
        $definition->setDecoratedService($decorates, $renameId, $priority, $invalidBehavior);
        }
        if (isset($service['autowire'])) {
        ......
        ......@@ -200,6 +200,38 @@ public static function providerTestExceptions() {
        YAML,
        'The service file "vfs://drupal/modules/example/example.yml" is not valid: it contains invalid root key(s) "do not". Services have to be added under "services" and Parameters under "parameters".',
        ],
        'decorates must be without @' => [<<<YAML
        services:
        example_service_1:
        class: \Drupal\Core\ExampleClass
        example_decoration:
        class: \Drupal\Core\ExampleClass
        decorates: "@example_service_1"
        YAML,
        'The value of the "decorates" option for the "example_decoration" service must be the id of the service without the "@" prefix (replace "@example_service_1" with "example_service_1").',
        ],
        'decorates_on_invalid may not be "null" with quotes' => [<<<YAML
        services:
        example_service_1:
        class: \Drupal\Core\ExampleClass
        example_decoration:
        class: \Drupal\Core\ExampleClass
        decorates: example_service_1
        decoration_on_invalid: "null"
        YAML,
        'Invalid value "null" for attribute "decoration_on_invalid" on service "example_decoration". Did you mean null (without quotes) in "vfs://drupal/modules/example/example.yml"?',
        ],
        'decoration_on_invalid must be valid' => [<<<YAML
        services:
        example_service_1:
        class: \Drupal\Core\ExampleClass
        example_decoration:
        class: \Drupal\Core\ExampleClass
        decorates: example_service_1
        decoration_on_invalid: foo
        YAML,
        'Invalid value "foo" for attribute "decoration_on_invalid" on service "example_decoration". Did you mean "exception", "ignore" or null in "vfs://drupal/modules/example/example.yml"?',
        ],
        ];
        }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment