Search code examples
phpyii2yii2-advanced-appsummernote

yii2 summernote widget set toolbar options


I am implementing the summernote in Yii2 warped by marqu3s\summernote\Summernote; https://github.com/undeman/yii2-summernote

but I can't manage to add the toolbar options showing in the summernote documentation: http://summernote.org/deep-dive/

That how I am trying to use it but when ever I add the toolbar option the toolbar goes away.

    $tabReport .= $form->field($model, 'ysk')->widget(Summernote::className(), [
    'clientOptions' => [
        'placeholder' => 'You can write here some important public notes to be display on top of the report...',
        'minHeight' => 100,
        'toolbar' => [
            'style' => ['bold', 'italic', 'underline', 'clear'],
        ],
    ],
  ]
);

Any clues?


Solution

  • Your array format is wrong:

    'toolbar' => [
        'style' => ['bold', 'italic', 'underline', 'clear'],
    ],
    

    will produce the js:

    'toolbar': {'style': ['bold', 'italic', 'underline', 'clear']}
    

    To produce the required js use the same structure as you would in javascript i.e:

    'toolbar' => [
         ['style': ['bold', 'italic', 'underline', 'clear']]
    ]
    

    In the case of your your answer:

    'toolbar' => [
        ['style', ['style']],
        ['font', ['bold', 'italic', 'underline', 'clear']],
        ['fontname', ['fontname']],
        ['color', ['color']],
        ['para', ['ul', 'ol', 'paragraph']],
        ['height', ['height']],
        ['table', ['table']],
        ['insert', ['link', 'picture', 'hr']],
        ['view', ['fullscreen', 'codeview']],
        ['help', ['help']],
    ]