2017 © Pedro Peláez
 

yii2-extension contenttools

ContentTools editor implementation for Yii 2.

image

dkhru/contenttools

ContentTools editor implementation for Yii 2.

  • Thursday, October 29, 2015
  • by dkhru
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yii2-content-tools

ContentTools editor implementation for Yii 2., (*1)

ContentTools

Check out ContentTools website http://getcontenttools.com for more information about the editor., (*2)

Installation

Add the package to your composer.json:, (*3)

{
    "require": {
        "bizley/contenttools": "dev-master"
    }
}

and run composer update or alternatively run composer require bizley/contenttools, (*4)

Usage

1. The widget.

Wrap any part of the content with <?php bizley\contenttools\ContentTools::begin(); ?> and <?php bizley\contenttools\ContentTools::end(); ?>., (*5)

<?php bizley\contenttools\ContentTools::begin(); ?>
This is the part of view that is editable.
<p>There are paragraphs</p>
<div>and more...</div>
<?php bizley\contenttools\ContentTools::end(); ?>

You can use the widget multiple times on one page., (*6)

2. Backend.

ContentTools saves content and uploaded images asynchronously and it requires some preparation on the backend side., (*7)

You have to create few controllers' actions: - "upload new image" action, - "rotate uploaded image" action, - "insert & crop uploaded image" action, - "save content" action., (*8)

Three first actions are already prepared if you don't want any special operations. You can find them in 'actions' folder. - UploadAction - takes care of validating the uploaded images using bizley\contenttools\models\ImageForm (jpg, png and gif images are allowed, maximum width and height is 1000px and maximum size is 2MB), images are saved in 'content-tools-uploads' folder accessible from web. - RotateAction - takes care of rotating the uploaded image using Imagine library (through yii2-imagine required in the composer.json). - InsertAction - takes care of inserting image into the content with optional cropping using Imagine library., (*9)

The default option for the image urls is:, (*10)

'imagesEngine' => [
    'upload' => '/site/content-tools-image-upload',
    'rotate' => '/site/content-tools-image-rotate',
    'insert' => '/site/content-tools-image-insert',
],

So if you don't want to change the 'imagesEngine' parameter add in your SiteController:, (*11)

public function actions()
{
    return [
        'content-tools-image-upload' => bizley\contenttools\actions\UploadAction::className(),
        'content-tools-image-insert' => bizley\contenttools\actions\InsertAction::className(),
        'content-tools-image-rotate' => bizley\contenttools\actions\RotateAction::className(),
    ];
}

The last "save content" action is not prepared so go ahead and take care of it. Default configuration for this is:, (*12)

'saveEngine' => [
    'save' => '/site/save-content',
],

Options

You can add options for the widget by passing the configuration array in the begin() method., (*13)

id

default: null Identifier of the editable region (must be unique). If left empty it is automatically set to 'contentToolsXXX' where XXX is the number of next widget., (*14)

tag

default: 'div' Tag that will be used to wrap the editable content., (*15)

dataName

default: 'name' Name of the data-* attribute that will store the identifier of editable region., (*16)

dataInit

default: 'editable' Name of the data-* attribute that will mark the region as editable., (*17)

options

default: [] Array of html options that will be applied to editable region's tag., (*18)

imagesEngine

default:, (*19)

[
    'upload' => '/site/content-tools-image-upload',
    'rotate' => '/site/content-tools-image-rotate',
    'insert' => '/site/content-tools-image-insert',
]

Array of the urls of the image actions OR false to switch off the default image engine (you will have to prepare js for handling images on your own)., (*20)

saveEngine

default:, (*21)

[
    'save' => '/site/save-content',
]

Array with the url of the content saving action OR false to switch off the default saving engine (you will have to prepare js for handling content saving on your own)., (*22)

styles

default: [] Array of styles that can be applied to the edited content. Every style should be added in array like:, (*23)

'Name of the style' => [
    'class' => 'Name of the CSS class',
    'tags'  => [Array of the html tags this can be applied to] or 'comma-separated list of the html tags this can be applied to'
],

Example:, (*24)

'Bootstrap Green' => [
    'class' => 'text-success',
    'tags'  => ['p', 'h2', 'h1']
],

'tags' key is optional and if omitted style can be applied to every element., (*25)

language

default: false Boolean flag or language code of the widget translation. You can see the list of prepared translations in 'ContentTools/translations' folder. false means that widget will not be translated (default language is English). true means that widget will be translated using the application language. If this parameter is a string widget tries to load the translation file with the given name. If it cannot be found and string is longer that 2 characters widget tries again this time with parameter shortened to 2 characters. If again it cannot be found language sets back to default., (*26)

globalConfig

default: true Boolean flag whether the configuration should be global. Global configuration means that every succeeding widget ignores tag, dataName, dataInit, imagesEngine, saveEngine and language parameters and sets them to be the same as in the first one. Also styles are added only if they've got unique names., (*27)

Actions callbacks

The default js image callbacks assume the following action response:, (*28)

{
    'size': [image-width-in-px, image-height-in-px],
    'url': image-url
}

with optional 'alt' for insert-action. In case of any errors response should be:, (*29)

{
    'errors': [array-of-error-descriptions]
}

At the moment errors are only displayed in browser's console (user sees only the big transparent cross)., (*30)

Saving content

Action responsible for saving the content should expect the array of every page region data in pairs 'region-identifier' => 'region-content'. You can set the 'id' of the region to be ModelName[attributeName] so it can be handled in the standard Yii 2 way (i.e. with load())., (*31)

The Versions

29/10 2015

dev-master

9999999-dev

ContentTools editor implementation for Yii 2.

  Sources   Download

Apache-2.0

The Requires

 

by Pawel Bizley Brzozowski

extension yii2 widget editor wysiwyg contenttools