dmstr/yii2-widgets2-module

Yii 2.0 Framework Widget Manager

Installs: 9 413

Dependents: 2

Suggesters: 0

Stars: 5

Watchers: 6

Forks: 6

Open Issues: 3

Type:yii2-extension

2.0.0-rc2 2019-04-05 12:02 UTC

README

Latest Stable Version Total Downloads License

Widget manager using twig templates

Installation

The preferred way to install this extension is through composer.

Either run

composer require dmstr/yii2-widgets2-module

to the require section of your composer.json file.

Testing

cd tests

docker-compose up -d

docker-compose run phpfpm bash

setup.sh

Config

...
'modules => [
	'widgets' => [
		'class' => '\hrzg\widget\Module',
		'layout' => '@backend/views/layouts/main',
		'playgroundLayout' => '@frontend/views/layouts/main',
		'dateBasedAccessControl' => true,
		'datepickerMinutes' => false,
		'timezone' => 'Europe/Berlin'
	]
]
...

Settings

availablePhpClasses

Usage

Once the extension is installed, simply use it in your code by :

Layout

Example with yii2-prototype-module

{{ use ('hrzg/widget/widgets') }}
{{ cell_widget({id: 'main'}) }}

Widget

  • Standard Twig widget hrzg\widget\widgets\TwigTemplate
  • Char-Rank ordering 001, 10, 5, aa1, aa1.2, b0 (not numeric)

JSON

Settings

Section: widgets

Key: availablePhpClasses

Type: JSON

####Example:

{"hrzg\\widget\\widgets\\TwigTemplate": "Twig layout"}

Widget example

Basic

{
    "title": "Basic",
    "type": "object",
    "properties": {
        "headline": {
            "type": "string",
            "default": "Avo vole tioma profitanto ts,"
        },
        "text_html": {
            "type": "string",
            "format": "html",
            "default": "Ja sub kiam aliu, fo unt fora danke helpverbo, dev bv tele kibi piedpilko.",
            "options": {
                "wysiwyg": true
            }
        }
    }
}
<h2>{{ headline }}</h2>
<p>{{ text_html }}</p>

For more examples, please see the docs

Copy widgets

Console config

If you use the dmstr/yii2-pages-module >= 0.21.3, set pagesModule to true and the widget route and request_param will be recognized.

In case pagesModule to true

The copy process will only be successful if every widget which is placed on the default pages route /pages/default/page has the corresponding page object in the source language before copy. In short: If you have widgets in your database, placed on route = /pages/default/page and request_param = page id the page with that page id MUST exist. If not, the widget is an orphan and must be deleted before you are able to copy

'controllerMap'       => [
	'copy-widgets' => [
		'class' => '\hrzg\widget\commands\CopyController',
		'pagesModule' => true
	]
]

CLI

Command: ./yii copy-widgets/language --sourceLanguage --destinationLanguage

Web UI

Url: /widgets/copy

RBAC permission

widgets_copy

This permission means that the user is allowed to copy widgets between languages. Also used to enable the access_domain input for widget content with all available application languages.

Usage

  • Go to -> /widgets/copy
  • Select the source language (you can select the global domain if you have permissions to)
  • Select the target language (you can select the global domain if you have permissions to)
  • Start Copy

Upgrading

from 0.2 to 0.3

{{ cell_widget({id: 'header'}) }}

RBAC

Available Permission items

Name Description
widgets_default_index Widgets Manager
widgets_crud_api Widgets CRUD API
widgets_crud_widget Widgets CRUD Content
widgets_crud_widget_copy Widgets CRUD Content Copy
widgets_crud_widget_create Widgets CRUD Content Create
widgets_crud_widget_delete Widgets CRUD Content Delete
widgets_crud_widget_index Widgets CRUD Content Index
widgets_crud_widget_update Widgets CRUD Content Update
widgets_crud_widget_view Widgets CRUD Content View
widgets_crud_widget-template Widgets CRUD Template
widgets_test Widgets TEST Playground
widgets_copy Widgets Language Copy
widgets-cell-edit Frontend editing
widgets Widgets Module

From dmstr/yii2-backend-module: frontend.toggle-view-mode

Settings

Section Key Value Type
widgets ckeditor.config
    {
      "height": "4000px",
      "toolbar": [
        ["Format"],
        ["Link", "Image", "Table", "-", "NumberedList", "BulletedList", "-", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"],
        ["Source"],
        "/", ["Bold", "Italic", "Underline", "StrikeThrough", "-", "RemoveFormat", "-", "Undo", "Redo", "-", "Paste", "PasteText", "PasteFromWord", "-", "Cut", "Copy", "Find", "Replace", "-", "Outdent", "Indent", "-", "Print"]
      ]
    }
OBJECT/JSON