-
Notifications
You must be signed in to change notification settings - Fork 11
/
Gutenberg.php
90 lines (77 loc) · 2.04 KB
/
Gutenberg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php namespace ReaZzon\Gutenberg\FormWidgets;
use Backend\Classes\FormWidgetBase;
/**
* Gutenberg Form Widget
*/
class Gutenberg extends FormWidgetBase
{
//
// Configurable properties
//
/**
* @var int Minimal height of rich editor. 0 = 100%
*/
public $minheight = 350;
//
// Object properties
//
/**
* @inheritDoc
*/
protected $defaultAlias = 'gutenberg';
/**
* @inheritDoc
*/
public function init()
{
$this->fillFromConfig([
'minheight'
]);
if ($this->formField->disabled) {
$this->readOnly = true;
}
}
/**
* @inheritDoc
*/
public function render()
{
$this->prepareVars();
return $this->makePartial('gutenberg');
}
/**
* Prepares the form widget view data
*/
public function prepareVars()
{
$this->vars['name'] = $this->formField->getName();
$this->vars['value'] = $this->getLoadValue();
$this->vars['model'] = $this->model;
$this->vars['minheight'] = $this->minheight;
}
/**
* @inheritDoc
*/
public function loadAssets()
{
// Required dependencies
// The Gutenberg editor expects React, ReactDOM, Moment and JQuery to be in the environment it runs in.
// An easy way to do this would be to add the following lines to your page:
// Jquery already on page by default OctoberCMS env.
$this->addJs('js/react.production.min.js', 'ReaZzon.Gutenberg');
$this->addJs('js/react-dom.production.min.js', 'ReaZzon.Gutenberg');
// Gutenberg assets
$this->addCss('css/laraberg.css', 'ReaZzon.Gutenberg');
$this->addJs('js/laraberg.js', 'ReaZzon.Gutenberg');
// Formwidget assets
$this->addJs('js/gutenberg.js', 'ReaZzon.Gutenberg');
$this->addCss('css/gutenberg.css', 'ReaZzon.Gutenberg');
}
/**
* @inheritDoc
*/
public function getSaveValue($value)
{
return $value;
}
}