YAML has taken the place of all other data representation or serialization formats in Drupal 8. All configuration outputs and all module or service definitions are in YAML; basically, if it isn't PHP, JavaScript or CSS, it's YAML. YAML was chosen because it's human-readable and the syntax maps well to normal data types, like lists, associative arrays, and a variety of scalar values. YAML uses white space to define the hierarchy of information instead of enclosures, such as brackets, braces, semi-colons, and so on. Looking at an example, using an .info.yml file for a theme, you'll see a lot of similarities to what you would have had in an .info file in Drupal 7.
name: Test
type: theme
description: A test theme.
core: 8.x
libraries:
- test/global
regions:
header: Header
content: Content # the content region is required
sidebar_first: 'Sidebar first'
footer: Footer
If you were to imagine this as a PHP associative array, it would look like:
[
'name' => 'Test',
'type' => 'theme',
'description' => 'A test theme.',
'core' = '8.x',
'libraries' => [ 'test/global' ],
'regions' => [
'header' => 'Header',
'content' => 'Content',
'sidebar_first' => 'Sidebar first',
'footer' => 'footer'
]
]
There are some specific rules as to how the values are defined in a YAML file:
- Strings can be surrounded by single or double quotations, but they can also be left unquoted--but unquoted strings are trimmed
- Double quoted strings allow you to embed escape characters such as \n or \t or any Unicode characters
- The values true or false are treated as Boolean values; if you need them as string values, they need to be quoted
- Null values can be entered as either null or ~
- Unquoted values that look like integers, floats, or are in exponential notation (for example, 5e7) will be cast to the appropriate number
- Values that look like ISO-8601 dates and times (for example, 2017-04-23 or 2017-04-23T13:44:19Z) will be converted to Unix timestamps