2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-linkfield

Adds a Linkfield for gorriecoe/silverstripe-link

image

gorriecoe/silverstripe-linkfield

Adds a Linkfield for gorriecoe/silverstripe-link

  • Sunday, July 15, 2018
  • by gorriecoe
  • Repository
  • 1 Watchers
  • 0 Stars
  • 56 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 167 % Grown

The README.md

Silverstripe linkfield

Adds a Linkfield for gorriecoe/silverstripe-link, (*1)

Why is this redirected from gorriecoe/linkfield?

The original maintainer of this repository has passed away. No changes are required and your module will continue to work as intended. Please see this issue for more info., (*2)

Installation

Composer is the recommended way of installing SilverStripe modules., (*3)

composer require gorriecoe/silverstripe-linkfield

Requirements

  • gorriecoe/silverstripe-link ^1.0
  • silvershop/silverstripe-hasonefield 3.0.1. See Issue #11
  • symbiote/silverstripe-gridfieldextensions 3.1

Maintainers

Screenshots

Link list Detail edit form, (*4)

Usage

<?php

use gorriecoe\Link\Models\Link;
use gorriecoe\LinkField\LinkField;

class MyClass extends DataObject
{
    private static $has_one = [
        'Button' => Link::class
    ];

    private static $many_many = [
        'Buttons' => Link::class
    ];

    private static $many_many_extraFields = [
        'Buttons' => [
            'Sort' => 'Int' // Required for all many_many relationships
        ]
    ];

    /**
     * CMS Fields
     * @return FieldList
     */
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldsToTab(
            'Root.Main',
            [
                LinkField::create(
                    'Button',
                    'Button',
                    $this
                ),
                LinkField::create(
                    'Buttons',
                    'Buttons',
                    $this
                )
            ]
        );
        return $fields;
    }
}

Configuration

By default all link types allowed in the Link model are displayed in the edit form, but this can be configured per-field, allowing multiple configurations without requiring multiple otherwise-identical Link model subclasses., (*5)

The Title field can also be hidden, which is useful if you intend on using the URL for a link but not the user-configured Title., (*6)

This configuration can be passed into the constructor, or set later using the LinkField::setLinkConfig() method., (*7)

// Allow only SiteTree and URL types, implicitly allow displaying title field.
$linkConfig = [
    'types' => [
        'SiteTree',
        'URL',
    ],
];
LinkField::create('FieldName', 'Field Title', $this, $linkConfig);
// Allow only SiteTree and URL types.
$linkConfig = [
    'types' => [
        'SiteTree' => TRUE,
        'URL' => TRUE,
        'Email' => FALSE,
        'Phone' => FALSE,
        'File' => FALSE,
    ],
];
LinkField::create('FieldName', 'Field Title', $this, $linkConfig);

Hide the Title field

$linkConfig = [
    'title_display' => false,
];
LinkField::create('FieldName', 'Field Title', $this, $linkConfig);

Setting the configuration later

$linkField = LinkField::create('FieldName', 'Field Title', $this);
$linkConfig = [
    'types' => [
        'SiteTree',
        'URL',
    ],
];
$linkField->setLinkConfig($linkConfig);

Sort column

By default the LinkField assumes that the sort column is named Sort. If you want to use another field name such as SortOrder, you can specify it using the setSortColumn method like so:, (*8)

LinkField::create(
    'Buttons',
    'Buttons',
    $this
)->setSortColumn('SortOrder')

You can also globally define the sort column. In your config.yml add the following:, (*9)

gorriecoe\LinkField\LinkField:
  sort_column: 'SortOrder'

Belongs many many

We can also add a belongs_many_many relation to the Link class. In your config.yml add the following:, (*10)

gorriecoe\Link\Models\Link:
  belongs_many_many:
    MyCustomObject : MyCustomObject.Buttons

The Versions

15/07 2018

dev-master

9999999-dev http://github.com/gorriecoe/silverstripe-linkfield

Adds a Linkfield for gorriecoe/silverstripe-link

  Sources   Download

BSD-3-Clause

The Requires

 

by Gorrie Coe

cms silverstripe link modular