diff --git a/README.md b/README.md index 500dd54..4f14bc8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ php artisan vendor:publish --provider="VanOns\Laraberg\LarabergServiceProvider" php artisan vendor:publish --provider="Customberg\PHP\CustombergServiceProvider" ``` -# Usage +# Model Setup The model that you want to use this block editor should have: @@ -37,6 +37,18 @@ CRUD::field('content') ->view_namespace('customberg::'); ``` +# Usage + +Create a new block with the `make:block` command: + +```bash +php artisan make:block AwesomeBlock +``` + +Then edit the block field definition in `app/Blocks/AwesomeBlock.php` file, and the block view in `resources/views/blocks/cb-awesome-block.blade.php`. + +Checkout [/example/app/Blocks/EverySingleField.php](https://github.com/customberg/customberg-php/blob/main/example/app/Blocks/EverySingleField.php) for a full example with every field type. + # Update After an update, get the latest assets using: @@ -63,17 +75,25 @@ Enjoy ! # Roadmap: -| | | -| -------- | ----------------------------- | -| ☐ | A checkbox and a switch field | -| ☐ | Radio field | -| ☐ | Slider field | -| ☐ | Google Maps field | -| ☐ | Documentation ! | -| ☐ | Icon picker field | +| | | +| -------- | ----------------- | +| ✅ | A checkbox field | +| ☐ | Switch field | +| ☐ | Radio field | +| ☐ | Slider field | +| ☐ | Google Maps field | +| ☐ | Documentation ! | +| ☐ | Icon picker field | # Changelog: +### v0.15 - 2024-09-26 + +- New field types: `checkbox`, `textarea`, `number`, `email`, `url` +- New property `placeholder` for text fields +- New property `hint` and `hint_html` for all fields that show a small helper text +- Checkout [/example/app/Blocks/EverySingleField.php](https://github.com/customberg/customberg-php/blob/main/example/app/Blocks/EverySingleField.php) for a full example + ### v0.14 - 2024-08-07 - Bugfix: Preview API while rendering a block with multilanguage, when i'm selecting the new language that does not have translation saved. diff --git a/src/CustombergInstance.php b/src/CustombergInstance.php index 36e943a..8c6c03b 100644 --- a/src/CustombergInstance.php +++ b/src/CustombergInstance.php @@ -95,14 +95,18 @@ public function loadBlocks() } $blockJson = json_encode($block); $init .= " - window.Laraberg.registerBlockType('cb/{$block['slug']}', { - title: '{$block['name']}', - icon: '{$block['icon']}', - category: 'customberg', - attributes: $attributesJson, - edit: window.CustombergEditFields($blockJson), - save: function (props) { return null; }, - }); + try { + window.Laraberg.registerBlockType('cb/{$block['slug']}', { + title: '{$block['name']}', + icon: '{$block['icon']}', + category: 'customberg', + attributes: $attributesJson, + edit: window.CustombergEditFields($blockJson), + save: function (props) { return null; }, + }); + } catch (e) { + console.error('Error registering block: cb/{$block['slug']}', e.message, { e }); + } "; } return " @@ -199,7 +203,8 @@ public function render($html, $lang = null) } } -function str_replace_limit($find, $replacement, $subject, $limit = 0) { +function str_replace_limit($find, $replacement, $subject, $limit = 0) +{ if ($limit == 0) { return str_replace($find, $replacement, $subject); }