Skip to content

Error on generate:event:subscriber command #2406

@nmeegama

Description

@nmeegama

I believe this happens when there is already a service defined. The new service/event definition does not start in a new line. But everything else is fine. Also the error could be fixed by formatting the YML file manually but the generation still has this fault. I will add the commands

dc generate:event:subscriber
Enter the module name [hello_world]:

Enter the service name [hello_world.default]:

hello_wprld.hello_listner

Class name [DefaultSubscriber]:

HelloListner

Type the event name or use keyup or keydown.
This is optional, press enter to continue

Enter event name [ ]:

kernel.request

Callback function name to handle event [kernel_request]:

onHelloRequest

Enter event name [ ]:

Do you want to load services from the container (yes/no) [no]:

Do you confirm generation? (yes/no) [yes]:

Generated or updated files
Site path: /Users/nmeegama/work_repo/d8
1 - modules/custom/hello_world/src/EventSubscriber/HelloListner.php
2 - modules/custom/hello_world/hello_world.services.yml
// cache:rebuild

Rebuilding cache(s), wait a moment please.
PHP Warning: Illegal string offset 'tags' in /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php on line 125

Warning: Illegal string offset 'tags' in /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php on line 125
PHP Fatal error: Uncaught Error: Cannot use string offset as an array in /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php:125
Stack trace:
#0 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php(97): Drupal\Core\DependencyInjection\YamlFileLoader->parseDefinitions(Array, 'modules/custom/...')
#1 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(1207): Drupal\Core\DependencyInjection\YamlFileLoader->load('modules/custom/...')
#2 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(850): Drupal\Core\DrupalKernel->compileContainer()
#3 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(463): Drupal\Core\DrupalKernel->initializeContainer()
#4 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(703): Drupal\Core\DrupalKernel->boot()
#5 /Users/nmeegama/work_repo/d8/core/includes/utility.inc(42): Drupal\Core\DrupalKernel->prepareLegacyRequest(Object(Symfony\Component\HttpFoundation\Request))
#6 ph in /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php on line 125

Fatal error: Uncaught Error: Cannot use string offset as an array in /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php:125
Stack trace:
#0 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php(97): Drupal\Core\DependencyInjection\YamlFileLoader->parseDefinitions(Array, 'modules/custom/...')
#1 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(1207): Drupal\Core\DependencyInjection\YamlFileLoader->load('modules/custom/...')
#2 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(850): Drupal\Core\DrupalKernel->compileContainer()
#3 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(463): Drupal\Core\DrupalKernel->initializeContainer()
#4 /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DrupalKernel.php(703): Drupal\Core\DrupalKernel->boot()
#5 /Users/nmeegama/work_repo/d8/core/includes/utility.inc(42): Drupal\Core\DrupalKernel->prepareLegacyRequest(Object(Symfony\Component\HttpFoundation\Request))
#6 ph in /Users/nmeegama/work_repo/d8/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php on line 125


The error is in the *.service.yml file which ends up as follows (the new event generated is in bold)
parameters:
hello_world.hello_cache: true
services:
hello_world.url_param_reader:
class: Drupal\hello_world\UtilityServices\URLParamReader
arguments:
- '@keyvalue'
- %hello_world.hello_cache% hello_wprld.hello_listner:
class: Drupal\hello_world\EventSubscriber\HelloListner
arguments: []
tags:
- { name: event_subscriber }

The error is gone once we correct the YML file manually

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions