PHP code example of heimrichhannot / contao-choices-bundle

1. Go to this page and download the library: Download heimrichhannot/contao-choices-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heimrichhannot / contao-choices-bundle example snippets


['field']['eval']['choicesOptions'] = [
    'enable' => true|false
];

public function onHuhChoicesCustomizeChoicesOptions(CustomizeChoicesOptionsEvent $event)
{
    $event->enableChoices();
    $event->disableChoices();
}

['field']['eval']['choicesOptions'] = [];

use HeimrichHannot\ChoicesBundle\Event\CustomizeChoicesOptionsEvent;

class CustomizeChoicesOptionsListener
{
    public function __invoke(CustomizeChoicesOptionsEvent $event)
    {
        if ($event->isFilterField()) {
            $this->addFilterChoicesOptions($event);
        } else {
            $this->addFieldChoicesOptions($event);
        }       
    }
}

use HeimrichHannot\ChoicesBundle\Asset\FrontendAsset;

class MyClass 
{
    private FrontendAsset $frontendAsset;

    public function action() {
        $this->frontendAsset->addFrontendAssets();
    }
}
javascript
/**
 * @param { CustomEvent } event
 */
function onHundhChoicesOptions(event) {
    let options = event.detail.options;
    // Customize options
}

/**
 * @param { CustomEvent } event
 */
function onHundhChoicesNewInstance(event) {
    let choicesInstance = event.detail.instance;
    // Work with the choices instance
}

document.addEventListener('hundhChoicesOptions', onHundhChoicesOptions);
document.addEventListener('hundhChoicesNewInstance', onHundhChoicesNewInstance);