vova07 / yii2-imperavi-widget

Imperavi Redactor widget for Yii 2
Other
247 stars 99 forks source link

predefined links #123

Closed olissongs closed 6 years ago

olissongs commented 6 years ago

Hi, is there a possibility to configure in the widget the predefined links? https://imperavi.com/redactor/plugins/definedlinks/

parameter 'defined-links' or 'definedlinks', no result

thats in a view.php

<?= $form->field($model, 'text')->widget(Widget::className(), [
                    'settings' => [
                        'lang' => 'de',
                        'minHeight' => 200,
                        'imageUpload' => Url::to(['/default/image-upload']),
                        'fileUpload' => Url::to(['/default/file-upload']),
                        'defined-links' => [
                                    [ "name"=> "Select...", "url"=> false ],
                                    [ "name"=> "Google", "url"=> "http://google.com" ],
                                    [ "name"=> "Home", "url"=> "/" ],
                                    [ "name"=> "About", "url"=> "/about/" ],
                                    [ "name"=> "Contact", "url"=> "/contact/" ],
                                ],
                        'plugins' => [
                            'fontsize',
                            'fontcolor',
                            'clips',
                            'fullscreen',
                            'definedlinks',
                            'filemanager',
                            'imagemanager',
                        ],
                    ],
                ]);
                ?>

thats in website html-source-code

redactor({"lang":
...
"defined-links":[{"name":"Select...","url":false},{"name":"Google","url":"http://google.com"},{"name":"Home","url":"/"},{"name":"About","url":"/about/"},{"name":"Contact","url":"/contact/"}],
...
"plugins":["fontsize","fontcolor","clips","fullscreen","definedlinks","filemanager","imagemanager"]
...

no links shown, any ideas? grafik

olissongs commented 6 years ago

working actual yii2 2.013 stable

vova07 commented 6 years ago

Hi @olissongs !

working actual yii2 2.013 stable

Does it mean that it work with that version, or it's the version of framework which doesn't work for you?

Thanks!

olissongs commented 6 years ago

Hi, i wanted to say i'm working with yii2.0.13.1, the general things are working. But the thing with the plugin "definedlinks" wont work.

but i cant say is it an understanding problem on my side, or a bug or a missing documentation thing.

its only the definedlinks thing that i didnt get to run. hope you can help. thanks

vova07 commented 6 years ago

@olissongs I got it, thanks!

So here is the solution:

Code in view.php

<?= \vova07\imperavi\Widget::widget([
        'name' => 'redactor',
        'settings' => [
            'plugins' => ['definedlinks'],
            'definedLinks' => \yii\helpers\Url::to(['site/predefined-links']), // This is very important because it doesn't work with specific JSON or array. It always try to fetch data from specified link.
        ],
    ]); ?>

Code in SiteController (Just because I use this controller in my example)

public function actionPredefinedLinks()
    {
        return json_encode(
            [
                [
                    'name' => 'Select...',
                    'url' => false,
                ],
                [
                    'name' => 'Google',
                    'url' => 'http://google.com',
                ],
                [
                    'name' => 'Home',
                    'url' => '/',
                ],
                [
                    'name' => 'About',
                    'url' => '/about/',
                ],
                [
                    'name' => 'Contact',
                    'url' => '/contact/',
                ],
            ]
        );
    }

Hope it will be useful for you. Feel free to re-open this issue in case you need it. Good luck!

olissongs commented 6 years ago

Yes this works fine! thank you