Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make conditional_logic actions and conditions configurable #342

Open
notsure opened this issue Jul 20, 2022 · 0 comments
Open

Make conditional_logic actions and conditions configurable #342

notsure opened this issue Jul 20, 2022 · 0 comments

Comments

@notsure
Copy link

notsure commented Jul 20, 2022

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,
        ];
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants