Skip to content

SilverStripe 4 custom form element and model for anchor, email, telephone, file, image, internal and external links

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
license.md
Notifications You must be signed in to change notification settings

evanshunt/Silverstripe-LinkItemField

 
 

Repository files navigation

SilverStripe 4 Link Item Field

Original Author: Andrew Mc Cormack

Features

Provides a has_one Link object with the following options:

  • Anchor link
  • Internal Link
  • External Link
  • Email
  • Telephone
  • File
  • Image
  • Link target (_blank etc)

Screen Shots

Installation

Add the following to your composer.json file and run /dev/buid?flush=all

{  
    "require": {  
        "evanshunt/silverstripe-linkitemfield": "4.0.*"
    }
}

Setup

The field references a has_one LinkItem relation on a DataObject. Make sure to include both the field and object namespaces in your class.

use evanshunt\LinkItemField\Forms\LinkItemField;
use evanshunt\LinkItemField\Model\LinkItem;
use SilverStripe\ORM\DataObject;

class MyObject extends DataObject 
{
    private static has_one = [
        'MyRelation' => LinkItem::class
    ];
}

The field can easily be added to an DataObject / extension through getCMSFields() / updateCMSFields() or similar.

$fields->addFieldToTab('Root.Main', LinkItemField::create('MyRelationID', 'My Relation Title'));

The relation will expose 3 properties in your template - Link, Title, and Target.

<% with MyRelation %>
<a href="$Link" target="$Target">$Title</a>
<% end_with %>

When calling Link the outputted URL will be formatted depending on the Link type

<a href="#{TheURL}">For Anchor</a>
<a href="{TheURL}">For Internal</a>
<a href="{TheURL}">For External</a>
<a href="mailto:{TheURL}">For Email</a>
<a href="tel:+{TheURL}">For Telephone</a>
<a href="{TheURL}">For File</a>
<a href="{TheURL}">For Image</a>

Todo

  • Add React

About

SilverStripe 4 custom form element and model for anchor, email, telephone, file, image, internal and external links

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
license.md

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 66.4%
  • JavaScript 18.5%
  • Scheme 13.8%
  • CSS 1.3%