Loading README.md +6 −4 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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 Loading docs/writing-components.md +27 −36 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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 Loading @@ -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. Loading src/Plugin/Discovery/DirectoryWithMetadataDiscovery.php +2 −2 Original line number Diff line number Diff line Loading @@ -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); } Loading src/Twig/TwigExtension.php +3 −2 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading
README.md +6 −4 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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 Loading
docs/writing-components.md +27 −36 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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 Loading @@ -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. Loading
src/Plugin/Discovery/DirectoryWithMetadataDiscovery.php +2 −2 Original line number Diff line number Diff line Loading @@ -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); } Loading
src/Twig/TwigExtension.php +3 −2 Original line number Diff line number Diff line Loading @@ -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); } Loading