Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Use Expandable and use jsonSerialize in favour of meta
Browse files Browse the repository at this point in the history
  • Loading branch information
pindab0ter committed Jun 29, 2021
1 parent 0ecc6ed commit 26a7133
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions src/CkEditor.php
Original file line number Diff line number Diff line change
@@ -1,70 +1,83 @@
<?php namespace BayAreaWebPro\NovaFieldCkEditor;

use Laravel\Nova\Fields\Expandable;
use Laravel\Nova\Fields\Field;

class CkEditor extends Field
{
use Expandable;

/**
* The field's component.
* @var string
* @var string $component
*/
public $component = 'ckeditor';

/**
* The meta data for the element.
* Indicates whether the media browser should be available.
* @var bool $mediaBrowser
*/
public bool $mediaBrowser = false;

/**
* Indicates whether the link browser should be available.
* @var bool $linkBrowser
*/
public bool $linkBrowser = false;

/**
* The snippets to be displayed in the snippet browser.
* @var array
*/
public $meta = [
'mediaBrowser' => false,
'linkBrowser' => false,
'shouldShow' => false,
];
public array $snippets = [];

/**
* Enable Media Browser
* Enable Media Browser.
* @param bool $enabled
* @return $this
*/
public function mediaBrowser($enabled = true): self
public function mediaBrowser(bool $enabled = true): self
{
return $this->withMeta([
'mediaBrowser' => $enabled
]);
$this->mediaBrowser = $enabled;

return $this;
}

/**
* Enable Link Browser
* Enable Link Browser.
* @param bool $enabled
* @return $this
*/
public function linkBrowser($enabled = true): self
public function linkBrowser(bool $enabled = true): self
{
return $this->withMeta([
'linkBrowser' => $enabled
]);
$this->linkBrowser = $enabled;

return $this;
}

/**
* Always show value in detail view
* @param bool $enabled
* Enable Snippets Browser.
* @param array $snippets
* @return $this
*/
public function alwaysShow($enabled = true): self
public function snippets(array $snippets): self
{
return $this->withMeta([
'shouldShow' => $enabled
]);
$this->snippets = $snippets;

return $this;
}

/**
* Enable Snippets Browser
* @param array $snippets
* @return $this
* Prepare the element for JSON serialization.
* @return array
*/
public function snippets(array $snippets): self
public function jsonSerialize(): array
{
return $this->withMeta([
'snippetBrowser' => $snippets
return array_merge(parent::jsonSerialize(), [
'mediaBrowser' => $this->mediaBrowser,
'linkBrowser' => $this->linkBrowser,
'snippets' => $this->snippets,
'shouldShow' => $this->shouldBeExpanded(),
]);
}
}

0 comments on commit 26a7133

Please sign in to comment.