- Issue created by @Murz
- π¦π²Armenia Murz Yerevan, Armenia
And one more inconsistency - https://git.drupalcode.org/project/drupal/-/blob/10.0.0/core/modules/res...
arguments: [rest] ... arguments: ['rest']
We already have a coding standard for YAML files here https://www.drupal.org/docs/develop/coding-standards/configuration-file-... β
But it describes too few rules.
I see that even in Drupal Core we have a mix of YAML and inline JSON constructions like this: https://git.drupalcode.org/project/drupal/-/blob/10.0.0/core/modules/com...
services:
comment.breadcrumb:
class: Drupal\comment\CommentBreadcrumbBuilder
arguments: ['@entity_type.manager']
tags:
- { name: breadcrumb_builder, priority: 100 }
comment.manager:
class: Drupal\comment\CommentManager
arguments: ['@entity_type.manager', '@config.factory', '@string_translation', '@module_handler', '@current_user', '@entity_field.manager', '@entity_display.repository']
comment.statistics:
class: Drupal\comment\CommentStatistics
arguments: ['@database', '@current_user', '@entity_type.manager', '@state', '@database.replica']
tags:
- { name: backend_overridable }
So, using brackets instead of plaintext in { name: backend_overridable }
looks not good, and lines with a list of arguments longer than 120 characters (we have 173 in the example) - too.
So we can use just the YAML language without JSON injections, and with it, the file will even look much clear! Here is a cleaned up example:
services:
comment.breadcrumb:
class: Drupal\comment\CommentBreadcrumbBuilder
arguments:
- '@entity_type.manager'
tags:
- name: breadcrumb_builder
priority: 100
comment.manager:
class: Drupal\comment\CommentManager
arguments:
- '@entity_type.manager'
- '@config.factory'
- '@string_translation'
- '@module_handler'
- '@current_user'
- '@entity_field.manager'
- '@entity_display.repository'
comment.statistics:
class: Drupal\comment\CommentStatistics
arguments:
- '@database'
- '@current_user'
- '@entity_type.manager'
- '@state'
- '@database.replica'
tags:
- name: backend_overridable
Also, we have a mix of class FQCN formats with a leading backslash and without it, even within a single file, eg this https://git.drupalcode.org/project/drupal/-/blob/10.0.0/core/core.servic...
router:
class: Drupal\Core\Routing\AccessAwareRouter
arguments: ['@router.no_access_checks', '@access_manager', '@current_user']
router.no_access_checks:
class: \Drupal\Core\Routing\Router
arguments: ['@router.route_provider', '@path.current', '@url_generator']
Describe recommendations to avoid the usage of JSON constructions in the YAML files and prefer a YAML formatted lists instead.
Also, describe other recommendations like putting an empty line between each service, missing backslash in class' FQCN, etc.
And one more inconsistency - https://git.drupalcode.org/project/drupal/-/blob/10.0.0/core/modules/res...
arguments: [rest]
...
arguments: ['rest']