PHPackages                             bigfork/silverstripe-linkset - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bigfork/silverstripe-linkset

ActiveSilverstripe-vendormodule[Utility &amp; Helpers](/categories/utility)

bigfork/silverstripe-linkset
============================

Silverstripe module that allows for easy adding of links to the CMS

2.0.0(2y ago)04BSD-3-ClausePHPPHP &gt;=8.1

Since Dec 7Pushed 2y ago2 watchersCompare

[ Source](https://github.com/bigfork/silverstripe-linkset)[ Packagist](https://packagist.org/packages/bigfork/silverstripe-linkset)[ RSS](/packages/bigfork-silverstripe-linkset/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

SilverStripe Linkset
====================

[](#silverstripe-linkset)

Adds easy to implement link options to the CMS

Features
--------

[](#features)

- Choose from the following options: None, Page, File, URL
- Option to remove fields that don't apply to your implementation
- Can output link straight to template

Installation
------------

[](#installation)

```
$ composer require bigfork/silverstripe-linkset
```

How to use
----------

[](#how-to-use)

You will need to create a $has\_one relation on your data object

```
private static array $has_one = [
    'ButtonLink' => LinkSet::class,
];

```

Then add the LinksetField to your fieldlist

```
$fields->addFieldsToTab(
    'Root.Main',
    [
        ...otherFields,
        LinksetField::create($this, 'ButtonLink'),
        ...otherFields,
    ]
);

```

LinkSetField constructor accepts five params:

- DataObject $data - The object the relation is on $this
- string $name - Name of the field should match the relation key
- ?string $title (optional) - Title of the field, will set the heading above the fields
- array $fieldsToRemove (optional) - To remove Title from the list of fields pass in array for example \['Title'\]. Possible options to remove are:
    - Title
    - LinkType
    - LinkURL
    - LinkTarget
    - LinkedPageID
    - LinkedFile
- array $typesToRemove (optional) - Remove link types from the radio, to remove the option for None pass in array for example \['None'\]. Possible options to remove are:
    - None
    - Page
    - File
    - URL

With all the parameters your code may look like:

```
$fields->addFieldsToTab(
    'Root.Main',
    [
        ...otherFields,
        LinksetField::create($this, 'ButtonLink', 'Button link', ['Title'], ['None']),
        ...otherFields,
    ]
);

```

### Using in templates

[](#using-in-templates)

You can output the link in the template by calling the relation

```
{$ButtonLink.AddExtraClass('button button--primary')}

```

This will output a simple anchor tag with the all the fields that had been set on the LinkSetField group.

Custom anchors can be done by accessing the fields through the relation as normal

```
