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

Add support for alwaysShow() by using Expandable trait #6

Merged
merged 2 commits into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions src/CkEditor.php
Original file line number Diff line number Diff line change
@@ -1,57 +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,
];
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;
}

/**
* Enable Snippets Browser
* Enable Snippets Browser.
* @param array $snippets
* @return $this
*/
public function snippets(array $snippets): self
{
return $this->withMeta([
'snippetBrowser' => $snippets
$this->snippets = $snippets;

return $this;
}

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