PHP code example of heimrichhannot / contao-tinymce-bundle

1. Go to this page and download the library: Download heimrichhannot/contao-tinymce-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-tinymce-bundle example snippets


class CustomDataContainer 
{
    private RequestStack $requestStack;
    private ScopeMatcher $scopeMatcher;

    public function onLoadCallback(DataContainer $dc = null): void
    {
        if ($this->requestStack->getCurrentRequest() && $this->scopeMatcher->isFrontendRequest($this->requestStack->getCurrentRequest())) {
            $GLOBALS['TL_DCA']['tl_custom']['fields']['text']['eval']['rte'] = 'tinyMCE';
        }
    }
}

use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use HeimrichHannot\TinyMceBundle\Manager\TinyMceManager;
use Symfony\Component\HttpFoundation\RequestStack;

class CustomDataContainer 
{
    private RequestStack $requestStack;
    private ScopeMatcher $scopeMatcher;
    private TinyMceManager $tinyMceManager;

    /**
     * @Callback(table="tl_jobmarket_job", target="config.onload")
     */
    public function onLoadCallback(DataContainer $dc = null): void
    {
        if ($this->requestStack->getCurrentRequest() && $this->scopeMatcher->isFrontendRequest($this->requestStack->getCurrentRequest())) {
            $GLOBALS['TL_DCA']['tl_custom']['fields']['text']['eval']['rte'] = 'tinyMCE';
            $GLOBALS['TL_DCA']['tl_custom']['fields']['text']['eval']['tinyMceOptions'] = [
                'menubar' => 'edit format',
                'toolbar' => 'link unlink | bold italic | bullist numlist | undo redo | code',
                'plugins' => ['paste', 'link', 'lists'],
                'paste_as_text' => true
            ];
            
            $GLOBALS['TL_DCA']['tl_custom']['fields']['littleText']['eval']['rte'] = 'tinyMCE';
            $GLOBALS['TL_DCA']['tl_custom']['fields']['littleText']['eval']['tinyMceOptions'] = $this->tinyMceManager->->getOptionPreset('limited');
        }
    }
}

$GLOBALS['TL_DCA']['tl_custom']['fields']['text']['eval']['tinyMceOptions'] = ['maxChars' => 200];

use HeimrichHannot\TinyMceBundle\Event\AddOptionPresetEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class TinyMceSubscriber implements EventSubscriberInterface
{
    public function onAddOptionPresetEvent(AddOptionPresetEvent $event): void
    {
        $event->addPreset('custom', [
            'menubar' => false,
            'toolbar' => 'undo redo | bold | bullist numlist indent outdent | link unlink',
            'plugins' => ['link', 'lists'],
            'statusbar' => false,
        ]);
    }

    public static function getSubscribedEvents()
    {
        return [
            AddOptionPresetEvent::NAME => 'onAddOptionPresetEvent',
        ];
    }
}