Problem/Motivation
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
Proposed resolution
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.
Remaining tasks
User interface changes
API changes
Data model changes