Skip to content

Commit 1890173

Browse files
authored
Minor improvements components.md (#179)
1 parent 7c37e8e commit 1890173

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

plugin/components.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Acme\Blog\Components;
2828

2929
class BlogPosts extends \Cms\Classes\ComponentBase
3030
{
31-
public function componentDetails()
31+
public function componentDetails(): array
3232
{
3333
return [
3434
'name' => 'Blog Posts',
@@ -68,10 +68,10 @@ You would be able to access its `posts` method through the `blogPosts` variable.
6868
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:
6969

7070
```php
71-
public function registerComponents()
71+
public function registerComponents(): array
7272
{
7373
return [
74-
'Winter\Demo\Components\Todo' => 'demoTodo'
74+
\Acme\Blog\Components\Todo::class => 'demoTodo'
7575
];
7676
}
7777
```
@@ -83,16 +83,16 @@ This will register the Todo component class with the default alias name **demoTo
8383
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:
8484

8585
```php
86-
public function defineProperties()
86+
public function defineProperties(): array
8787
{
8888
return [
8989
'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',
9696
]
9797
];
9898
}
@@ -146,7 +146,7 @@ A `dropdown` allows you to select a single value from a series of options. A `se
146146
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:
147147

148148
```php
149-
public function defineProperties()
149+
public function defineProperties(): array
150150
{
151151
return [
152152
'units' => [
@@ -173,7 +173,7 @@ public function defineProperties()
173173
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:
174174

175175
```php
176-
public function defineProperties()
176+
public function defineProperties(): array
177177
{
178178
return [
179179
'country' => [
@@ -193,7 +193,7 @@ public function getCountryOptions()
193193
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:
194194

195195
```php
196-
public function defineProperties()
196+
public function defineProperties(): array
197197
{
198198
return [
199199
'country' => [
@@ -233,7 +233,7 @@ public function getStateOptions()
233233
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:
234234

235235
```php
236-
public function defineProperties()
236+
public function defineProperties(): array
237237
{
238238
return [
239239
'postPage' => [

0 commit comments

Comments
 (0)