├── docs ├── changelog.md └── install.md ├── kirby-logic-field.php ├── logic └── logic.php ├── package.json └── readme.md /docs/changelog.md: -------------------------------------------------------------------------------- 1 | ## Changelog 2 | 3 | **1.2** 4 | 5 | - Added snippet example to readme. 6 | - Updated the config example to include `$page` as well. 7 | - Sending `$page` separated from `$field`. Two objects instead of just `$field`. 8 | 9 | **1.1** 10 | 11 | - Replaced hook with a `c::set` option. The syntax is now even shorter. 12 | 13 | **1.0** 14 | 15 | - Complete rewrite 16 | - Renamed from Kirby Fragment Field to Kirby Logic Field 17 | - Using a hook instead of a snippet. Only a config is needed. 18 | - Changed from a field to a plugin. -------------------------------------------------------------------------------- /docs/install.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Use one of the alternatives below. 4 | 5 | ## 1. Kirby CLI 6 | 7 | If you are using the [Kirby CLI](https://github.com/getkirby/cli) you can install this plugin by running the following commands in your shell: 8 | 9 | ``` 10 | $ cd path/to/kirby 11 | $ kirby plugin:install jenstornell/kirby-logic-field 12 | ``` 13 | 14 | ## 2. Clone or download 15 | 16 | 1. [Clone](https://github.com/jenstornell/kirby-logic-field.git) or [download](https://github.com/jenstornell/kirby-logic-field/archive/master.zip) this repository. 17 | 2. Unzip the archive if needed and rename the folder to `kirby-logic-field`. 18 | 19 | **Make sure that the plugin folder structure looks like this:** 20 | 21 | ``` 22 | site/plugins/kirby-logic-field/ 23 | ``` 24 | 25 | ## 3. Git Submodule 26 | 27 | If you know your way around Git, you can download this plugin as a submodule: 28 | 29 | ``` 30 | $ cd path/to/kirby 31 | $ git submodule add https://github.com/jenstornell/kirby-logic-field site/plugins/kirby-logic-field 32 | ``` -------------------------------------------------------------------------------- /kirby-logic-field.php: -------------------------------------------------------------------------------- 1 | set('field', 'logic', __DIR__ . DS . 'logic'); -------------------------------------------------------------------------------- /logic/logic.php: -------------------------------------------------------------------------------- 1 | hook($this); 5 | } 6 | 7 | public function hook($field) { 8 | $hook = c::get('plugin.logic.field'); 9 | if(is_callable($hook)) { 10 | $callback = call_user_func_array($hook, array($field, $field->page)); 11 | } 12 | if($callback) return $callback; 13 | } 14 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kirby-logic-field", 3 | "description": "Kirby CMS custom logic field", 4 | "author": "Jens Törnell ", 5 | "version": "1.2", 6 | "type": "kirby-plugin", 7 | "license": "MIT" 8 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Kirby Logic Field 2 | 3 | *Version 1.2 [Changelog](docs/changelog.md)* 4 | 5 | Inject your logic into a custom field. 6 | 7 | **[Installation instructions](docs/install.md)** 8 | 9 | ## Usage 10 | 11 | ### Blueprint 12 | 13 | Set the `type` to `logic`: 14 | 15 | ```yaml 16 | fields: 17 | my_logic_field: 18 | label: My logic field 19 | type: logic 20 | ``` 21 | 22 | ### Code 23 | 24 | **As a config** 25 | 26 | In `config.php` (or a plugin): 27 | 28 | ```php 29 | c::set('plugin.logic.field', function($field, $page) { 30 | return '

' . $field->name() . ' ' . $page->title() . '

'; 31 | }); 32 | ``` 33 | 34 | **As a snippet** 35 | 36 | If you don't like inline html you can replace it with a [snippet](https://getkirby.com/docs/templates/snippets). 37 | 38 | ```php 39 | c::set('plugin.logic.field', function($field, $page) { 40 | return snippet('logic-' . $page->intendedTemplate(), ['field' => $field, 'page' => $page], true); 41 | }); 42 | ``` 43 | 44 | In most cases the filename should be something like `logic-default.php` for the default template. 45 | 46 | You have access to `$field` and `$page` in the snippet. 47 | 48 | ## Requirements 49 | 50 | - [**Kirby**](https://getkirby.com/) 2.4.1+ 51 | 52 | ## Disclaimer 53 | 54 | This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/jenstornell/plugin-name/issues/new). 55 | 56 | ## License 57 | 58 | [MIT](https://opensource.org/licenses/MIT) 59 | 60 | It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech. 61 | 62 | ## Credits 63 | 64 | - [Jens Törnell](https://github.com/jenstornell) 65 | --------------------------------------------------------------------------------