Skip to content

Make conditional_logic actions and conditions configurable #342

Open
@notsure

Description

@notsure
Q A
Bug report? no
Feature request? yes

Description:

It would be nice to enable or actually disable certain options for the conditional_logic actions and conditions, because sometimes users do not need all the possibilities and in case the front end is customised it is also possible that not all options are supported.

Feature Wish:

Create a new available property in your config.yml file called: enabled for each action and condition. And remove all enabled=false items in the function generateConditionalLogicStore within the ExtJsFormBuilder class.

This way a user of the bundle could easily add it within the custom config file:

Example 1: set enabled flag in config

form_builder:
    conditional_logic:
        action:
            switchOutputWorkflow:
                enabled: false
        condition:
            outputWorkflow:
                enabled: false

Example 2: each item could also be nullable

form_builder:
    conditional_logic:
        action:
            switchOutputWorkflow: ~
        condition:
            outputWorkflow: ~

Quickfix / Workaround:

If you need this feature now, you could overwrite the service to do so. In our config file for the formbuilder we have added:

form_builder.yml

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    FormBuilderBundle\Builder\ExtJsFormBuilder:
        class: App\FormBuilder\Builder\ExtJsFormBuilder

We created a new file to overwrite the ExtJsFormBuilder.php

<?php

namespace App\FormBuilder\Builder;

use FormBuilderBundle\Model\FormDefinitionInterface;

/**
 * This overwrite was needed to reduce the amount of allowed actions and conditions.
 */
class ExtJsFormBuilder extends \FormBuilderBundle\Builder\ExtJsFormBuilder
{
    const ALLOWED_ACTIONS = [
        'toggleElement'
    ];
    const ALLOWED_CONDITIONS = [
        'elementValue'
    ];

    public function generateExtJsForm(FormDefinitionInterface $formDefinition): array
    {
        $data = parent::generateExtJsForm($formDefinition);
        $data['conditional_logic_store'] = $this->generateConditionalLogicStore();

        return $data;
    }

    private function generateConditionalLogicStore(): array
    {
        $actions = [];
        foreach ($this->conditionalLogicRegistry->getAllConfiguration('action') as $actionName => $action) {
            if (!in_array($actionName, self::ALLOWED_ACTIONS)) {
                continue;
            }

            $actions[] = $this->getConditionalLogicItem($actionName, $action['name'], $action['icon']);
        }

        $conditions = [];
        foreach ($this->conditionalLogicRegistry->getAllConfiguration('condition') as $conditionName => $condition) {
            if (!in_array($conditionName, self::ALLOWED_CONDITIONS)) {
                continue;
            }

            $conditions[] = $this->getConditionalLogicItem($conditionName, $condition['name'], $condition['icon']);
        }

        return [
            'actions' => $actions,
            'conditions' => $conditions,
        ];
    }

    private function getConditionalLogicItem(string $identifier, string $name, string $icon): array
    {
        return [
            'identifier' => $identifier,
            'name' => $name,
            'icon' => $icon,
        ];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions