Skip to content

Commit bfe9951

Browse files
committed
remove doc
1 parent 432e63d commit bfe9951

File tree

1 file changed

+0
-115
lines changed

1 file changed

+0
-115
lines changed

docs/field_types.md

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -319,118 +319,3 @@ $field->setOptions([
319319
// Your options here
320320
]);
321321
```
322-
323-
Callable
324-
--------
325-
326-
The Callable column aims to offer almost as much flexibility as the Twig column, but without requiring the creation of a template.
327-
You simply need to specify a callable, which allows you to transform the 'data' variable on the fly.
328-
329-
When defining callables in YAML, only string representations of callables are supported.
330-
When configuring grids using PHP (as opposed to service grid configuration), both string and array callables are supported. However, closures cannot be used due to restrictions in Symfony's configuration (values of type "Closure" are not permitted in service configuration files).
331-
By contrast, when configuring grids with service definitions, you can use both callables and closures.
332-
333-
Here are some examples of what you can do:
334-
335-
<details open><summary>Yaml</summary>
336-
337-
```yaml
338-
# config/packages/sylius_grid.yaml
339-
340-
sylius_grid:
341-
grids:
342-
app_user:
343-
fields:
344-
id:
345-
type: callable
346-
options:
347-
callable: "callable:App\\Helper\\GridHelper::addHashPrefix"
348-
label: app.ui.id
349-
name:
350-
type: callable
351-
options:
352-
callable: "callable:strtoupper"
353-
label: app.ui.name
354-
```
355-
356-
</details>
357-
358-
<details open><summary>PHP</summary>
359-
360-
```php
361-
<?php
362-
// config/packages/sylius_grid.php
363-
364-
use Sylius\Bundle\GridBundle\Builder\Field\CallableField;
365-
use Sylius\Bundle\GridBundle\Builder\GridBuilder;
366-
use Sylius\Bundle\GridBundle\Config\GridConfig;
367-
368-
return static function (GridConfig $grid): void {
369-
$grid->addGrid(GridBuilder::create('app_user', '%app.model.user.class%')
370-
->addField(
371-
CallableField::create('id', 'App\\Helper\\GridHelper::addHashPrefix')
372-
->setLabel('app.ui.id')
373-
)
374-
// or
375-
->addField(
376-
CallableField::create('id', ['App\\Helper\\GridHelper', 'addHashPrefix'])
377-
->setLabel('app.ui.id')
378-
)
379-
380-
->addField(
381-
CallableField::create('name', 'strtoupper')
382-
->setLabel('app.ui.name')
383-
)
384-
)
385-
};
386-
```
387-
388-
OR
389-
390-
```php
391-
<?php
392-
# src/Grid/UserGrid.php
393-
394-
declare(strict_types=1);
395-
396-
namespace App\Grid;
397-
398-
use App\Entity\User;
399-
use Sylius\Bundle\GridBundle\Builder\Field\CallableField;
400-
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
401-
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
402-
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;
403-
404-
final class UserGrid extends AbstractGrid implements ResourceAwareGridInterface
405-
{
406-
public static function getName(): string
407-
{
408-
return 'app_user';
409-
}
410-
411-
public function buildGrid(GridBuilderInterface $gridBuilder): void
412-
{
413-
$gridBuilder
414-
->addField(
415-
CallableField::create('id', GridHelper::addHashPrefix(...))
416-
->setLabel('app.ui.id')
417-
)
418-
->addField(
419-
CallableField::create('name', 'strtoupper')
420-
->setLabel('app.ui.name')
421-
)
422-
->addField(
423-
CallableField::create('roles' fn (array $roles): string => implode(', ', $roles))
424-
->setLabel('app.ui.roles')
425-
)
426-
;
427-
}
428-
429-
public function getResourceClass(): string
430-
{
431-
return User::class;
432-
}
433-
}
434-
```
435-
436-
</details>

0 commit comments

Comments
 (0)