|
1 |
| -# Links by FriendsOfFlarum |
| 1 | +# FoF Links |
2 | 2 |
|
3 |
| - [](https://packagist.org/packages/fof/links) |
| 3 | + [](https://packagist.org/packages/fof/links) [](https://packagist.org/packages/fof/links) |
4 | 4 |
|
5 |
| -A [Flarum](http://flarum.org) extension. Manage Flarum primary navigation links. Original by @sijad. |
| 5 | +A [Flarum](http://flarum.org) extension that allows you to add links to your forum's navigation. |
6 | 6 |
|
7 |
| - |
| 7 | +## Features |
8 | 8 |
|
9 |
| -### Installation |
| 9 | +- Add links to your forum's navigation menu |
| 10 | +- Support for both internal and external links |
| 11 | +- Control link visibility based on user groups |
| 12 | +- Guest-only links |
| 13 | +- Hierarchical links (dropdown menus) |
| 14 | +- Programmatic link definition via PHP |
10 | 15 |
|
11 |
| -Use [Bazaar](https://discuss.flarum.org/d/5151-flagrow-bazaar-the-extension-marketplace) or install manually with composer: |
| 16 | +## Installation |
12 | 17 |
|
13 |
| -```sh |
| 18 | +Install with composer: |
| 19 | + |
| 20 | +```bash |
14 | 21 | composer require fof/links
|
15 | 22 | ```
|
16 | 23 |
|
17 |
| -### Updating |
| 24 | +## Updating |
18 | 25 |
|
19 |
| -```sh |
| 26 | +```bash |
20 | 27 | composer update fof/links
|
| 28 | +php flarum cache:clear |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### Admin Interface |
| 34 | + |
| 35 | +Links can be managed through the admin interface under the "Links" tab. |
| 36 | + |
| 37 | +### Programmatic Link Definition |
| 38 | + |
| 39 | +This extension provides a way to define links programmatically through PHP code. This can be useful in situations where there are multiple environments (ie dev, staging, production) and you want to define a set of links only once (in code), and not have to re-enter or define them via the admin interface. |
| 40 | + |
| 41 | +#### Basic Usage |
| 42 | + |
| 43 | +```php |
| 44 | +use FoF\Links\Extend\LinksOverride; |
| 45 | +use FoF\Links\LinkDefinition; |
| 46 | + |
| 47 | +return [ |
| 48 | + // Other extenders... |
| 49 | + |
| 50 | + (new LinksOverride()) |
| 51 | + ->addLinks([ |
| 52 | + LinkDefinition::make() |
| 53 | + ->withId(1) |
| 54 | + ->withTranslationKey('my-extension.link') |
| 55 | + ->withUrl('/my-page') |
| 56 | + ->withIcon('fas fa-link') |
| 57 | + ->withIsInternal(true) |
| 58 | + ]) |
| 59 | +]; |
| 60 | +``` |
| 61 | + |
| 62 | +#### Hierarchical Links |
| 63 | + |
| 64 | +You can create dropdown menus by adding child links: |
| 65 | + |
| 66 | +```php |
| 67 | +use FoF\Links\Extend\LinksOverride; |
| 68 | +use FoF\Links\LinkDefinition; |
| 69 | + |
| 70 | +$parent = LinkDefinition::make() |
| 71 | + ->withId(1) |
| 72 | + ->withTranslationKey('my-extension.parent') |
| 73 | + ->withUrl('/parent'); |
| 74 | + |
| 75 | +$child1 = LinkDefinition::make() |
| 76 | + ->withId(2) |
| 77 | + ->withTranslationKey('my-extension.child1') |
| 78 | + ->withUrl('/child1'); |
| 79 | + |
| 80 | +$child2 = LinkDefinition::make() |
| 81 | + ->withId(3) |
| 82 | + ->withTranslationKey('my-extension.child2') |
| 83 | + ->withUrl('/child2'); |
| 84 | + |
| 85 | +$parent->addChild($child1); |
| 86 | +$parent->addChild($child2); |
| 87 | + |
| 88 | +return [ |
| 89 | + // Other extenders... |
| 90 | + |
| 91 | + (new LinksOverride()) |
| 92 | + ->addLinks([$parent]) |
| 93 | +]; |
21 | 94 | ```
|
22 | 95 |
|
23 |
| -### TODO List by Sijad |
| 96 | +#### Using a Provider Class |
| 97 | + |
| 98 | +For more complex scenarios, you can use a provider class: |
| 99 | + |
| 100 | +```php |
| 101 | +use FoF\Links\Extend\LinksOverride; |
| 102 | +use FoF\Links\LinkDefinition; |
| 103 | + |
| 104 | +class MyLinksProvider |
| 105 | +{ |
| 106 | + public function __invoke() |
| 107 | + { |
| 108 | + return [ |
| 109 | + LinkDefinition::make() |
| 110 | + ->withId(1) |
| 111 | + ->withTranslationKey('my-extension.link') |
| 112 | + ->withUrl('/my-page') |
| 113 | + ]; |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +return [ |
| 118 | + // Other extenders... |
| 119 | + |
| 120 | + (new LinksOverride()) |
| 121 | + ->addLinks(MyLinksProvider::class) |
| 122 | +]; |
| 123 | +``` |
| 124 | + |
| 125 | +### LinkDefinition API |
| 126 | + |
| 127 | +The `LinkDefinition` class provides a fluent interface for defining links: |
24 | 128 |
|
25 |
| -- [ ] Add sub items |
26 |
| -- [ ] Add permission |
| 129 | +| Method | Description | |
| 130 | +|--------|-------------| |
| 131 | +| `withId(int $id)` | Set the link ID | |
| 132 | +| `withTranslationKey(string $key)` | Set the translation key for the link title | |
| 133 | +| `withUrl(string $url)` | Set the link URL | |
| 134 | +| `withIcon(string $icon)` | Set the link icon (FontAwesome class) | |
| 135 | +| `withIsInternal(bool $isInternal)` | Set whether the link is internal | |
| 136 | +| `withIsNewtab(bool $isNewtab)` | Set whether the link should open in a new tab | |
| 137 | +| `withUseRelme(bool $useRelme)` | Set whether to use rel="me" attribute | |
| 138 | +| `withGuestOnly(bool $guestOnly)` | Set whether the link is only visible to guests | |
| 139 | +| `withParentId(?int $parentId)` | Set the parent link ID | |
| 140 | +| `withPosition(int $position)` | Set the link position | |
| 141 | +| `addChild(LinkDefinition $child)` | Add a child link | |
27 | 142 |
|
28 |
| -### Links |
| 143 | +## Links |
29 | 144 |
|
30 | 145 | - [Packagist](https://packagist.org/packages/fof/links)
|
31 | 146 | - [GitHub](https://github.com/FriendsOfFlarum/links)
|
32 |
| -- [Sijad's Links](https://github.com/sijad/flarum-ext-links) |
| 147 | +- [Discuss](https://discuss.flarum.org/d/18335) |
33 | 148 |
|
34 | 149 | An extension by [FriendsOfFlarum](https://github.com/FriendsOfFlarum).
|
0 commit comments