# Schema for the configuration files of the CKEditor 5 module.

editor.settings.ckeditor5:
  type: mapping
  label: 'CKEditor 5 settings'
  mapping:
    toolbar:
      type: mapping
      label: 'Toolbar configuration'
      mapping:
        items:
          type: sequence
          orderby: ~
          label: 'Items'
          sequence:
            type: ckeditor5.toolbar_item
            label: 'Button'
            constraints:
              # Each active CKEditor 5 toolbar item whose plugin has conditions must have those conditions met.
              CKEditor5ToolbarItemConditionsMet: []
    plugins:
      type: sequence
      label: 'Plugins'
      orderby: key
      sequence:
        type: ckeditor5.plugin.[%key]
  constraints:
    # Each enabled CKEditor 5 plugin that implements \Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableInterface
    # must exist in here.
    CKEditor5EnabledConfigurablePlugins: []

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language
ckeditor5.plugin.ckeditor5_language:
  type: mapping
  label: 'Language'
  mapping:
    language_list:
      type: string
      label: 'Language list ID'
      constraints:
        # Configuring this does not make sense without the corresponding button.
        CKEditor5ToolbarItemDependencyConstraint:
          toolbarItem: textPartLanguage
        # Only the following values are accepted.
        Choice:
          # United Nations "official languages".
          - un
          # Drupal's predefined language list.
          - all
          # Languages configured at /admin/config/regional/language for the site.
          - site_configured

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading
ckeditor5.plugin.ckeditor5_heading:
  type: mapping
  label: Headings
  mapping:
    enabled_headings:
      type: sequence
      orderby: value
      label: 'Enabled Headings'
      constraints:
        NotBlank:
          message: "Enable at least one heading, otherwise disable the Heading plugin."
      sequence:
        type: string
        label: 'Heading type'
        constraints:
          Choice:
            callback: \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::validChoices

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ImageResize
ckeditor5.plugin.ckeditor5_imageResize:
  type: mapping
  label: Image Resize
  mapping:
    allow_resize:
      type: boolean
      label: 'Allow resize'
      constraints:
        NotNull: []

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing
ckeditor5.plugin.ckeditor5_sourceEditing:
  type: mapping
  label: Source Editing
  mapping:
    allowed_tags:
      type: sequence
      orderby: ~
      label: 'Allowed Tags'
      sequence:
        type: ckeditor5.element
        label: 'Allowed Tag'
        constraints:
          SourceEditingRedundantTags: []
          SourceEditingPreventSelfXssConstraint: []

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Alignment
ckeditor5.plugin.ckeditor5_alignment:
  type: mapping
  label: Alignments
  mapping:
    enabled_alignments:
      type: sequence
      orderby: value
      label: 'Enabled Alignments'
      constraints:
        NotBlank:
          message: "Enable at least one alignment, otherwise disable the Alignment button."
      sequence:
        type: string
        label: 'Alignment type'
        constraints:
          Choice:
            - left
            - center
            - right
            - justify

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin
ckeditor5.plugin.ckeditor5_list:
  type: mapping
  label: List
  mapping:
    properties:
      type: mapping
      label: 'Allowed list attributes'
      mapping:
        reversed:
          type: boolean
          label: 'Allow reverse list'
          constraints:
            NotNull: []
        startIndex:
          type: boolean
          label: 'Allow start index'
          constraints:
            NotNull: []
    multiBlock:
      type: boolean
      label: 'Allow blocks to be created in list items'
      constraints:
        NotNull: []

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Media
ckeditor5.plugin.media_media:
  type: mapping
  label: Media
  mapping:
    allow_view_mode_override:
      type: boolean
      label: 'Allow view mode override'
      constraints:
        NotNull: []

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock
ckeditor5.plugin.ckeditor5_codeBlock:
  type: mapping
  label: Code Block
  mapping:
    languages:
      type: sequence
      orderby: ~
      label: 'Languages'
      constraints:
        NotBlank:
          message: "Enable at least one language, otherwise disable the Code Block plugin."
        UniqueLabelInList:
          labelKey: label
      sequence:
        type: mapping
        label: 'Language'
        mapping:
          label:
            type: required_label
            label: 'Language label'
          language:
            type: string
            label: 'Language key'

# Plugin \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Style
ckeditor5.plugin.ckeditor5_style:
  type: mapping
  label: Style
  mapping:
    styles:
      type: sequence
      orderby: ~
      label: 'Styles'
      constraints:
        NotBlank:
          message: "Enable at least one style, otherwise disable the Style plugin."
        UniqueLabelInList:
          labelKey: label
      sequence:
        type: mapping
        label: 'Style'
        mapping:
          label:
            type: required_label
            label: 'Style label'
          element:
            type: ckeditor5.element
            constraints:
              # Validate that this contains exactly 1 attribute (class) and >=1 class attr value.
              CKEditor5Element:
                requiredAttributes:
                  -
                    attributeName: class
                    minAttributeValueCount: 1
              StyleSensibleElement: []
            label: 'Style tag + classes'
