PHP code example of contao-graveyard / stylepicker

1. Go to this page and download the library: Download contao-graveyard/stylepicker 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/ */

    

contao-graveyard / stylepicker example snippets


/*
 * HOOK to get table,PID(s),section and condition
 * in-parameter: str $table, int $id
 * out-parameter as array or FALSE if the callback does not match:
 * 		array($tbl,$pids,$sec,$cond)
 * 		str $tbl: table name, mostly the same as from the in-parameter
 * 		array $layout: ID of Pagelayout
 * 		str $sec: a section (column) identifier
 * 		str $cond: some addition condition
 */
if (isset($GLOBALS['TL_HOOKS']['stylepicker4ward_getFilter']) && is_array($GLOBALS['TL_HOOKS']['stylepicker4ward_getFilter'])) {
    foreach ($GLOBALS['TL_HOOKS']['stylepicker4ward_getFilter'] as $callback) {
        System::importStatic($callback[0]);
        $result = $this->{$callback[0]}->{$callback[1]}($table, $id);
        if (is_array($result)) {
            [$table, $layout, $section, $condition] = $result;
            break;
        }
    }
}



namespace App\EventListener

use ContaoGraveyard\StylePickerBundle\Event\GetStylePickerFilterEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
class StylePickerEventListener
{
    public function __invoke(GetStylePickerFilterEvent $event): void
    {
        if ($event->getTable() !== 'my_table') {
            return;
        }

        $event->setLayout(213);
        $event->setCondition('foobar');
        $event->setSection('your_section');
    }
}



namespace App\EventListener

use ContaoGraveyard\StylePickerBundle\Event\GetStylePickerFilterEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

class MyMultiListener
{
    #[AsEventListener]
    public function onGetStylePickerFilterEvent(GetStylePickerFilterEvent $event): void
    {
        // ...
    }
}