Skip to content

Commit

Permalink
#20 Do not extend Code field
Browse files Browse the repository at this point in the history
it contains a lot of extra methods, not needed for our case.
  • Loading branch information
alies-dev committed May 3, 2022
1 parent f45e8c5 commit 081f6bb
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions src/Unlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace InteractionDesignFoundation\NovaUnlayerField;

use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Requests\NovaRequest;

class Unlayer extends Code
class Unlayer extends Field
{
public const MODE_EMAIL = 'email';
public const MODE_WEB = 'web';
Expand All @@ -23,7 +23,7 @@ class Unlayer extends Code
public $savingCallback;

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

/**
* Specify Unlayer config
Expand Down Expand Up @@ -54,7 +54,7 @@ final public function savingCallback(?callable $callback): static
}

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


/**
* Set the Code editor to display all of its contents.
*/
public function fullHeight(): static
{
$this->height = '100%';

return $this;
}

/**
* Set the visual height of the Code editor to automatic.
*/
public function autoHeight(): static
{
$this->height = 'auto';

return $this;
}

/**
* Set the visual height of the Unlayer editor (with units).
*/
public function height(string $height): static
{
$this->height = $height;

return $this;
}

/**
* Prepare the field for JSON serialization.
*
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return array_merge(parent::jsonSerialize(), [
'height' => $this->height,
]);
}

/**
* Hydrate the given attribute on the model based on the incoming request.
* @see \Laravel\Nova\Fields\Field::fillAttributeFromRequest
Expand All @@ -85,7 +128,7 @@ final public function plugins(array $plugins): static
* @param string $attribute
* @return void
*/
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute): void
{
if (is_callable($this->savingCallback)) {
call_user_func($this->savingCallback, $request, $requestAttribute, $model, "{$requestAttribute}_html");
Expand Down

0 comments on commit 081f6bb

Please sign in to comment.