AbstractItemFrontend.php
2.93 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace Nextend\SmartSlider3\Renderable\Item;
use Nextend\Framework\Data\Data;
use Nextend\Framework\Parser\Link;
use Nextend\Framework\Pattern\GetAssetsPathTrait;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\Renderable\Component\ComponentLayer;
abstract class AbstractItemFrontend {
use GetAssetsPathTrait;
/** @var AbstractItem */
protected $item;
protected $id;
/** @var ComponentLayer */
protected $layer;
/** @var Data */
public $data;
protected $isEditor = false;
/**
*
* @param AbstractItem $item
* @param string $id
* @param array $itemData
* @param ComponentLayer $layer
*/
public function __construct($item, $id, $itemData, $layer) {
$this->item = $item;
$this->id = $id;
$this->data = new Data($itemData);
$this->layer = $layer;
$this->fillDefault($item->getValues());
}
private function fillDefault($defaults) {
$this->item->upgradeData($this->data);
$this->data->fillDefault($defaults);
}
public abstract function render();
public function renderAdmin() {
$this->isEditor = true;
/**
* Fix linked fonts/styles for the editor
*/
$this->item->adminNormalizeFontsStyles($this->data);
$rendered = $this->renderAdminTemplate();
$json = $this->data->toJson();
return Html::tag("div", array(
"class" => "n2-ss-item n2-ss-item-" . $this->item->getType(),
"data-item" => $this->item->getType(),
"data-itemvalues" => $json
), $rendered);
}
protected abstract function renderAdminTemplate();
public function needHeight() {
return false;
}
public function isAuto() {
return false;
}
protected function hasLink() {
$link = $this->data->get('href', '#');
if (($link != '#' && !empty($link))) {
return true;
}
return false;
}
protected function getLink($content, $attributes = array(), $renderEmpty = false) {
$link = $this->data->get('href', '#');
$target = $this->data->get('href-target', '#');
$rel = $this->data->get('href-rel', '#');
$class = $this->data->get('href-class', '');
if (($link != '#' && !empty($link)) || $renderEmpty === true) {
$link = Link::parse($this->layer->getOwner()
->fill($link), $attributes, $this->isEditor);
if (!empty($target) && $target != '_self') {
$attributes['target'] = $target;
}
if (!empty($rel)) {
$attributes['rel'] = $rel;
}
if (!empty($class)) {
$attributes['class'] = $class;
}
return Html::link($content, $link, $attributes);
}
return $content;
}
}