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: packages/schemas/docs/04-layouts/01-overview.md
+120-11
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
---
2
2
title: Overview
3
3
---
4
+
import UtilityInjection from "@components/UtilityInjection.astro"
4
5
## Overview
5
6
6
-
Filament schemas are not limited to just displaying [form fields](../../forms/fields) and [infolist entries](../../infolists/entries). You can also use "layout components" to organize them into an infinitely nestable structure.
7
+
Filament schemas are not limited to just displaying [form fields](../forms) and [infolist entries](../infolists). You can also use "layout components" to organize them into an infinitely nestable structure.
7
8
8
9
Layout component classes can be found in the `Filament\Schemas\Components` namespace. They reside within the schema array of components.
9
10
@@ -28,33 +29,141 @@ Filament ships with some layout components, suitable for arranging your componen
28
29
-[Wizard](wizard)
29
30
-[Section](section)
30
31
-[Split](split)
31
-
-[Placeholder](placeholder)
32
32
33
-
You may also [create your own custom layout components](custom) to organize fields however you wish.
33
+
You may also [create your own custom layout components](custom) to organize schemas however you wish.
34
34
35
-
## Setting an ID
35
+
## Adding extra HTML attributes to a layout component
36
36
37
-
You may define an ID for the component using the `id()` method:
37
+
You can pass extra HTML attributes to the component via the `extraAttributes()` method, which will be merged onto its outer HTML element. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
<UtilityInjectionset="formFields"version="4.x">As well as allowing a static value, the `extraAttributes()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
47
+
48
+
By default, calling `extraAttributes()` multiple times will overwrite the previous attributes. If you wish to merge the attributes instead, you can pass `merge: true` to the method.
47
49
48
-
You can pass extra HTML attributes to the component, which will be merged onto the outer DOM element. Pass an array of attributes to the `extraAttributes()` method, where the key is the attribute name and the value is the attribute value:
50
+
## Component utility injection
51
+
52
+
The vast majority of methods used to configure entries accept functions as parameters instead of hardcoded values:
Classes will be merged with the default classes, and any other attributes will override the default attributes.
72
+
This alone unlocks many customization possibilities.
73
+
74
+
The package is also able to inject many utilities to use inside these functions, as parameters. All customization methods that accept functions as arguments can inject utilities.
75
+
76
+
These injected utilities require specific parameter names to be used. Otherwise, Filament doesn't know what to inject.
77
+
78
+
### Injecting the state of another component
79
+
80
+
You may also retrieve the state (value) of a form field or infolist entry from within a callback, using a `$get` parameter:
81
+
82
+
```php
83
+
use Filament\Schemas\Components\Utilities\Get;
84
+
85
+
function (Get $get) {
86
+
$email = $get('email'); // Store the value of the `email` entry in the `$email` variable.
87
+
//...
88
+
}
89
+
```
90
+
91
+
### Injecting the current Eloquent record
92
+
93
+
You may retrieve the Eloquent record for the current schema using a `$record` parameter:
94
+
95
+
```php
96
+
use Illuminate\Database\Eloquent\Model;
97
+
98
+
function (?Model $record) {
99
+
// ...
100
+
}
101
+
```
102
+
103
+
### Injecting the current operation
104
+
105
+
If you're writing a schema for a panel resource or relation manager, and you wish to check if a schema is `create`, `edit` or `view`, use the `$operation` parameter:
106
+
107
+
```php
108
+
function (string $operation) {
109
+
// ...
110
+
}
111
+
```
112
+
113
+
<Asidevariant="info">
114
+
You can manually set a schema's operation using the `$schema->operation()` method.
115
+
</Aside>
116
+
117
+
### Injecting the current Livewire component instance
118
+
119
+
If you wish to access the current Livewire component instance, define a `$livewire` parameter:
120
+
121
+
```php
122
+
use Livewire\Component;
123
+
124
+
function (Component $livewire) {
125
+
// ...
126
+
}
127
+
```
128
+
129
+
### Injecting the current component instance
130
+
131
+
If you wish to access the current component instance, define a `$component` parameter:
132
+
133
+
```php
134
+
use Filament\Schemas\Components\Component;
135
+
136
+
function (Component $component) {
137
+
// ...
138
+
}
139
+
```
140
+
141
+
### Injecting multiple utilities
142
+
143
+
The parameters are injected dynamically using reflection, so you are able to combine multiple parameters in any order:
144
+
145
+
```php
146
+
use Filament\Schemas\Components\Utilities\Get;
147
+
use Filament\Schemas\Components\Utilities\Set;
148
+
use Livewire\Component as Livewire;
149
+
150
+
function (Livewire $livewire, Get $get, Set $set) {
151
+
// ...
152
+
}
153
+
```
154
+
155
+
### Injecting dependencies from Laravel's container
156
+
157
+
You may inject anything from Laravel's container like normal, alongside utilities:
0 commit comments