Skip to content

Instantly share code, notes, and snippets.

@cleggypdc
Created August 29, 2019 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleggypdc/e07c8314067e48238e191ecaf57ff9b5 to your computer and use it in GitHub Desktop.
Save cleggypdc/e07c8314067e48238e191ecaf57ff9b5 to your computer and use it in GitHub Desktop.
Editable CKEDITOR Config
<?php
namespace AppBundle\Document;
final class EditableConstants
{
const TITLE_WYSIWYG_CONFIG = [
'placeholder' => 'Section title ...',
'enterMode' => 2,
"toolbarGroups" => [
[
"name" => 'basicstyles',
"groups" => ['basicstyles', 'colors', 'cleanup']
]
],
'height' => 50
];
const BLOG_WYSIWYG_CONFIG = [
"toolbarGroups" => [
[ 'name' => 'clipboard', 'groups' => [ 'undo', 'clipboard' ] ],
[ 'name' => 'editing', 'groups' => [ 'find', 'selection', 'editing' ] ],
[ 'name' => 'basicstyles', 'groups' => [ 'basicstyles', 'cleanup' ] ],
'/',
[ 'name' => 'paragraph', 'groups' => [ 'align', 'list', 'indent', 'blocks', 'paragraph' ] ],
[ 'name' => 'links', 'groups' => [ 'links' ] ],
[ 'name' => 'insert', 'groups' => [ 'insert' ] ],
'/',
[ 'name' => 'styles', 'groups' => [ 'styles' ] ],
[ 'name' => 'colors', 'groups' => [ 'colors' ] ],
[ 'name' => 'document', 'groups' => [ 'mode' ] ]
],
"removeButtons" => 'Save,NewPage,Preview,Print,Templates,Find,SelectAll,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,CopyFormatting,JustifyBlock,Language,BidiRtl,BidiLtr,Flash,Table,Smiley,PageBreak,Iframe,About,Maximize,ShowBlocks,Font,Styles',
"disallowedContent" => 'h1'
];
const PROFILE_IMAGE_CONFIG = [
'class' => 'img-fluid rounded-circle',
'disableInlineUpload' => true,
'width' => 56,
'height' => 56,
'thumbnail' => 'profile-image'
];
/**
* Extend a constant array with custom config, basically an array_merge but explains why
* @param array $constant
* @param array $newConfig
* @return array
*/
public static function extend($constant=[], $newConfig=[])
{
return array_merge($constant, $newConfig);
}
}
<?php
<?= $this->wysiwyg('content', \AppBundle\Document\EditableConstants::BLOG_WYSIWYG_CONFIG); ?>
@cleggypdc
Copy link
Author

Extend by using

<?= $this->wysiwyg('content', \AppBundle\Document\EditableConstants::extend(
    \AppBundle\Document\EditableConstants::BLOG_WYSIWYG_CONFIG, [
    // your extra config goes here
]
)); ?>

@julkue
Copy link

julkue commented Sep 2, 2019

Use this PHP class for using the class EditableConstants with Twig:

<?php

declare(strict_types=1);

namespace AppBundle\Twig;

use AppBundle\Document\EditableConstants;
use Twig\TwigFunction;
use Twig\Extension\AbstractExtension;

class WYSIWYGEditablesExtension extends AbstractExtension
{
    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return [
            new TwigFunction('wysiwyg_config', function (string $constant) {
                return constant(EditableConstants::class . '::' . $constant);
            }),
        ];
    }
}

Usage:

{{ dump(wysiwyg_config('TITLE_WYSIWYG_CONFIG')) }}

(Don't forgot to register it within templating_twig.yml)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment