This repository has been archived by the owner on Jun 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Expandable and use jsonSerialize in favour of meta
- Loading branch information
1 parent
0ecc6ed
commit 26a7133
Showing
1 changed file
with
42 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]); | ||
} | ||
} |