|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chillu\ElementalEmbedlyBlock\Block; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
8
|
|
|
use SilverStripe\View\Requirements; |
|
9
|
|
|
|
|
10
|
|
|
class EmbedlyBlock extends BaseElement |
|
11
|
|
|
{ |
|
12
|
|
|
private static $icon = 'font-icon-block-media'; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
private static $db = [ |
|
|
|
|
|
|
15
|
|
|
'EmbedURL' => 'Text', |
|
16
|
|
|
'Width' => 'Varchar', |
|
17
|
|
|
'Align' => 'Enum(array("left","right","center"), "left")', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
private static $singular_name = 'Embed.ly'; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
private static $plural_name = 'Embed.ly'; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
private static $table_name = 'EmbedlyBlock'; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
public function getType() |
|
27
|
|
|
{ |
|
28
|
|
|
return _t(__CLASS__ . '.BlockType', 'Embed.ly'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getCMSFields() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
34
|
|
|
$fields->dataFieldByName('EmbedURL')->setRows(1); |
|
35
|
|
|
|
|
36
|
|
|
$fields->dataFieldByName('Width') |
|
37
|
|
|
->setTitle('Maximum width') |
|
38
|
|
|
->setDescription('Example: 500px, 100%. Cards are responsive by default.'); |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
return parent::getCMSFields(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Return content summary for summary section of ElementEditor |
|
46
|
|
|
* |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function provideBlockSchema() |
|
50
|
|
|
{ |
|
51
|
|
|
$blockSchema = parent::provideBlockSchema(); |
|
52
|
|
|
$blockSchema['content'] = $this->EmbedURL; |
|
|
|
|
|
|
53
|
|
|
return $blockSchema; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getWidthAttribute() |
|
60
|
|
|
{ |
|
61
|
|
|
if (!$this->Width) { |
|
|
|
|
|
|
62
|
|
|
return ''; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (is_numeric($this->Width)) { |
|
66
|
|
|
return "{$this->Width}px"; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// Sanitisation |
|
70
|
|
|
if (!preg_match('/[0-9](\%|px)/', $this->Width)) { |
|
71
|
|
|
return ''; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->Width; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getApiKey() |
|
78
|
|
|
{ |
|
79
|
|
|
return SiteConfig::get()->First()->ElementalEmbedlyApiKey; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|