Skip to content

CollectionSelector

CollectionSelector element is a select list with collections.

collection-selector

Build-in Validators

Element validate if chosen collection exists.

Available Validators

Element has available validators:

Relations Support

Element does not support relations between elements.

Configuration output schema

schema
{
  "<element_type>" : "collectionSelector",
  "<element_name>" : string,
  "<element_label>" : string,
  "<element_labelDescription>" : string,
  "<element_isRequired>" : bool,
  "<element_isHidden>" : bool,
  "<element_defaultValue>" : int,
  "<element_validators>" : []
}
example
{
  "type" : "collectionSelector",
  "name" : "collection",
  "label" : "Displayed collection",
  "isRequired" : false,
  "isHidden" : false,
  "defaultValue" : 12,
  "validators": [
    { "type" : "positiveNumber" },
    { "type" : "int" },
    { "type" : "lessEqThan", "options" : { "max" : 25 } }
  ]
}

Element value

If value is filled: int.

usage in module TWIG
{% if moduleConfig.collection %}
    Displayed collection ID: {{ moduleConfig.collection }}
{% endif %}

Example of module

Twig

Twig
{% set collectionId = moduleConfig.selectedCollectionId %}
{% if collectionId %}
    {% set collection = ObjectApi.getCollection(collectionId) %}
    {% if collection %}
        <section>
            <div>
                <h2 class="h2">{{ collection.name }}</h2>

                {% if moduleConfig.showDescription and collection.description %}
                    <p>
                        {{ collection.description|raw }}
                    </p>
                {% endif %}

                <div>
                    <a href="{{ collection.url }}" class="btn btn_primary">
                        {{ translate("See collection") }}
                    </a>
                </div>
            </div>
        </section>
    {% endif %}
{% endif %}

JSON configuration

JSON configuration
[
  {
    "label": "Collection",
    "state": "unfolded",
    "elements": [
      {
        "name": "selectedCollectionId",
        "type": "collectionSelector",
        "label": "Select Collection"
      },
      {
        "name": "showDescription",
        "type": "checkbox",
        "label": "Show collection description"
      }
    ]
  }
]

JSON translations

JSON translations
{
  "module": {
    "pl_PL": {
      "See collection": "Zobacz kolekcję"
    },
    "en_US": {
      "See collection": "See collection"
    }
  },
  "schema": {
    "pl_PL": {
      "Collection" : "Kolekcja",
      "Select Collection" : "Wybierz kolekcję",
      "Show collection description" : "Pokaż opis kolekcji"
    },
    "en_US": {
      "Collection" : "Collection",
      "Select Collection" : "Select Collection",
      "Show collection description" : "Show collection description"
    }
  }
}