Skip to content

Commit 081f6bb

Browse files
committed
#20 Do not extend Code field
it contains a lot of extra methods, not needed for our case.
1 parent f45e8c5 commit 081f6bb

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

src/Unlayer.php

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace InteractionDesignFoundation\NovaUnlayerField;
44

5-
use Laravel\Nova\Fields\Code;
5+
use Laravel\Nova\Fields\Field;
66
use Laravel\Nova\Http\Requests\NovaRequest;
77

8-
class Unlayer extends Code
8+
class Unlayer extends Field
99
{
1010
public const MODE_EMAIL = 'email';
1111
public const MODE_WEB = 'web';
@@ -23,7 +23,7 @@ class Unlayer extends Code
2323
public $savingCallback;
2424

2525
/** @var string Height of the editor (with units) */
26-
public $height = '800px';
26+
public string $height = '800px';
2727

2828
/**
2929
* Specify Unlayer config
@@ -54,7 +54,7 @@ final public function savingCallback(?callable $callback): static
5454
}
5555

5656
/**
57-
* Set generated HTML code that can be used on details page.
57+
* Set generated HTML-code that can be used on details page.
5858
* @param string|callable():string $html
5959
*/
6060
final public function html(string | callable $html): static
@@ -76,6 +76,49 @@ final public function plugins(array $plugins): static
7676
return $this->withMeta(['plugins' => $plugins]);
7777
}
7878

79+
80+
/**
81+
* Set the Code editor to display all of its contents.
82+
*/
83+
public function fullHeight(): static
84+
{
85+
$this->height = '100%';
86+
87+
return $this;
88+
}
89+
90+
/**
91+
* Set the visual height of the Code editor to automatic.
92+
*/
93+
public function autoHeight(): static
94+
{
95+
$this->height = 'auto';
96+
97+
return $this;
98+
}
99+
100+
/**
101+
* Set the visual height of the Unlayer editor (with units).
102+
*/
103+
public function height(string $height): static
104+
{
105+
$this->height = $height;
106+
107+
return $this;
108+
}
109+
110+
/**
111+
* Prepare the field for JSON serialization.
112+
*
113+
* @return array<string, mixed>
114+
*/
115+
public function jsonSerialize(): array
116+
{
117+
return array_merge(parent::jsonSerialize(), [
118+
'height' => $this->height,
119+
]);
120+
}
121+
79122
/**
80123
* Hydrate the given attribute on the model based on the incoming request.
81124
* @see \Laravel\Nova\Fields\Field::fillAttributeFromRequest
@@ -85,7 +128,7 @@ final public function plugins(array $plugins): static
85128
* @param string $attribute
86129
* @return void
87130
*/
88-
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
131+
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute): void
89132
{
90133
if (is_callable($this->savingCallback)) {
91134
call_user_func($this->savingCallback, $request, $requestAttribute, $model, "{$requestAttribute}_html");

0 commit comments

Comments
 (0)