Skip to content

Commit ee89b4c

Browse files
committed
Merge branch 'b20'
2 parents c5ef3d8 + 4b2b767 commit ee89b4c

File tree

9 files changed

+210
-16
lines changed

9 files changed

+210
-16
lines changed

content/collections/fieldtypes/redactor.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ image: 22318543-6610-45b9-b21b-d1bed3b2afe7
55
options:
66
-
77
name: settings
8-
type: array
8+
type: string
99
description: >
10-
An array of settings to be passed into
11-
the Redactor plugin. This should be a
12-
YAML version of the Javascript object
13-
you would use to initialize Redactor.
10+
The _name_ of the Redactor setting configuration you want to use.
11+
If you leave this blank, or specify a name that doesn't exist,
12+
Statamic will use the first set of settings in the list.
1413
id: 25d8be49-2300-42ac-90e4-92df42fc2906
1514
---
1615
## Data Structure {#data-structure}
@@ -22,14 +21,32 @@ quote: |
2221
<blockquote>I signed up for Second Life about a year ago. Back then, my life was so great that I literally wanted a second one. Absolutely everything was the same... except I could fly.</blockquote><p>– Dwight Schrute</p>
2322
```
2423

25-
This is fine, but keep it in mind if you're using it for your `content` field set to "markdown". Statamic parse the `content` as Markdown and any unintended text indentation will be converted to code blocks.
26-
27-
[redactor-docs]: https://imperavi.com/assets/pdf/redactor-documentation-10.pdf
24+
This is fine, but keep it in mind if you're using it for your `content` field and are using a markdown file.
25+
Statamic automatically parses the `content` field as Markdown within `md` files.
2826

2927

3028
## Redactor.js Configuration {#configuration}
3129

32-
You are able to customize all of the Redactor options. You can [view the full list of settings in the Redactor documentation][redactor-docs]
30+
You are able to set any number of predefined Redactor setting configurations. We give you two out of the box, but of
31+
course you are free to modify those and add more.
32+
33+
``` .language-yaml
34+
-
35+
name: Standard
36+
settings:
37+
buttons: [formatting, bold, italic, unorderedlist, orderedlist, html]
38+
-
39+
name: Basic
40+
settings:
41+
buttons: [bold, italic]
42+
```
43+
44+
Each item has a name, which is what you will see when configuring your fieldtype, and the settings themselves.
45+
46+
You can find these Redactor settings in `Configure > Settings > System` or within `site/settings/system.yaml`.
47+
48+
The `settings` value should be a YAML representation of the options object that will get passed into the Redactor jQuery
49+
plugin. You are able to customize all of the Redactor options. You can [view the full list of settings in the Redactor documentation][redactor-docs].
3350

3451
Any settings and options available to the plugin can be set here. For example, if the docs say to use the following configuration object:
3552

@@ -43,12 +60,16 @@ $('textarea').redactor({
4360
You would translate to YAML like so:
4461

4562
``` .language-yaml
46-
settings:
47-
formatting:
48-
- p
49-
- blockquote
50-
- h2
51-
minHeight: 300
63+
-
64+
name: My Redactor Settings
65+
settings:
66+
formatting:
67+
- p
68+
- blockquote
69+
- h2
70+
minHeight: 300
5271
```
5372

5473
*Note: Function type options (eg. callbacks) are not supported.*
74+
75+
[redactor-docs]: https://imperavi.com/assets/pdf/redactor-documentation-10.pdf

content/collections/tags/theme-asset.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ parameters:
1212
description: >
1313
The path to the file, relative to the
1414
theme directory.
15+
-
16+
name: cache_bust
17+
type: 'boolean *false*'
18+
description: >
19+
Setting this to `true` will add the timestamp of the asset to the end of
20+
the URL in a `?v=` query param.
1521
id: de348605-5489-4282-9257-bd9ffd92438e
1622
---
1723
## Explicit mode {#explicit-mode}

content/collections/tags/theme-css.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ parameters:
2020
theme assets, setting this to `true`
2121
will use the manifest to output the
2222
filename.
23+
-
24+
name: cache_bust
25+
type: 'boolean *false*'
26+
description: >
27+
Setting this to `true` will add the timestamp of the asset to the end of
28+
the URL in a `?v=` query param. Use this to version files if you are
29+
_not_ using Elixir.
2330
id: 6b5093dc-dd82-4ae2-a9ff-53d4099d11e3
2431
---
2532
## Example {#example}

content/collections/tags/theme-js.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ parameters:
1717
theme assets, setting this to `true`
1818
will use the manifest to output the
1919
filename.
20+
-
21+
name: cache_bust
22+
type: 'boolean *false*'
23+
description: >
24+
Setting this to `true` will add the timestamp of the asset to the end of
25+
the URL in a `?v=` query param. Use this to version files if you are
26+
_not_ using Elixir.
2027
---
2128
## Example {#example}
2229
```

content/collections/tags/users.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ parameters:
66
name: sort
77
type: string *username*
88
description: Sort entries by a field.
9+
-
10+
name: group
11+
type: string
12+
description: Specify the slug to filter users by a single group.
13+
-
14+
name: role
15+
type: string
16+
description: Specify the slug to filter users by a single role.
917
id: c3e6df36-d705-4293-a5d8-40d27a06a18c
1018
---
1119
This tag has the same functionality as the [collection](collection) tag, with some differences.

content/pages/3.addons/1.getting-started/2.code-structure/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ site/
2222
|-- Models/
2323
| |-- Order.php
2424
| └── Product.php
25+
|-- resources/
26+
| |-- assets/
27+
| | |-- js/
28+
| | |-- css/
29+
| | `-- img/
30+
| |-- lang/
31+
| | `-- en/
32+
| | `-- settings.php
33+
| `-- views/
34+
| `-- index.blade.php
2535
|-- BisonAPI.php
2636
|-- BisonController.php
2737
|-- BisonFieldtype.php
@@ -30,8 +40,12 @@ site/
3040
|-- BisonServiceProvider.php
3141
|-- BisonTags.php
3242
|-- BisonTasks.php
43+
|-- BisonWidget.php
3344
|-- bootstrap.php
3445
|-- composer.json
46+
|-- default.yaml
47+
|-- routes.yaml
48+
|-- settings.yaml
3549
└── meta.yaml
3650
```
3751

content/pages/3.addons/2.anatomy/10.controllers/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class KarmaController extends Controller
3232
}
3333
```
3434

35-
Each public method in the controller can have a route pointed toward it. We can route to the controller action above by editing the routes array in our addon's `meta.yaml` file.
35+
Each public method in the controller can have a route pointed toward it. We can route to the controller action above by editing the routes array in our addon's `routes.yaml` file.
3636

3737
``` .language-yaml
3838
routes:
@@ -64,3 +64,7 @@ routes:
6464
uses: getEdit
6565
as: karma.edit
6666
```
67+
68+
Note: If you want a settings page, you do _not_ need to create a route. A `/cp/addons/addon-name/settings` route
69+
will be available to you automatically. To avoid conflicts you should not create a route named `settings`.
70+
[See how to create a settings page](/addons/anatomy/settings).
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
overview: >
3+
Widgets let you display anything you like on the Control Panel dashboard. From important sales data
4+
to a random Chuck Norris joke of the day.
5+
title: Widgets
6+
id: c6a4207b-8477-48db-9a7f-576b9a714031
7+
---
8+
## Creating a Widget
9+
10+
To create a widget, you will need a class file named `[AddonName]Widget.php`. eg. `ComplimentWidget.php`.
11+
12+
You can also use `php please make:widget AddonName` to have one generated for you.
13+
14+
Here's a basic widget:
15+
16+
``` .language-php
17+
<?php
18+
19+
namespace Statamic\Addons\Compliment;
20+
21+
use Statamic\Extend\Widget;
22+
23+
class ComplimentWidget extends Widget
24+
{
25+
public function html()
26+
{
27+
return '<p>You look extra handsome today.</p>';
28+
}
29+
}
30+
```
31+
32+
Simply add an `html` method that returns a string. That's it.
33+
34+
## Adding the widget to the dashboard
35+
36+
In your Control Panel settings (`Configure > Settings > Control Panel` or `site/settings/cp.yaml`), add your widget
37+
to the array.
38+
39+
```
40+
widgets:
41+
-
42+
type: compliment
43+
```
44+
45+
## Configuring a widget
46+
47+
You may add configuration options to your widget, much like parameters on tags or options in a fieldtype.
48+
49+
Let's say we want to add the option to specify the `gender` receiving the compliment.
50+
51+
``` .language-yaml
52+
widget:
53+
type: compliment
54+
gender: female
55+
```
56+
57+
You can retrieve the config option within the Widget class by using `$this->getConfig('gender')`.
58+
59+
``` .language-php
60+
public function html()
61+
{
62+
$adjective = ($this->getConfig('gender', 'male') === 'male')
63+
? 'handsome' : 'beautiful';
64+
65+
return '<p>You look extra ' . $adjective . ' today.</p>';
66+
}
67+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
overview: >
3+
Addons can be configured using a number of settings. While these are stored in
4+
a YAML file, it's simple to create a UI for editing these through the Control Panel.
5+
title: Settings
6+
id: 14266569-ed5c-4804-b36c-fc66e502491e
7+
---
8+
## Overview
9+
10+
Instead of hard-coding values into your addon, you may allow them to be user-configurable. You may leverage this
11+
using configuration settings.
12+
13+
``` .language-php
14+
// Instead of hardcoding values...
15+
$message = 'Hello John!';
16+
17+
// Use a config setting!
18+
$name = $this->getConfig('greeting_name', 'John');
19+
$message = "Hello {$name}!";
20+
```
21+
22+
You should add all your settings to `default.yaml` in your addon folder. As the filename suggests, these will
23+
act as the default values.
24+
25+
If a user wants to override a setting they may create a `site/addons/addon_name.yaml` file and add the value
26+
in there. Note that the whole `default.yaml` doesn't need to be copied. Only the values that they wish to
27+
override need to be in there.
28+
29+
## Creating a Settings UI {#ui}
30+
31+
A nice alternative to opening YAML files is the ability to edit settings through the Control Panel.
32+
33+
To allow your users to edit your configuration settings, simply create a `settings.yaml` fieldset
34+
in your addon's folder.
35+
36+
``` .language-yaml
37+
fields:
38+
foo:
39+
type: text
40+
```
41+
42+
You should _not_ include `display` or `instructions` values. Instead, these should be added to your addon's
43+
`resources/lang/en/settings.php` file.
44+
45+
``` .language-php
46+
<?php
47+
return [
48+
'foo' => 'Foo',
49+
'foo_instruct' => "What's a foo? You tell me."
50+
];
51+
```
52+
53+
Of course, these strings may be translated into other languages by using separate files.
54+
55+
## Retrieving config settings
56+
57+
You can use `$this->getConfig($value, $fallback)` (as well as the type-casting alternatives: `getConfigInt`,
58+
`getConfigBool`, etc) to retrieve a value.
59+
60+
Config settings can be used from within any addon aspect.

0 commit comments

Comments
 (0)