-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlCode.php
More file actions
61 lines (52 loc) · 1.51 KB
/
HtmlCode.php
File metadata and controls
61 lines (52 loc) · 1.51 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
<?php declare(strict_types=1);
namespace InteractionDesignFoundation\NovaHtmlCodeField;
use Laravel\Nova\Fields\Textarea;
/**
* @phpcs:disable SlevomatCodingStandard.Classes.RequireAbstractOrFinal
*/
class HtmlCode extends Textarea
{
/**
* The field's component.
* @var string
*/
public $component = 'nova-html-code-field';
/**
* Indicates if the element should be shown on the index view.
* @var bool
*/
public $showOnIndex = false;
/**
* Indicates if the field label and form element should sit on top of each other.
* @var bool
*/
public $stacked = true;
/**
* Set default HTML code (template).
* In order to instruct package where to inject generated HTML, please provide a special marker: "%CODE%"
* Example: <section>%CODE%</section>
* @param string|\Closure():string $template
*/
public function previewTemplate($template): self
{
if (is_callable($template)) {
$template = $template();
}
if (!str_contains($template, '%CODE%')) {
throw new \InvalidArgumentException('%CODE% placeholder is not found in your template. Please add it.');
}
return $this->withMeta([
'template' => $template,
]);
}
/**
* Inject styles to template
* @param list<string> $stylesUrls
*/
final public function styles(array $stylesUrls): self
{
return $this->withMeta([
'styles' => $stylesUrls,
]);
}
}