|
2 | 2 |
|
3 | 3 | Under the hood Sharp manages a breadcrumb to keep track of stacked pages. |
4 | 4 |
|
5 | | -## Display the breadcrumb |
6 | | - |
7 | | -You can activate the breadcrumb display in sharp's configuration: |
8 | | - |
9 | | -```php |
10 | | -class SharpServiceProvider extends SharpAppServiceProvider |
11 | | -{ |
12 | | - protected function configureSharp(SharpConfigBuilder $config): void |
13 | | - { |
14 | | - $config |
15 | | - ->displayBreadcrumb() |
16 | | - // [...] |
17 | | - } |
18 | | -} |
19 | | -``` |
20 | | - |
21 | 5 | ## Configure entity label |
22 | 6 |
|
23 | 7 | In Entity classes, you can define how an entity should be labeled in the breadcrumb with the `label` attribute: |
@@ -74,6 +58,72 @@ class PostShow extends \Code16\Sharp\Show\SharpShow |
74 | 58 | In the Form, the breadcrumb label is only used in one particular case: when coming from an embedded Entity List inside a Show Page. In this case, the Show Page and the Form entity are different, and the breadcrumb helps to keep track of the current edited entity. |
75 | 59 | ::: |
76 | 60 |
|
| 61 | +## Configure custom labels cache |
| 62 | + |
| 63 | +Breadcrumb labels are cached for 30 minutes to reduce DB queries between each navigation. If you don't want to cache them, which means all `SharpShow` in breadcrumb are loaded on every navigation, you can update the config in the SharpServiceProvider: |
| 64 | + |
| 65 | +```php |
| 66 | +class SharpServiceProvider extends SharpAppServiceProvider |
| 67 | +{ |
| 68 | + protected function configureSharp(SharpConfigBuilder $config): void |
| 69 | + { |
| 70 | + $config |
| 71 | + ->configureBreadcrumbLabelsCache(false) |
| 72 | + // ... |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +Alternatively, you can change the cache duration (default is 30 minutes): |
| 78 | + |
| 79 | +```php |
| 80 | +class SharpServiceProvider extends SharpAppServiceProvider |
| 81 | +{ |
| 82 | + protected function configureSharp(SharpConfigBuilder $config): void |
| 83 | + { |
| 84 | + $config |
| 85 | + ->configureBreadcrumbLabelsCache(duration: 10) |
| 86 | + // ... |
| 87 | + } |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +### Lazy loading |
| 92 | + |
| 93 | +In some cases, having the labels replaced by the default Entity label is acceptable and you want to have less DB queries, you can activate the lazy loading: |
| 94 | + |
| 95 | +```php |
| 96 | +class SharpServiceProvider extends SharpAppServiceProvider |
| 97 | +{ |
| 98 | + protected function configureSharp(SharpConfigBuilder $config): void |
| 99 | + { |
| 100 | + $config |
| 101 | + ->enableBreadcrumbLabelsLazyLoading() |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | +::: warning |
| 106 | +Be aware that the user may see the breadcrumb with default entity labels (e.g. "Posts > Post > Category > Edit") when : |
| 107 | +- a nested page is accessed directly (e.g. direct link) |
| 108 | +- cached labels are expired |
| 109 | +::: |
| 110 | + |
| 111 | +## Hide the breadcrumb |
| 112 | + |
| 113 | +If you don't want any breadcrumb, you can hide it in sharp's configuration: |
| 114 | + |
| 115 | +```php |
| 116 | +class SharpServiceProvider extends SharpAppServiceProvider |
| 117 | +{ |
| 118 | + protected function configureSharp(SharpConfigBuilder $config): void |
| 119 | + { |
| 120 | + $config |
| 121 | + ->displayBreadcrumb(false) |
| 122 | + // [...] |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
77 | 127 | ## Interact with Sharp's Breadcrumb |
78 | 128 |
|
79 | | -Refer to [the Context documentation](context.md) to find out how to interact with Sharp's breadcrumb. |
| 129 | +Refer to [the Context documentation](context.md) to find out how to interact with Sharp's breadcrumb. |
0 commit comments