May 17, 2014

The module .info file

Here is the original D7 file.
name = Optimizely
description = Manages loading Optimizely generated

    project javascript file(s) to enable A/B testing.
core = 7.x
php = 5.2
project = "optimizely"
configure = admin/config/system/optimizely/settings
files[] = optimizely.test
In Drupal 8 the required .info file for a module has been replaced with a  .info.yml  file, which serves the same purpose. The new syntax is YAML, which is more generally known and accepted.

Here is the very first cut for such a file. These three keys seem to be the minimum required for D8 to recognize the presence of a module.
name: Optimizely
type: module
core: 8.x
Contrib and custom modules may now be placed in the top-level  modules  directory (whereas core modules are placed in  core/modules ). Subdirectories may be used. So I created this new file in the path


Here's a fleshed out version which is equivalent to the original (as far as I know at this point).
# These first three properties are required.
name: Optimizely
type: module
core: 8.x

# This value for the description key is broken across
# multiple lines to demonstrate how it's done and for
# better formatting in this blog.
description: >
  Manages loading Optimizely generated project
  javascript file(s) to enable A/B testing.

php: 5.2
project: optimizely

# The configure property specifies a "route name",
# which I will define later.

configure: optimizely.settings

# files[] are no longer needed because of autoloading
The path to the configuration menu is replaced by use of the new routing system, which I will be learning and getting into later.

From "Remove any files[] entries. Classes are now autoloaded using a separate mechanism".

Syntax Notes: 
  • You must put one or more spaces or tabs after each colon.
  • Quote marks are optional around string values.
  • Comments start with a pound sign #
  • Indentation is syntactically significant and indicates elements at the same level.
  • I broke up the value for the description property into two lines by (1) using a > character which means the newlines are to be folded and (2) indenting the lines of the string value.

.info files are now .info.yml files
Includes a couple of examples on the new .info.yml files.

Description and tutorial for YAML syntax, data types, et al. Has technical details if you want to delve into them but the first part of the article is a good intro.

No comments:

Post a Comment