You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: plugin/components.md
+14-14
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ namespace Acme\Blog\Components;
28
28
29
29
class BlogPosts extends \Cms\Classes\ComponentBase
30
30
{
31
-
public function componentDetails()
31
+
public function componentDetails(): array
32
32
{
33
33
return [
34
34
'name' => 'Blog Posts',
@@ -68,10 +68,10 @@ You would be able to access its `posts` method through the `blogPosts` variable.
68
68
Components must be registered by overriding the `registerComponents` method inside the [Plugin registration class](registration#registration-file). This tells the CMS about the Component and provides a **short name** for using it. An example of registering a component:
69
69
70
70
```php
71
-
public function registerComponents()
71
+
public function registerComponents(): array
72
72
{
73
73
return [
74
-
'Winter\Demo\Components\Todo' => 'demoTodo'
74
+
\Acme\Blog\Components\Todo::class => 'demoTodo'
75
75
];
76
76
}
77
77
```
@@ -83,16 +83,16 @@ This will register the Todo component class with the default alias name **demoTo
83
83
When you add a component to a page or layout you can configure it using properties. The properties are defined with the `defineProperties` method of the component class. The next example shows how to define a component property:
84
84
85
85
```php
86
-
public function defineProperties()
86
+
public function defineProperties(): array
87
87
{
88
88
return [
89
89
'maxItems' => [
90
-
'title' => 'Max items',
91
-
'description' => 'The most amount of todo items allowed',
92
-
'default' => 10,
93
-
'type' => 'string',
94
-
'validationPattern' => '^[0-9]+$',
95
-
'validationMessage' => 'The Max Items property can contain only numeric symbols'
90
+
'title' => 'Max items',
91
+
'description' => 'The most amount of todo items allowed',
92
+
'default' => 10,
93
+
'type' => 'string',
94
+
'validationPattern' => '^[0-9]+$',
95
+
'validationMessage' => 'The Max Items property can contain only numeric symbols',
96
96
]
97
97
];
98
98
}
@@ -146,7 +146,7 @@ A `dropdown` allows you to select a single value from a series of options. A `se
146
146
The option list for `dropdown` and `set` properties can be static or dynamic. Static options are defined with the `options` property for dropdowns and the `items` property for sets. Example:
147
147
148
148
```php
149
-
public function defineProperties()
149
+
public function defineProperties(): array
150
150
{
151
151
return [
152
152
'units' => [
@@ -173,7 +173,7 @@ public function defineProperties()
173
173
The list of options or items could be fetched dynamically from the server when the Inspector is displayed. If the `options` parameter is omitted for dropdowns or the `items` parameter is omitted for sets, the list is considered dynamic. The component class must define a method returning this list. The method should have a name in the following format: `get*Property*Options`, where **Property** is the property name, for example: `getCountryOptions`. The method returns an array of options with the option values as keys and option labels as values. Example of a dynamic dropdown list definition:
174
174
175
175
```php
176
-
public function defineProperties()
176
+
public function defineProperties(): array
177
177
{
178
178
return [
179
179
'country' => [
@@ -193,7 +193,7 @@ public function getCountryOptions()
193
193
Dynamic `dropdown` and `set` lists can depend on other properties. For example, the state list could depend on the selected country. The dependencies are declared with the `depends` parameter in the property definition. The next example defines two dynamic dropdown properties and the state list depends on the country:
194
194
195
195
```php
196
-
public function defineProperties()
196
+
public function defineProperties(): array
197
197
{
198
198
return [
199
199
'country' => [
@@ -233,7 +233,7 @@ public function getStateOptions()
233
233
Sometimes components need to create links to the website pages. For example, the blog post list contains links to the blog post details page. In this case the component should know the post details page file name (then it can use the [page Twig filter](/docs/v1.2/markup/filters/page)). Winter includes a helper for creating dynamic dropdown page lists. The next example defines the postPage property which displays a list of pages:
0 commit comments