Commit 84c29eda authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Issue #3313224: Drop support for metadata.json

parent 432d2bec
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@ What do you mean by "component"?
In this context, a component is the combination of:

* A regular Twig template.
* Metadata describing the input data the template accepts (the `metadata.json`
* Metadata describing the input data the template accepts (
  the `my-component.component.yml`
  file).
* Optional JavaScript.
* Optional Styles.
@@ -36,9 +37,10 @@ How to create a component
-------------------------

A component is any directory in your Drupal install that contains
a `metadata.json`. This folder must also contain at least a `my-component.twig`
template. It is advised to create a `css` and `js` directory for your
stylesheets and JS scripts. Learn more about creating a component in
a `my-component.component.yml`. This folder must also contain at least
a `my-component.twig` template. It is advised to create a `css` and `js`
directory for your stylesheets and JS scripts. Learn more about creating a
component in
the [documentation](https://git.drupalcode.org/project/cl_components/-/blob/1.x/docs/writing-components.md)
. You will need to let Drupal know where to start scanning for components (
including subdirectories). You can add as many locations as you need in the
+27 −36
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
            |- README.md (documentation for component)
            |- thumbnail.png (thumbnail for component selectors)
            |- my-component-machine-name.twig (required)
            |- metadata.json (required)
            |- my-component.component.yml (required)
            |- assets
                |- static
                    (assets that won't be processed and need to be copied to dist folder)
@@ -44,34 +44,26 @@ the color palette (like your navigation), but others do not support palettes
by [this schema](https://git.drupalcode.org/project/cl_components/-/raw/1.x/src/metadata.schema.json)
.

You could write a `metadata.json` like:

```json
{
  "$schema": "https://git.drupalcode.org/project/cl_components/-/raw/1.x/src/metadata.schema.json",
  "machineName": "my-image",
  "name": "Image",
  "status": "BETA",
  "componentType": "molecule",
  "schemas": {
    "props": {
      "type": "object",
      "required": [
        "caption"
      ],
      "properties": {
        "caption": {
          "type": "string",
          "title": "Caption",
          "description": "The caption for the image",
          "examples": [
            "A bird eating grass seeds."
          ]
        }
      }
    }
  }
}
You could write a `my-image.component.yml` like:

```yaml
$schema: https://git.drupalcode.org/project/cl_components/-/raw/1.x/src/metadata.schema.json
machineName: my-image
name: Image
status: BETA
componentType: molecule
schemas:
  props:
    type: object
    required:
      - caption
    properties:
      caption:
        type: string
        title: Caption
        description: The caption for the image
        examples:
          - A bird eating grass seeds.
```

See how this component is not to be used directly in Drupal, but in other
@@ -80,13 +72,12 @@ module can remove it from the available components in Drupal.

## Twig templates

The folder that contains the `metadata.json` is the _component folder_. For a
component to be valid there needs to be at least one `component-id.twig` file.
That is considered to be the main template for the component. Other templates
are allowed for component variants. They need to follow the naming convention
`component-id--variant-name.twig`.

Component templates have several variables available to them:
The folder that contains the `component-id.component.yml` is the _component
folder_. For a component to be valid there needs to be at least
one `component-id.twig` file. That is considered to be the main template for the
component. Other templates are allowed for component variants. They need to
follow the naming convention `component-id--variant-name.twig`. Component
templates have several variables available to them:

- `clAttributes`: an object with HTML attributes meant for the root of your
  component.
+2 −2
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@ class DirectoryWithMetadataDiscovery extends YamlDirectoryDiscovery {
      | \FilesystemIterator::CURRENT_AS_FILEINFO
      | \FilesystemIterator::SKIP_DOTS;
    $directory_iterator = new \RecursiveDirectoryIterator($directory, $flags);
    // Either detect "metadata.json" or "my_component.component.yml".
    $regex = '/^(metadata.json|([a-z0-9_-])+.component.yml)$/i';
    // Detect "my_component.component.yml".
    $regex = '/^([a-z0-9_-])+.component.yml$/i';
    $filter = new RegexRecursiveFilterIterator($directory_iterator, $regex);
    return new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::LEAVES_ONLY, $flags);
  }
+3 −2
Original line number Diff line number Diff line
@@ -50,8 +50,9 @@ class TwigExtension extends AbstractExtension {
    $component = $this->pluginManager->find($component_id);
    if (!empty($variant) && !in_array($variant, $component->getVariants(), TRUE)) {
      $message = sprintf(
        'Unable to render variant "%s". This variant is not declared in the metadata.json for this component.',
        $variant
        'Unable to render variant "%s". This variant is not declared in the %s.component.yml for this component.',
        $variant,
        $component_id
      );
      throw new TemplateNotFoundException($message);
    }