Skip to content

Commit 1ea00e7

Browse files
committed
added image and carousel(90%) blocks
1 parent 0064fb8 commit 1ea00e7

File tree

8 files changed

+200
-1
lines changed

8 files changed

+200
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"mihaildev/yii2-elfinder": "*",
1414
"nullref/yii2-useful": "dev-master",
1515
"nullref/yii2-core": "dev-master",
16-
"nullref/yii2-admin": "dev-master"
16+
"nullref/yii2-admin": "dev-master",
17+
"bower-asset/owl.carousel": "2.*"
1718
},
1819
"autoload": {
1920
"psr-4": {

src/blocks/carousel/Block.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace nullref\cms\blocks\carousel;
4+
5+
use nullref\cms\components\Block as BaseBlock;
6+
/**
7+
* Class Block
8+
*/
9+
class Block extends BaseBlock
10+
{
11+
public $content;
12+
public $tag = 'div';
13+
public $tagClass = 'container';
14+
public $carouselName = 'cms-slider carousel-slider';
15+
16+
public function getName()
17+
{
18+
return 'Carousel Block';
19+
}
20+
21+
public function rules()
22+
{
23+
return [
24+
[['content','tag','tagClass', 'carouselName'],'required'],
25+
];
26+
}
27+
28+
}

src/blocks/carousel/Widget.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace nullref\cms\blocks\carousel;
7+
8+
use nullref\cms\blocks\text\Widget as BaseWidget;
9+
use yii\helpers\Html;
10+
use sersid\owlcarousel\Asset;
11+
12+
13+
class Widget extends BaseWidget
14+
{
15+
public $carouselName;
16+
public function run()
17+
{
18+
Asset::register($this->view);
19+
$this->view->registerJs(<<<JS
20+
jQuery(function(){
21+
var selector = "."+"$this->carouselName";
22+
jQuery(selector).owlCarousel({
23+
loop:true,
24+
center: true,
25+
margin:0,
26+
nav:true,
27+
items: 1
28+
});
29+
});
30+
JS
31+
);
32+
33+
return
34+
Html::beginTag($this->tag, ['class' => $this->tagClass]) .
35+
Html::beginTag('div', ['class' => $this->carouselName]) .
36+
$this->content.
37+
Html::endTag('div') .
38+
Html::endTag($this->tag);
39+
}
40+
}

src/blocks/carousel/_form.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use mihaildev\ckeditor\CKEditor;
4+
use \yii\web\View;
5+
6+
/**
7+
* @var $form \yii\widgets\ActiveForm
8+
* @var $block \nullref\cms\blocks\html\Block
9+
* @var $this \yii\web\View
10+
*/
11+
list(, $footnotesUrl) = Yii::$app->assetManager->publish('@nullref/cms/assets/ckeditor-plugins/codemirror');
12+
$this->registerJs("CKEDITOR.plugins.addExternal( 'codemirror', '" . $footnotesUrl . "/','plugin.js');", View::POS_END);
13+
14+
echo $form->field($block, 'content')->widget(CKEditor::className(), [
15+
'id' => 'editor',
16+
'editorOptions' => [
17+
'preset' => 'full',
18+
'inline' => false,
19+
'extraPlugins' => 'codemirror',
20+
'codemirror' => [
21+
'autoCloseBrackets' => true,
22+
'autoCloseTags' => true,
23+
'autoFormatOnStart' => true,
24+
'autoFormatOnUncomment' => true,
25+
'continueComments' => true,
26+
'enableCodeFolding' => true,
27+
'enableCodeFormatting' => true,
28+
'enableSearchTools' => true,
29+
'highlightMatches' => true,
30+
'indentWithTabs' => false,
31+
'lineNumbers' => true,
32+
'lineWrapping' => true,
33+
'mode' => 'htmlmixed',
34+
'matchBrackets' => true,
35+
'matchTags' => true,
36+
'showAutoCompleteButton' => true,
37+
'showCommentButton' => true,
38+
'showFormatButton' => true,
39+
'showSearchButton' => true,
40+
'showTrailingSpace' => true,
41+
'showUncommentButton' => true,
42+
'styleActiveLine' => true,
43+
'theme' => 'default',
44+
'useBeautify' => true,
45+
],
46+
],
47+
]);
48+
echo $form->field($block, 'tag')->textInput();
49+
echo $form->field($block, 'tagClass')->textInput();
50+
echo $form->field($block, 'carouselName')->textInput();

src/blocks/image/Block.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace nullref\cms\blocks\image;
4+
5+
use nullref\cms\components\Block as BaseBlock;
6+
/**
7+
* Class Block
8+
*/
9+
class Block extends BaseBlock
10+
{
11+
public $image;
12+
public $alt = '';
13+
public $width = 100;
14+
public $height = 100;
15+
16+
public function getName()
17+
{
18+
return 'Image Block';
19+
}
20+
21+
public function rules()
22+
{
23+
return [
24+
[['image','alt', 'width','height'],'required'],
25+
];
26+
}
27+
}

src/blocks/image/Widget.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace nullref\cms\blocks\image;
7+
8+
use nullref\cms\components\Widget as BaseWidget;
9+
use yii\helpers\Html;
10+
11+
12+
class Widget extends BaseWidget
13+
{
14+
public $image;
15+
public $alt = '';
16+
public $width = 100;
17+
public $height = 100;
18+
19+
public function run()
20+
{
21+
return
22+
Html::beginTag('img', [
23+
'src' => $this->image,
24+
'alt' => $this->alt,
25+
'width' => $this->width,
26+
'height' => $this->height,
27+
]) .
28+
Html::endTag('img');
29+
}
30+
}

src/blocks/image/_form.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use mihaildev\elfinder\InputFile;
4+
5+
/**
6+
* @var $form \yii\widgets\ActiveForm
7+
* @var $block \nullref\cms\blocks\text\Block
8+
*/
9+
10+
echo $form->field($block, 'image')->widget(InputFile::className(), [
11+
'language' => 'ru',
12+
'controller' => 'elfinder-backend', // âñòàâëÿåì íàçâàíèå êîíòðîëëåðà, ïî óìîë÷àíèþ ðàâåí elfinder
13+
'filter' => 'image', // ôèëüòð ôàéëîâ, ìîæíî çàäàòü ìàññèâ ôèëüòðîâ https://github.com/Studio-42/elFinder/wiki/Client-configuration-options#wiki-onlyMimes
14+
'template' => '<div class="input-group">{input}<span class="input-group-btn">{button}</span></div>',
15+
'options' => ['class' => 'form-control'],
16+
'buttonOptions' => ['class' => 'btn btn-default'],
17+
'multiple' => false // âîçìîæíîñòü âûáîðà íåñêîëüêèõ ôàéëîâ
18+
]);
19+
echo $form->field($block, 'alt')->textInput();
20+
echo $form->field($block, 'width')->textInput();
21+
echo $form->field($block, 'height')->textInput();

src/components/BlockManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function getList()
2929
return array_merge($this->blocks,[
3030
'text' => 'nullref\cms\blocks\text',
3131
'html' => 'nullref\cms\blocks\html',
32+
'image' => 'nullref\cms\blocks\image',
33+
'carousel' => 'nullref\cms\blocks\carousel',
3234
]);
3335
}
3436

0 commit comments

Comments
 (0)