Commit 432d2bec authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Issue #3312422 by e0ipso: Delegate component negotiation to a new service

parent 9b843b43
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ function cl_components_manager(): ComponentPluginManager {
function cl_components_library_info_build() {
  // Iterate over all the components to get the CSS and JS files.
  $plugin_manager = cl_components_manager();
  $components = $plugin_manager->getAllComponentsWithoutDupes();
  $components = $plugin_manager->getAllComponents();
  $libraries = array_reduce(
    $components,
    static function (array $libraries, Component $component) use ($plugin_manager) {
@@ -43,7 +43,9 @@ function cl_components_library_info_build() {
      catch (InvalidComponentHookException $e) {
        // The component does not support this hook. It is fine, do nothing.
      }
      return array_merge($libraries, [$component->getId() => $library]);
      $library_name = $component->getLibraryName();
      [, $library_id] = explode('/', $library_name);
      return array_merge($libraries, [$library_id => $library]);
    },
    []
  );
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@ services:
    tags:
      - { name: twig.loader, priority: 5 }

  Drupal\cl_components\ComponentNegotiator:
    arguments:
      - '@theme.manager'
      - '@extension.list.module'

  Drupal\cl_components\Twig\TwigExtension:
    arguments:
      - '@plugin.manager.cl_component'
@@ -29,3 +34,4 @@ services:
      - '@cache.component_registry'
      - '@config.factory'
      - '@theme.manager'
      - '@Drupal\cl_components\ComponentNegotiator'
+0 −53
Original line number Diff line number Diff line
{
  "$schema": "https://git.drupalcode.org/project/cl_components/-/raw/1.x/src/metadata.schema.json",
  "machineName": "my-banner",
  "name": "Banner",
  "componentType": "organism",
  "description": "Banner with title and a CTA link",
  "variants": [
    "tall"
  ],
  "schemas": {
    "props": {
      "type": "object",
      "properties": {
        "heading": {
          "title": "Heading",
          "description": "The title for the banner text.",
          "examples": [
            "Join us at The Conference"
          ],
          "type": "string"
        },
        "ctaText": {
          "title": "CTA Text",
          "type": "string",
          "examples": [
            "Click me!"
          ]
        },
        "ctaHref": {
          "title": "CTA Href",
          "type": "string",
          "examples": [
            "https://www.example.org"
          ]
        },
        "ctaTarget": {
          "title": "CTA Target",
          "type": "string",
          "enum": [
            "",
            "_blank"
          ]
        },
        "image": {
          "title": "Media Image",
          "description": "Background image for the banner.",
          "type": "string"
        }
      }
    }
  },
  "status": "READY"
}
+38 −0
Original line number Diff line number Diff line
$schema: https://git.drupalcode.org/project/cl_components/-/raw/1.x/src/metadata.schema.json
machineName: my-banner
name: Banner
componentType: organism
description: Banner with title and a CTA link
variants:
  - tall
schemas:
  props:
    type: object
    properties:
      heading:
        title: Heading
        description: The title for the banner text.
        examples:
          - Join us at The Conference
        type: string
      ctaText:
        title: CTA Text
        type: string
        examples:
          - Click me!
      ctaHref:
        title: CTA Href
        type: string
        examples:
          - 'https://www.example.org'
      ctaTarget:
        title: CTA Target
        type: string
        enum:
          - ''
          - _blank
      image:
        title: Media Image
        description: Background image for the banner.
        type: string
status: READY
+1 −1
Original line number Diff line number Diff line
@@ -16,6 +16,6 @@ function cl_component_my_banner_form_alter($form, FormStateInterface $form_state
    '' => \t('- No target -'),
    '_blank' => \t('Blank'),
  ];
  // @todo: Use the media browser to select an image for the component.
  // @todo Use the media browser to select an image for the component.
  return $form;
}
Loading