• This repository has been archived on 27/Jul/2023
  • Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    PHP
  • License
    Other
  • Created over 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CKEditor WYSIWYG widget for Yii2.

CKEditor Widget for Yii2

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Renders a CKEditor WYSIWYG text editor plugin widget.

Installation

The preferred way to install this extension is through composer.

Either run

composer require 2amigos/yii2-ckeditor-widget

or add

"2amigos/yii2-ckeditor-widget" : "~2.1"

to the require section of your application's composer.json file.

Skins & Plugins

This widget works with default's dev-full/stable branch of CKEditor, with a set of plugins and skins. If you wish to configure a different skins or plugins that the one proposed, you will have to download them separately and configure the widget's clientOptions attribute accordingly.

Usage

The library comes with two widgets: CKEditor and CKEditorInline. One is for classic edition and the other for inline editing respectively.

Using a model with a basic preset:


use dosamigos\ckeditor\CKEditor;


<?= $form->field($model, 'text')->widget(CKEditor::className(), [
        'options' => ['rows' => 6],
        'preset' => 'basic'
    ]) ?>

Using inline edition with basic preset:


use dosamigos\ckeditor\CKEditorInline;

<?php CKEditorInline::begin(['preset' => 'basic']);?>
    This text can be edited now :)
<?php CKEditorInline::end();?>

How to add custom plugins

This is the way to add custom plugins to the editor. Since version 2.0 we are working with the packagist version of the CKEditor library, therefore we are required to use its configuration API in order to add external plugins.

Lets add the popular Code Editor Plugin for example. This plugin would allow us to add a button to our editor's toolbar so we can add code to the content we are editing.

Assuming you have downloaded the plugin and added to the root directory of your Yii2 site. I have it this way:

+ frontend 
+ -- web 
    + -- pbckcode 

We can now add it to our CKEditor widget. For this example I am using CKEditorInline widget. One thing you notice on this example is that we do not use the preset attribute; this is highly important as we want to add a customized toolbar to our widget. No more talking, here is the code:

<?php
 
use dosamigos\ckeditor\CKEditorInline;

// First we need to tell CKEDITOR variable where is our external plugin
$this->registerJs("CKEDITOR.plugins.addExternal('pbckcode', '/pbckcode/plugin.js', '');");

// ... 
// Using the plugin
<?php CKEditorInline::begin(['preset' => 'custom', 'clientOptions' => [
    'extraPlugins' => 'pbckcode',
    'toolbarGroups' => [
        ['name' => 'undo'],
        ['name' => 'basicstyles', 'groups' => ['basicstyles', 'cleanup']],
        ['name' => 'colors'],
        ['name' => 'links', 'groups' => ['links', 'insert']],
        ['name' => 'others', 'groups' => ['others', 'about']],
        
        ['name' => 'pbckcode'] // <--- OUR NEW PLUGIN YAY!
    ]
]]) ?>

<p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
    dolore magna aliqua. 
</p>
<?php CKEditorInline::end() ?>

Browse & Upload

To browse and upload files, the KCFinder plugin is used, which is disabled by default.

To enable it, just use 'kcfinder'=>true.

See this simple example code:

<?php
use dosamigos\ckeditor\CKEditor;

echo $form->field($model, 'text')->widget(CKEditor::className(), [
    'kcfinder' => true,
]);

The upload folder name is upload in the root web directory by default.

You can set options for the kcfOptions parameter, and can find all KCFinder's options in this link: https://kcfinder.sunhater.com/install

For change upload directory or change some options you can see this advanced example code:

<?php
use dosamigos\ckeditor\CKEditor;

echo $form->field($model, 'text')->widget(CKEditor::className(), [
    'kcfinder' => true,
    'kcfOptions' => [
        'uploadURL' => '@web/upload',
        'uploadDir' => '@webroot/upload',
        'access' => [  // @link http://kcfinder.sunhater.com/install#_access
            'files' => [
                'upload' => true,
                'delete' => true,
                'copy' => true,
                'move' => true,
                'rename' => true,
            ],
            'dirs' => [
                'create' => true,
                'delete' => true,
                'rename' => true,
            ],
        ],
        'types' => [  // @link http://kcfinder.sunhater.com/install#_types
            'files' => [
                'type' => '',
            ],
        ],
    ],
]);

About extra assets

You maybe wonder why there is file dosamigos-ckeditor.widget.js. The reason is that due to the way Yii2 works with forms and Cross-Site Request Forgery (csrf). CKEditor does not trigger the on change event nor collects the CSRF token when using file uploads.

The asset tackles both issues.

Testing

To test the extension, is better to clone this repository on your computer. After, go to the extensions folder and do the following (assuming you have composer installed on your computer):

$ composer install --no-interaction --prefer-source --dev

Once all required libraries are installed then do:

$ vendor/bin/phpunit

Further Information

Please, check the CKEditor plugin site documentation for further information about its configuration options.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see License File for more information.

2amigOS!
Web development has never been so fun!
www.2amigos.us

More Repositories

1

yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
PHP
292
star
2

yii2-file-upload-widget

BlueImp File Upload Widget for Yii2
PHP
252
star
3

qrcode-library

Create QrCodes with ease
PHP
222
star
4

yiiwheels

Widget extension library for the YiiStrap extension
JavaScript
133
star
5

yii2-date-picker-widget

Bootstrap DatePicker Widget for Yii2
PHP
130
star
6

yii2-chartjs-widget

ChartJs Widget For Yii2
PHP
108
star
7

yii2-google-maps-library

Google Maps API library for Yii2
PHP
106
star
8

yii2-tinymce-widget

TinyMCE WYSIWYG widget for Yii2
JavaScript
100
star
9

yii2-taggable-behavior

This extension allows you to get functional for tagging.
PHP
85
star
10

yii2-selectize-widget

Selectize From Brian Reavis Yii2 Widget
PHP
73
star
11

yii2-translateable-behavior

Handles ActiveRecord's attribute translations
PHP
66
star
12

yii2-gallery-widget

BlueImp Gallery Widget for Yii2
PHP
60
star
13

yii2-editable-widget

X-Editable Widget for Yii2
PHP
58
star
14

yii2-grid-view-library

Highly enhanced GridView widget and grid components for Yii2
PHP
57
star
15

yii2-app-template

Yii 2 Basic Application Template with ConfigKit.
PHP
54
star
16

mailer-library

Mailer library with queue capabilities.
PHP
50
star
17

yii2-multi-select-widget

Bootstrap MultiSelect and MultiSelect Listbox widgets for Yii2
PHP
45
star
18

yiinitializr

Library that will help boost your application installation with ease and also to run Yii applications from its bootstrap files on a much cleaner way that the framework currently proposes.
PHP
44
star
19

yii2-date-time-picker-widget

Bootstrap DateTimePicker Widget for Yii2
PHP
44
star
20

yii2-highcharts-widget

HighCharts Js Widget for Yii2
PHP
42
star
21

yiiwheels-docs

Demo site for yii-wheels
PHP
40
star
22

yii2-resource-manager-component

Uploaded file management extension
PHP
35
star
23

2fa-library

2 Factor Authentication (2FA) library
PHP
34
star
24

yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
PHP
30
star
25

embeddable-js-widget-template

How to create an embeddable JS widget
JavaScript
27
star
26

yii2-transliterator-helper

TransliteratorHelper transliterates UTF-8 encoded text to US-ASCII
PHP
26
star
27

yii2-semantic-ui

Yii2 Semantic UI Extension
PHP
25
star
28

yii2-disqus-widget

DISQUS widget for Yii2
PHP
25
star
29

yii2-config-kit

Configuration kit for Yii applications
PHP
24
star
30

ei18n

Ei18 is a translation module to allow Yii'ers to easily manage missing translations on application pages. It is heavily inspired by yii.translate developed by Gustavo SalomΓ© Silva.
JavaScript
24
star
31

yii2-type-ahead-widget

Twitter Typeahead Bootstrap Widget
PHP
23
star
32

yii2-file-input-widget

Jasny File Input Bootstrap Widget
PHP
23
star
33

mail-api-service

A microservice to send emails based on templates.
PHP
23
star
34

yii2-google-places-library

Google Places API library for Yii2
PHP
23
star
35

yiifoundation

Yii extension library for the ZURB Foundation Framework
CSS
22
star
36

yii2-flysystem-component

The League Flysystem Library for Yii Framework
PHP
22
star
37

yiiaws

Amazon Web Services SDK PHP 2 Wrapper
PHP
21
star
38

yii2-arrayquery-component

ArrayQuery allows you to apply conditions to arrays that are to be displayed with ArrayDataProviders
PHP
21
star
39

yii2-exportable-widget

Allows the exportation of a GridView widget to different formats
PHP
20
star
40

yii2-switch-widget

Bootstrap Switch Widget for Yii2
PHP
17
star
41

egmap

Objet-oriented PHP abstraction to the Google Maps API to ease the process of adding a Google Map on your Yii projects.
PHP
14
star
42

efeed

Feed Writer Generator Extension (RSS 1.0, RSS 2.0, and ATOM 1.0)
PHP
12
star
43

yii-cdn-asset-management-library

CDN Asset Management Tools for Yii1
PHP
12
star
44

yii2-croppie-widget

Image cropping plugin for Yii2
PHP
11
star
45

yii2-dynamic-form

JavaScript
10
star
46

escriptboost

Minify the javascript/css code of your application's assets and pages
PHP
9
star
47

storage-api-service

A microservice that abstracts asset storage on different providers
PHP
9
star
48

google-places-library

Google Places API library
PHP
9
star
49

egeoip

EGeoIp Extension uses geoPlugin free webservice to locate IP geo information
PHP
9
star
50

yii2-bootstrap-form-helpers-library

Bootstrap Form Helpers Library Widgets for Yii2.
JavaScript
8
star
51

yii2-extension-skeleton

A skeleton repository for Yii2 Skeleton Packages
PHP
8
star
52

yii2-switchery-widget

Yii2 wrapper for iOS 7 style switches for your checkboxes
PHP
7
star
53

yii2-app-usuario-template

Yii 2 Basic Application Template with ConfigKit and Yii 2 Usuario Module
PHP
7
star
54

yii2-select2-widget

Select 2 jQuery plugin for Yii2 with Bootstrap theme capabilities
PHP
7
star
55

yiiwheels-custom

Yiiwheels custom library. Removes Yiistrap dependency and implements Yii2 based bootstrap library to be used on Yii1.
JavaScript
6
star
56

yiihelpers

A library of useful Helper functions to give your apps an extra hand.
PHP
6
star
57

transliteration-helper

TransliteratorHelper transliterates UTF-8 encoded text to US-ASCII
PHP
5
star
58

yii2-twilio-component

A Yii2 Application Component to ease the use of Twilio's PHP SDK
PHP
5
star
59

resource-manager

Uploaded file management extension
PHP
5
star
60

yii2-pjax-filter-behavior

PjaxFilter is an action filter that filters HTTP requests to ensure pjax calls.
PHP
4
star
61

yii2-leaflet-geocoder-plugin

Yii 2 Plugin that adds geo search capabilities to your leaflet maps with dropdown list capabilities.
PHP
4
star
62

yii2-leaflet-markercluster-plugin

Yii 2 LeafLet Plugin to provide beautiful, sophisticated, high performance marker clustering solution with smooth animations and lots of great features.
JavaScript
4
star
63

yii2-shopping-cart-component

3
star
64

yii2-dosamigos-asset-bundle

Includes assets that are common to projects using dosamigos extensions.
JavaScript
3
star
65

laravel-mail-api

A microservice to send emails based on templates.
PHP
2
star
66

yii2-nexmo-library

Allows you to send SMS through Nexmo Service Provider.
PHP
2
star
67

yii2-packagist-component

Yii 2 Packagist API extension component
PHP
1
star
68

command-bus

Simple Command Bus
PHP
1
star
69

yii2-leaflet-geosearch-plugin

Yii 2 Plugin that adds geo search capabilities to your leaflet maps.
JavaScript
1
star
70

yii2-file-manager

1
star
71

yii2-leaflet-makimarker-plugin

Yii 2 LeafLet Plugin to create map icons using Maki Icons from MapBox.
PHP
1
star