diff --git a/src/Commands/GenerateBlocks.php b/src/Commands/GenerateBlocks.php index d2af9776f0..131b748f17 100644 --- a/src/Commands/GenerateBlocks.php +++ b/src/Commands/GenerateBlocks.php @@ -7,6 +7,7 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\View; use Illuminate\Support\Str; use Illuminate\View\Factory as ViewFactory; @@ -75,7 +76,9 @@ public function handle() $blockName = str_replace('a17-block-', '', $block->component); $basename = str_replace('.blade.php', '', $block->fileName); + View::share('TwillUntilConsumed', ['renderForBlocks' => true]); $vueBlockTemplate = $this->viewFactory->make('admin.blocks.' . $basename, ['renderForBlocks' => true])->render(); + View::share('TwillUntilConsumed', []); $vueBlockContent = $this->viewFactory->make('twill::blocks.builder', [ 'render' => $this->sanitize($vueBlockTemplate), diff --git a/src/Http/Controllers/Admin/ModuleController.php b/src/Http/Controllers/Admin/ModuleController.php index 1fb30e9c86..92e5f76728 100644 --- a/src/Http/Controllers/Admin/ModuleController.php +++ b/src/Http/Controllers/Admin/ModuleController.php @@ -474,6 +474,7 @@ public function edit($id, $submoduleId = null) return View::exists($view); }); + View::share('form', $this->form($id)); return View::make($view, $this->form($id)); } @@ -505,6 +506,7 @@ public function create($parentModuleId = null) return View::exists($view); }); + View::share('form', $this->form(null)); return View::make($view, $this->form(null)); } @@ -638,6 +640,7 @@ public function restoreRevision($id) Session::flash('restoreMessage', twillTrans('twill::lang.publisher.restore-message', ['user' => $revision->byUser, 'date' => $date])); + View::share('form', $this->form($id, $item)); return View::make($view, $this->form($id, $item)); } diff --git a/src/Http/Controllers/Admin/SingletonModuleController.php b/src/Http/Controllers/Admin/SingletonModuleController.php index 39b854e573..ee0a8d9a90 100644 --- a/src/Http/Controllers/Admin/SingletonModuleController.php +++ b/src/Http/Controllers/Admin/SingletonModuleController.php @@ -3,6 +3,7 @@ namespace A17\Twill\Http\Controllers\Admin; use Illuminate\Support\Facades\Session; +use Illuminate\Support\Facades\View; abstract class SingletonModuleController extends ModuleController { @@ -25,6 +26,7 @@ public function editSingleton() Session::put('pages_back_link', url()->current()); + View::share('form', $this->form($item->id)); return view("admin.{$this->moduleName}.form", $this->form($item->id)); } } diff --git a/src/Services/Blocks/Block.php b/src/Services/Blocks/Block.php index baa8affcfc..2dd4939eae 100644 --- a/src/Services/Blocks/Block.php +++ b/src/Services/Blocks/Block.php @@ -3,6 +3,7 @@ namespace A17\Twill\Services\Blocks; use Exception; +use Illuminate\Support\Facades\View; use Illuminate\Support\Str; class Block @@ -365,12 +366,15 @@ public function getFileName() */ public function render() { - return BladeCompiler::render( + View::share('TwillUntilConsumed', ['renderForBlocks' => true]); + $block = BladeCompiler::render( self::removeSpecialBladeTags($this->contents), [ 'renderForBlocks' => true, ] ); + View::share('TwillUntilConsumed', []); + return $block; } /** diff --git a/src/TwillServiceProvider.php b/src/TwillServiceProvider.php index 4fd3417220..7d33a50364 100644 --- a/src/TwillServiceProvider.php +++ b/src/TwillServiceProvider.php @@ -2,6 +2,8 @@ namespace A17\Twill; +use A17\Twill\View\Components\BlockEditor; +use A17\Twill\View\Components\Checkbox; use Exception; use A17\Twill\Commands\BlockMake; use A17\Twill\Commands\Build; @@ -36,6 +38,7 @@ use Cartalyst\Tags\TagsServiceProvider; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Foundation\AliasLoader; +use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -119,6 +122,11 @@ public function register() $this->registerProviders(); $this->registerAliases(); + // Only works as of laravel 7. + if (self::supportsBladeComponents()) { + Blade::componentNamespace('A17\\Twill\\View\\Components', 'twill'); + } + Relation::morphMap([ 'users' => User::class, 'media' => Media::class, @@ -129,6 +137,10 @@ public function register() config(['twill.version' => $this->version()]); } + public static function supportsBladeComponents(): bool { + return (int)explode('.', app()->version())[0] >= 8; + } + /** * Registers the package service providers. * @@ -169,7 +181,6 @@ private function registerAliases() if (config('twill.enabled.file-library')) { $loader->alias('FileService', FileService::class); } - } /** @@ -333,7 +344,7 @@ private function registerCommands() * @param string $expression * @return string */ - private function includeView($view, $expression) + private function includeView($view, $expression): string { [$name] = str_getcsv($expression, ',', '\''); @@ -341,6 +352,38 @@ private function includeView($view, $expression) $view = $partialNamespace . $view . $name; + if ( + self::supportsBladeComponents() && + class_exists(Blade::getClassComponentNamespaces()['twill'] . '\\' . Str::studly($name)) + ) { + $expression = explode(',', $expression); + array_shift($expression); + $expression = implode(',', $expression); + if ($expression === "") { + $expression = '[]'; + } + $expression = str_replace("'", "\\'", $expression); + + $php = '", $data); ?>'; + + return $php; + } + + // Legacy behaviour. + // @TODO: Not sure if we should keep this. $expression = explode(',', $expression); array_shift($expression); $expression = "(" . implode(',', $expression) . ")"; @@ -374,7 +417,6 @@ private function extendBlade() }); $blade->directive('partialView', function ($expression) { - $expressionAsArray = str_getcsv($expression, ',', '\''); [$moduleName, $viewName] = $expressionAsArray; @@ -432,7 +474,6 @@ private function extendBlade() $blade->aliasComponent('twill::partials.form.utils._connected_fields', 'formConnectedFields'); $blade->aliasComponent('twill::partials.form.utils._inline_checkboxes', 'formInlineCheckboxes'); } - } /** diff --git a/src/View/Components/BlockEditor.php b/src/View/Components/BlockEditor.php new file mode 100644 index 0000000000..b542782a37 --- /dev/null +++ b/src/View/Components/BlockEditor.php @@ -0,0 +1,51 @@ +trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content'); + $this->blocks = $blocks; + $this->groups = $groups; + $this->group = $group; + $this->allowedBlocks = generate_list_of_available_blocks( + $this->blocks ?? null, + $this->group ?? $this->groups ?? null + ); + $this->title = $title ?? Str::title($name); + $this->withoutSeparator = $withoutSeparator; + } + + public function render() + { + return view('twill::partials.form._block_editor', [ + 'editorName' => [ + 'label' => $this->title, + 'value' => $this->name, + ], + ]); + } +} diff --git a/src/View/Components/Browser.php b/src/View/Components/Browser.php new file mode 100644 index 0000000000..43ce7860dc --- /dev/null +++ b/src/View/Components/Browser.php @@ -0,0 +1,94 @@ +name = $name; + $this->moduleName = $moduleName; + $this->modules = $modules; + $this->endpoints = $endpoints; + $this->endpoint = $endpoint; + $this->max = $max; + $this->note = $note; + $this->fieldNote = $fieldNote; + $this->browserNote = $browserNote; + $this->itemLabel = $itemLabel; + $this->buttonOnTop = $buttonOnTop; + $this->wide = $wide; + $this->sortable = $sortable; + $this->routePrefix = $routePrefix; + $this->params = $params; + + $endpointsFromModules = isset($this->modules) ? collect($this->modules)->map(function ($module) { + return [ + 'label' => $module['label'] ?? ucfirst($module['name']), + 'value' => moduleRoute( + $module['name'], + $module['routePrefix'] ?? null, + 'browser', + $module['params'] ?? [], + false + ), + ]; + })->toArray() : null; + + $this->endpoints = $this->endpoints ?? $endpointsFromModules ?? []; + $this->endpoint = $this->endpoint ?? (!empty($endpoints) ? null : moduleRoute( + $this->moduleName, + $this->routePrefix, + 'browser', + $this->params, + false + )); + + $this->itemLabel = $this->itemLabel ?? strtolower($this->label); + + $this->note = $this->note ?? + 'Add' . ($this->max > 1 ? " up to {$this->max} " . $itemLabel : ' one ' . Str::singular($this->itemLabel)); + } + + public function render() + { + return view('twill::partials.form._browser'); + } +} diff --git a/src/View/Components/Checkbox.php b/src/View/Components/Checkbox.php new file mode 100644 index 0000000000..c7e5896eb7 --- /dev/null +++ b/src/View/Components/Checkbox.php @@ -0,0 +1,45 @@ +note = $note; + $this->default = $default; + $this->fieldsInModal = $fieldsInModal; + $this->disabled = $disabled; + $this->border = $border; + $this->confirmMessageText = $confirmMessageText; + $this->confirmTitleText = $confirmTitleText; + $this->requireConfirmation = $requireConfirmation; + } + + public function render() + { + return view('twill::partials.form._checkbox'); + } +} diff --git a/src/View/Components/Checkboxes.php b/src/View/Components/Checkboxes.php new file mode 100644 index 0000000000..294b358884 --- /dev/null +++ b/src/View/Components/Checkboxes.php @@ -0,0 +1,66 @@ +inline = $inline; + $this->border = $border; + $this->min = $min; + $this->max = $max; + } + + public function render() + { + return view('twill::partials.form._checkboxes', [ + 'options' => $this->options, + 'inModal' => $this->isInModal() + ]); + } +} diff --git a/src/View/Components/Color.php b/src/View/Components/Color.php new file mode 100644 index 0000000000..2589f20329 --- /dev/null +++ b/src/View/Components/Color.php @@ -0,0 +1,11 @@ +withTime = $withTime; + $this->allowInput = $allowInput; + $this->allowClear = $allowClear; + $this->note = $note; + $this->inModal = $inModal; + $this->timeOnly = $timeOnly; + $this->placeholder = $placeholder; + $this->required = $required; + $this->time24Hr = $time24Hr; + $this->altFormat = $altFormat; + $this->hourIncrement = $hourIncrement; + $this->minuteIncrement = $minuteIncrement; + } + + public function render() + { + return view('twill::partials.form._date_picker'); + } +} diff --git a/src/View/Components/FieldWithOptions.php b/src/View/Components/FieldWithOptions.php new file mode 100644 index 0000000000..29d3397bc9 --- /dev/null +++ b/src/View/Components/FieldWithOptions.php @@ -0,0 +1,85 @@ +options = $options; + $this->options = $this->getOptions(); + $this->unpack = $unpack; + $this->columns = $columns; + $this->searchable = $searchable; + $this->note = $note; + $this->placeholder = $placeholder; + $this->disabled = $disabled; + $this->addNew = $addNew; + $this->default = $default; + $this->moduleName = $moduleName; + $this->storeUrl = $storeUrl; + $this->fieldsInModal = $fieldsInModal; + + $this->confirmMessageText = null; + $this->confirmTitleText = null; + $this->requireConfirmation = null; + } + + public function isInModal(): bool + { + return $this->fieldsInModal ?? false; + } + + public function getOptions(): array + { + return is_object($this->options) && method_exists($this->options, 'map') ? $this->options->map( + function ($label, $value) { + return [ + 'value' => $value, + 'label' => $label, + ]; + } + )->values()->toArray() : $this->options; + } +} diff --git a/src/View/Components/Files.php b/src/View/Components/Files.php new file mode 100644 index 0000000000..80cfd3547e --- /dev/null +++ b/src/View/Components/Files.php @@ -0,0 +1,43 @@ +itemLabel = $itemLabel; + $this->note = $note ?? 'Add' . ($max > 1 ? " up to $max $itemLabel" : ' one ' . Str::singular($itemLabel)); + $this->fieldNote = $fieldNote; + $this->filesizeMax = $filesizeMax; + $this->buttonOnTop = $buttonOnTop; + $this->max = $max; + } + + public function render() + { + return view('twill::partials.form._files'); + } +} diff --git a/src/View/Components/Input.php b/src/View/Components/Input.php new file mode 100644 index 0000000000..908b475ee8 --- /dev/null +++ b/src/View/Components/Input.php @@ -0,0 +1,69 @@ +type = $type; + $this->translated = $translated; + $this->required = $required; + $this->note = $note; + $this->placeholder = $placeholder; + $this->maxlength = $maxlength; + $this->disabled = $disabled; + $this->readonly = $readonly; + $this->default = $default; + $this->rows = $rows; + $this->ref = $ref; + $this->onChange = $onChange; + $this->onChangeAttribute = $onChangeAttribute; + $this->prefix = $prefix; + $this->inModal = $inModal; + } + + public function render() + { + return view('twill::partials.form._input', [ + 'onChangeFullAttribute' => $this->onChangeAttribute ? "('".$this->onChangeAttribute."', ...arguments)" : "", + ]); + } +} diff --git a/src/View/Components/Map.php b/src/View/Components/Map.php new file mode 100644 index 0000000000..5f0deccd54 --- /dev/null +++ b/src/View/Components/Map.php @@ -0,0 +1,36 @@ +showMap = $showMap; + $this->openMap = $openMap; + $this->inModal = $fieldsInModal ?? false; + $this->saveExtendedData = $saveExtendedData; + $this->autoDetectLatLngValue = $autoDetectLatLngValue; + } + + public function render() + { + return view('twill::partials.form._map'); + } +} diff --git a/src/View/Components/Medias.php b/src/View/Components/Medias.php new file mode 100644 index 0000000000..9e608f7025 --- /dev/null +++ b/src/View/Components/Medias.php @@ -0,0 +1,66 @@ +max = $max; + $this->required = $required; + $this->note = $note; + $this->fieldNote = $fieldNote; + $this->withAddInfo = $withAddInfo; + $this->withVideoUrl = $withVideoUrl; + $this->withCaption = $withCaption; + $this->altTextMaxLength = $altTextMaxLength; + $this->captionMaxLength = $captionMaxLength; + $this->extraMetadatas = $extraMetadatas; + $this->widthMin = $widthMin; + $this->heightMin = $heightMin; + $this->buttonOnTop = $buttonOnTop; + $this->activeCrop = $activeCrop; + } + + public function render() + { + return view('twill::partials.form._medias', [ + 'multiple' => $this->max > 1 || $this->max === 0, + ]); + } +} diff --git a/src/View/Components/MultiSelect.php b/src/View/Components/MultiSelect.php new file mode 100644 index 0000000000..efa3397eb8 --- /dev/null +++ b/src/View/Components/MultiSelect.php @@ -0,0 +1,59 @@ +min = $min; + $this->max = $max; + } + + public function render() + { + return view('twill::partials.form._multi_select', [ + 'options' => $this->options, + 'inModal' => $this->isInModal() + ]); + } +} diff --git a/src/View/Components/Radios.php b/src/View/Components/Radios.php new file mode 100644 index 0000000000..cd611f99bd --- /dev/null +++ b/src/View/Components/Radios.php @@ -0,0 +1,60 @@ +inline = $inline; + $this->border = $border; + } + + public function render() + { + return view('twill::partials.form._radios', [ + 'options' => $this->options, + 'inModal' => $this->isInModal() + ]); + } +} diff --git a/src/View/Components/Repeater.php b/src/View/Components/Repeater.php new file mode 100644 index 0000000000..98547e64fb --- /dev/null +++ b/src/View/Components/Repeater.php @@ -0,0 +1,31 @@ +buttonAsLink = $buttonAsLink; + $this->type = $type; + $this->max = $max; + } + + public function render() + { + return view('twill::partials.form._repeater'); + } +} diff --git a/src/View/Components/Select.php b/src/View/Components/Select.php new file mode 100644 index 0000000000..1fb2b017b6 --- /dev/null +++ b/src/View/Components/Select.php @@ -0,0 +1,14 @@ + $this->options, + 'inModal' => $this->isInModal() + ]); + } +} diff --git a/src/View/Components/TimePicker.php b/src/View/Components/TimePicker.php new file mode 100644 index 0000000000..f7ab6326c0 --- /dev/null +++ b/src/View/Components/TimePicker.php @@ -0,0 +1,14 @@ +timeOnly = true; + $this->withTime = true; + $this->altFormat = $this->altFormat ?? (($this->time24Hr ?? false) ? 'H:i' : 'h:i K'); + return view('twill::partials.form._date_picker'); + } +} diff --git a/src/View/Components/TwillFormComponent.php b/src/View/Components/TwillFormComponent.php new file mode 100644 index 0000000000..48fe94bcda --- /dev/null +++ b/src/View/Components/TwillFormComponent.php @@ -0,0 +1,39 @@ +renderForBlocks = $renderForBlocks; + $this->item = $form['item'] ?? null; + $this->form_fields = $form['form_fields'] ?? []; + $this->name = $name; + $this->label = $label; + + $shared = View::shared('TwillUntilConsumed', []); + foreach ($shared as $key => $value) { + $this->{$key} = $value; + } + } +} diff --git a/src/View/Components/Wysiwyg.php b/src/View/Components/Wysiwyg.php new file mode 100644 index 0000000000..9f5efb2ddf --- /dev/null +++ b/src/View/Components/Wysiwyg.php @@ -0,0 +1,106 @@ +translated = $translated; + $this->required = $required; + $this->maxlength = $maxlength; + $this->options = $options; + $this->placeholder = $placeholder; + $this->note = $note; + $this->disabled = $disabled; + $this->readonly = $readonly; + $this->editSource = $editSource; + $this->toolbarOptions = $toolbarOptions; + $this->inModal = $inModal; + $this->hideCounter = $hideCounter; + $this->type = $type; + $this->limitHeight = $limitHeight; + $this->syntax = $syntax; + $this->customTheme = $customTheme; + $this->customOptions = $customOptions; + $this->default = $default; + } + + public function render() + { + if ($this->toolbarOptions) { + $toolbarOptions = array_map(static function ($option) { + if ($option === 'list-unordered') { + return (object)['list' => 'bullet']; + } + if ($option === 'list-ordered') { + return (object)['list' => 'ordered']; + } + if ($option === 'h1') { + return (object)['header' => 1]; + } + if ($option === 'h2') { + return (object)['header' => 2]; + } + return $option; + }, $this->toolbarOptions); + + $toolbarOptions = [ + 'modules' => [ + 'toolbar' => $toolbarOptions, + 'syntax' => $this->syntax, + ], + ]; + } + + $options = $this->customOptions ?? $toolbarOptions ?? false; + + return view('twill::partials.form._wysiwyg', [ + 'theme' => $this->customTheme, + 'activeSyntax' => $this->syntax, + 'options' => $options, + ]); + } +} diff --git a/views/partials/form/_block_editor.blade.php b/views/partials/form/_block_editor.blade.php index 8baec7e6c6..926e59d7f6 100644 --- a/views/partials/form/_block_editor.blade.php +++ b/views/partials/form/_block_editor.blade.php @@ -1,16 +1,20 @@ -@php - $trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content'); - $name = $name ?? 'default'; - $title = $title ?? Str::title($name); - $allowedBlocks = generate_list_of_available_blocks($blocks ?? null, $group ?? $groups ?? null); +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content'); + $name = $name ?? 'default'; + $title = $title ?? Str::title($name); + $allowedBlocks = generate_list_of_available_blocks($blocks ?? null, $group ?? $groups ?? null); - $editorName = [ - 'label' => $title, - 'value' => $name, - ]; -@endphp + $withoutSeparator = $withoutSeparator ?? false; -@unless($withoutSeparator ?? false) + $editorName = [ + 'label' => $title, + 'value' => $name, + ]; + @endphp +@endunless + +@unless($withoutSeparator)
@endunless diff --git a/views/partials/form/_browser.blade.php b/views/partials/form/_browser.blade.php index a6eec87807..caceca73ea 100644 --- a/views/partials/form/_browser.blade.php +++ b/views/partials/form/_browser.blade.php @@ -1,27 +1,29 @@ -@php - $name = $name ?? $moduleName; - $label = $label ?? 'Missing browser label'; +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $name = $name ?? $moduleName; + $label = $label ?? 'Missing browser label'; - $endpointsFromModules = isset($modules) ? collect($modules)->map(function ($module) { - return [ - 'label' => $module['label'] ?? ucfirst($module['name']), - 'value' => moduleRoute($module['name'], $module['routePrefix'] ?? null, 'browser', $module['params'] ?? [], false) - ]; - })->toArray() : null; + $endpointsFromModules = isset($modules) ? collect($modules)->map(function ($module) { + return [ + 'label' => $module['label'] ?? ucfirst($module['name']), + 'value' => moduleRoute($module['name'], $module['routePrefix'] ?? null, 'browser', $module['params'] ?? [], false) + ]; + })->toArray() : null; - $endpoints = $endpoints ?? $endpointsFromModules ?? []; + $endpoints = $endpoints ?? $endpointsFromModules ?? []; - $endpoint = $endpoint ?? (!empty($endpoints) ? null : moduleRoute($moduleName, $routePrefix ?? null, 'browser', $params ?? [], false)); + $endpoint = $endpoint ?? (!empty($endpoints) ? null : moduleRoute($moduleName, $routePrefix ?? null, 'browser', $params ?? [], false)); - $max = $max ?? 1; - $itemLabel = $itemLabel ?? strtolower($label); - $note = $note ?? 'Add' . ($max > 1 ? " up to $max ". $itemLabel : ' one ' . Str::singular($itemLabel)); - $fieldNote = $fieldNote ?? ''; - $sortable = $sortable ?? true; - $wide = $wide ?? false; - $buttonOnTop = $buttonOnTop ?? false; - $browserNote = $browserNote ?? ''; -@endphp + $max = $max ?? 1; + $itemLabel = $itemLabel ?? strtolower($label); + $note = $note ?? 'Add' . ($max > 1 ? " up to $max ". $itemLabel : ' one ' . Str::singular($itemLabel)); + $fieldNote = $fieldNote ?? ''; + $sortable = $sortable ?? true; + $wide = $wide ?? false; + $buttonOnTop = $buttonOnTop ?? false; + $browserNote = $browserNote ?? ''; + @endphp +@endunless map(function($label, $value) { - return [ - 'value' => $value, - 'label' => $label - ]; - })->values()->toArray() : $options; +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $options = is_object($options) && method_exists($options, 'map') ? $options->map(function($label, $value) { + return [ + 'value' => $value, + 'label' => $label + ]; + })->values()->toArray() : $options; - $note = $note ?? false; - $inline = $inline ?? false; - $border = $border ?? false; - $columns = $columns ?? 0; + $note = $note ?? false; + $inline = $inline ?? false; + $border = $border ?? false; + $columns = $columns ?? 0; - // do not use for now, but this will allow you to create a new option directly from the form - $addNew = $addNew ?? false; - $moduleName = $moduleName ?? null; - $storeUrl = $storeUrl ?? ''; - $inModal = $fieldsInModal ?? false; -@endphp + // do not use for now, but this will allow you to create a new option directly from the form + $addNew = $addNew ?? false; + $moduleName = $moduleName ?? null; + $storeUrl = $storeUrl ?? ''; + $inModal = $fieldsInModal ?? false; + @endphp +@endunless 1 ? " up to $max $itemLabel" : ' one ' . Str::singular($itemLabel)); - $fieldNote = $fieldNote ?? ''; - $filesizeMax = $filesizeMax ?? 0; - $buttonOnTop = $buttonOnTop ?? false; -@endphp +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $max = $max ?? 1; + $itemLabel = $itemLabel ?? strtolower($label); + $note = $note ?? 'Add' . ($max > 1 ? " up to $max $itemLabel" : ' one ' . Str::singular($itemLabel)); + $fieldNote = $fieldNote ?? ''; + $filesizeMax = $filesizeMax ?? 0; + $buttonOnTop = $buttonOnTop ?? false; + @endphp +@endunless 1 || $max == 0; - $widthMin = $widthMin ?? 0; - $heightMin = $heightMin ?? 0; - $buttonOnTop = $buttonOnTop ?? false; - $activeCrop = $activeCrop ?? true; -@endphp +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $max = $max ?? 1; + $required = $required ?? false; + $note = $note ?? ''; + $fieldNote = $fieldNote ?? ''; + $withAddInfo = $withAddInfo ?? true; + $withVideoUrl = $withVideoUrl ?? true; + $withCaption = $withCaption ?? true; + $altTextMaxLength = $altTextMaxLength ?? false; + $captionMaxLength = $captionMaxLength ?? false; + $extraMetadatas = $extraMetadatas ?? false; + $multiple = $max > 1 || $max == 0; + $widthMin = $widthMin ?? 0; + $heightMin = $heightMin ?? 0; + $buttonOnTop = $buttonOnTop ?? false; + $activeCrop = $activeCrop ?? true; + @endphp +@endunless @if (config('twill.media_library.translated_form_fields', $translated ?? false) && ($translated ?? true)) map(function($label, $value) { - return [ - 'value' => $value, - 'label' => $label - ]; - })->values()->toArray() : $options; +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $options = is_object($options) && method_exists($options, 'map') ? $options->map(function($label, $value) { + return [ + 'value' => $value, + 'label' => $label + ]; + })->values()->toArray() : $options; - $unpack = $unpack ?? true; - $note = $note ?? false; - $columns = $columns ?? 0; + $unpack = $unpack ?? true; + $note = $note ?? false; + $columns = $columns ?? 0; - // do not use for now, but this will allow you to create a new option directly from the form - $addNew = $addNew ?? false; - $moduleName = $moduleName ?? null; - $storeUrl = $storeUrl ?? ''; - $inModal = $fieldsInModal ?? false; -@endphp + // do not use for now, but this will allow you to create a new option directly from the form + $addNew = $addNew ?? false; + $moduleName = $moduleName ?? null; + $storeUrl = $storeUrl ?? ''; + $inModal = $fieldsInModal ?? false; + @endphp +@endunless @if ($unpack) map(function($label, $value) { - return [ - 'value' => $value, - 'label' => $label - ]; - })->values()->toArray() : $options; +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $note = $note ?? false; + $options = is_object($options) && method_exists($options, 'map') ? $options->map(function($label, $value) { + return [ + 'value' => $value, + 'label' => $label + ]; + })->values()->toArray() : $options; - $required = $required ?? false; - $default = $default ?? false; - $inline = $inline ?? false; - $border = $border ?? false; - $columns = $columns ?? 0; + $required = $required ?? false; + $default = $default ?? false; + $inline = $inline ?? false; + $border = $border ?? false; + $columns = $columns ?? 0; - // do not use for now, but this will allow you to create a new option directly from the form - $addNew = $addNew ?? false; - $moduleName = $moduleName ?? null; - $storeUrl = $storeUrl ?? ''; - $inModal = $fieldsInModal ?? false; - $confirmMessageText = $confirmMessageText ?? ''; - $confirmTitleText = $confirmTitleText ?? ''; - $requireConfirmation = $requireConfirmation ?? false; -@endphp + // do not use for now, but this will allow you to create a new option directly from the form + $addNew = $addNew ?? false; + $moduleName = $moduleName ?? null; + $storeUrl = $storeUrl ?? ''; + $inModal = $fieldsInModal ?? false; + $confirmMessageText = $confirmMessageText ?? ''; + $confirmTitleText = $confirmTitleText ?? ''; + $requireConfirmation = $requireConfirmation ?? false; + @endphp +@endunless map(function($label, $value) { - return [ - 'value' => $value, - 'label' => $label - ]; - })->values()->toArray() : $options; +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $options = is_object($options) && method_exists($options, 'map') ? $options->map(function($label, $value) { + return [ + 'value' => $value, + 'label' => $label + ]; + })->values()->toArray() : $options; - $note = $note ?? false; - $placeholder = $placeholder ?? false; - $required = $required ?? false; - $searchable = $searchable ?? false; - $disabled = $disabled ?? false; - $columns = $columns ?? 0; + $note = $note ?? false; + $placeholder = $placeholder ?? false; + $required = $required ?? false; + $searchable = $searchable ?? false; + $disabled = $disabled ?? false; + $columns = $columns ?? 0; - // do not use for now, but this will allow you to create a new option directly from the form - $addNew = $addNew ?? false; - $moduleName = $moduleName ?? null; - $storeUrl = $storeUrl ?? ''; - $inModal = $fieldsInModal ?? false; -@endphp + // do not use for now, but this will allow you to create a new option directly from the form + $addNew = $addNew ?? false; + $moduleName = $moduleName ?? null; + $storeUrl = $storeUrl ?? ''; + $inModal = $fieldsInModal ?? false; + @endphp +@endunless @if ($unpack ?? false) $label, 'name' => $name, @@ -11,6 +12,6 @@ 'altFormat' => $altFormat ?? (($time24Hr ?? false) ? 'H:i' : 'h:i K'), 'timeOnly' => true, 'withTime' => true, - 'hourIncrement' => $hourncrement ?? null, + 'hourIncrement' => $hourIncrement ?? null, 'minuteIncrement' => $minuteIncrement ?? null, ]) diff --git a/views/partials/form/_wysiwyg.blade.php b/views/partials/form/_wysiwyg.blade.php index e85c7c2486..7b46149e0b 100644 --- a/views/partials/form/_wysiwyg.blade.php +++ b/views/partials/form/_wysiwyg.blade.php @@ -1,49 +1,51 @@ -@php - $translated = $translated ?? false; - $required = $required ?? false; - $maxlength = $maxlength ?? false; - $options = $options ?? false; - $placeholder = $placeholder ?? false; - $note = $note ?? false; - $disabled = $disabled ?? false; - $readonly = $readonly ?? false; - $editSource = $editSource ?? false; - $toolbarOptions = $toolbarOptions ?? false; - $inModal = $fieldsInModal ?? false; - $default = $default ?? false; - $hideCounter = $hideCounter ?? false; - $type = $type ?? 'quill'; - $limitHeight = $limitHeight ?? false; +@unless(\A17\Twill\TwillServiceProvider::supportsBladeComponents()) + @php + $translated = $translated ?? false; + $required = $required ?? false; + $maxlength = $maxlength ?? false; + $options = $options ?? false; + $placeholder = $placeholder ?? false; + $note = $note ?? false; + $disabled = $disabled ?? false; + $readonly = $readonly ?? false; + $editSource = $editSource ?? false; + $toolbarOptions = $toolbarOptions ?? false; + $inModal = $fieldsInModal ?? false; + $default = $default ?? false; + $hideCounter = $hideCounter ?? false; + $type = $type ?? 'quill'; + $limitHeight = $limitHeight ?? false; - // quill.js options - $activeSyntax = $syntax ?? false; - $theme = $customTheme ?? 'github'; - if ($toolbarOptions) { - $toolbarOptions = array_map(function ($option) { - if ($option == 'list-unordered') { - return (object) ['list' => 'bullet']; - } - if ($option == 'list-ordered') { - return (object) ['list' => 'ordered']; - } - if ($option == 'h1') { - return (object) ['header' => 1]; - } - if ($option == 'h2') { - return (object) ['header' => 2]; - } - return $option; - }, $toolbarOptions); + // quill.js options + $activeSyntax = $syntax ?? false; + $theme = $customTheme ?? 'github'; + if ($toolbarOptions) { + $toolbarOptions = array_map(function ($option) { + if ($option === 'list-unordered') { + return (object) ['list' => 'bullet']; + } + if ($option === 'list-ordered') { + return (object) ['list' => 'ordered']; + } + if ($option === 'h1') { + return (object) ['header' => 1]; + } + if ($option === 'h2') { + return (object) ['header' => 2]; + } + return $option; + }, $toolbarOptions); - $toolbarOptions = [ - 'modules' => [ - 'toolbar' => $toolbarOptions, - 'syntax' => $activeSyntax - ] - ]; - } - $options = $customOptions ?? $toolbarOptions ?? false; -@endphp + $toolbarOptions = [ + 'modules' => [ + 'toolbar' => $toolbarOptions, + 'syntax' => $activeSyntax + ] + ]; + } + $options = $customOptions ?? $toolbarOptions ?? false; + @endphp +@endunless @if($activeSyntax) @pushonce('extra_css:wysiwyg')