khusseini/PimcoreRadBrickBundle

[Datasource]: Areabrick data condition

Closed this issue · 0 comments

Problem:
Some datasources should only be called if the correct input is available. This is specifically the case if arguments depend on values of other editables in the areabrick. Currently the service call needs to take this into consideration whereas this check can be transfered to the configuration of an areabrick.

Solution:

Add a new confiuration option for datasources under areabricks and only execute those if the condition returns true.

pseudo_services.yml

services:
    pimcore.tags_service:
    public: true
    class: Pimcore\Model\Element\Tag
    app.products:
        alias: '@AppBundle\Services\Products'
        public: true
pimcore_rad_brick:
  datasources:
    products_for_tags:
      service_id: app.products
      method: findProductsByTags
      args:
      - tags
    tags_for_element:
      service_id: pimcore.tags_service
      method: getTagsForElement
      args:
      - type
      - element_id
  areabricks: 
    product_list:
      label: Product List
      use_edit: true
      datasources:
        tags:
          id: tags_for_element
          conditions:
          - "try(view['use_document_tags'].isChecked() ?: view['select_category'].getElement())"
          args:
            type: "try(view['use_document_tags'].isChecked() ? 'document' : 'object', 'object')"
            element_id: "try(
              view['use_document_tags'].getIsChecked() ? request.attributes.get('document').getId(),
              try(view['select_category'].getElement().getId())
            )"
      editables:
        use_document_tags:
          type: checkbox
        select_category:
          type: relation
          options:
            types: ['object']
            subtypes:
              object: ['object']
            classes: ["CoreShopCategory"]