2017 © Pedro Peláez
 

craft-plugin linkit

One link field to rule them all.

image

fruitstudios/linkit

One link field to rule them all.

  • Tuesday, May 29, 2018
  • by fruitstudios
  • Repository
  • 3 Watchers
  • 11 Stars
  • 3,174 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 13 Open issues
  • 17 Versions
  • 122 % Grown

The README.md

Linkit, (*1)

Linkit plugin for Craft 3

One link field to rule them all... This plugin adds a custom fieldtype which enables support for linking to email addresses, telephone numbers, URL's and Craft element types., (*2)

New for Craft 3

  • Link to Users and specify a profile url rule
  • New social links
  • Completely rewritten for Craft 3
  • Easily extendable, create your own custom link types

Requirements

This plugin requires Craft CMS 3.1.2 or later., (*3)

Installation

Plugin Store

Log into your control panel, hit up the 'Plugin Store', search for this plugin and install., (*4)

Composer

Open terminal, go to your Craft project folder and use composer to load this plugin. Once loaded you can install via the Craft Control Panel, go to Settings → Plugins, locate the plugin and hit “Install”., (*5)

cd /path/to/project
composer require fruitstudios/linkit

Updating from Craft 2

Version 1.0.7 includes migration scripts for Craft 2, just install or update via the plugin store and Linkit will handle everything else., (*6)

Backup before installing / updating and note that only native link types (email, url, phone, entry, asset, category and product) can be updated. Settings for custom link types will be overwritten and although content will remain in place, it may cause issues unexpected issues with your templates., (*7)

For help on migrating custom link types see the docs and if you run into issues during the update just open a GitHub issue., (*8)

Configuring Linkit

Once installed, create a new field and choose the Linkit fieldtype. You'll then have the option of configuring what link type will be available to this field., (*9)

The following link types are available:, (*10)

Basic, (*11)

  1. Email Address
  2. Telephone Number
  3. URL

Social, (*12)

  1. Twitter
  2. Facebook
  3. Instagram
  4. Linked In

Elements, (*13)

  1. Entry
  2. Category
  3. User
  4. Asset
  5. Product

Each link type has additional option to allow further customisation. For example, the User link type allows you to set a default path..., (*14)

Linkit, (*15)

You can also customise the dropdown labels that appear on the field., (*16)

Linkit, (*17)

Using Linkit

Template Variables (Basic Use), (*18)

Output the custom field to get a ready built html link..., (*19)

{{ entry.linkItField | raw }}

or in full..., (*20)

{{ entry.linkItField.link }} or {{ entry.linkItField.getLink() }}

Create a customised html link..., (*21)

{% set attributes = {
    title: 'Custom Title',
    target: '_self',
    class: 'my-class',
    "data-custom": 'custom-data-attribute'
} %}
{{ entry.linkItField.link(attributes) }}

Template Variables (Advanced Use), (*22)

Each Linkit field returns a Linkit model with the following tags..., (*23)

{{ entry.linkItField.url }} or {{ entry.linkItField.getUrl() }}
{{ entry.linkItField.text }} or {{ entry.linkItField.getText() }}

{{ entry.linkItField.type }}
{{ entry.linkItField.typeHandle }}

{{ entry.linkItField.hasElement }}
{{ entry.linkItField.available }} or {{ entry.linkItField.isAvailable() }}

{{ entry.linkItField.target }}
{{ entry.linkItField.targetString }}
{{ entry.linkItField.linkAttributes }}
{{ entry.linkItField.customText }}

If your link is an element link you also have access to the following..., (*24)

{{ entry.linkItField.element }} or {{ entry.linkItField.getElement() }}

or via the specific element types..., (*25)

{{ entry.linkItField.entry }} or {{ entry.linkItField.getEntry() }}
{{ entry.linkItField.asset }} or {{ entry.linkItField.getAsset() }}
{{ entry.linkItField.category }} or {{ entry.linkItField.getCategory() }}
{{ entry.linkItField.user }} or {{ entry.linkItField.getUser() }}
{{ entry.linkItField.product }} or {{ entry.linkItField.getProduct() }}

Example Usage, (*26)

If you have created a field called 'linkItField' with a User link type like so..., (*27)

Linkit, (*28)

{{ entry.linkItField.link }}

would output <a href="/profile/USERNAME">Visit Profile</a> which is the default user path that is created in the setting and the user would be available at..., (*29)

{{ entry.linkItField.user }}

A Note On Element Status, (*30)

To match first party element fieldtypes, Linkit now links to and allows users to select disabled elements when using element link types, we have added a new method to allow you to determine if a link is available (enabled) for the current site, as such the following will return a boolean value, (*31)

{{ entry.linkItField.avialable }} or {{ entry.linkItField.isAvialable() }}

you can use this to work out if you should display a link, (*32)

{% if entry.linkItField.available %}
    {{ entry.linkItField.link | raw }}
{% endif %}

You can still access the linked element and any other attributes should you need to access a disabled element, (*33)

{# So long as it exists the link is always returned irrelevant of status #}
{% set element = entry.linkItField.element %}
{% if element %}
    {{ element.title }} - {{ element.url }}
{% endif %}

You can easily create your own link types,, (*34)

Full documenation is coming soon, for now, take a look at the models folder. Each link type is a seperate model, just extend Link or ElementLink, depending on your needs, and everything will be set up for you., (*35)

Hook up the requirements and register custom link types in your plugin (or modules) init()..., (*36)

<?php

...

use fruitstudios\linkit\Linkit;
use fruitstudios\linkit\events\RegisterLinkTypesEvent;
use fruitstudios\linkit\services\LinkitService;

use developer\plugin\models\CustomType;

...

public function init()
{
    parent::init();

    Event::on(LinkitService::class, LinkitService::EVENT_REGISTER_LINKIT_FIELD_TYPES, function (RegisterLinkTypesEvent $event) {
        $event->types[] = new CustomType();
    });

}

If you think they are super useful and you agree we can look to add them to the core plugin for everyone to use., (*37)

Brought to you by FRUIT, (*38)

The Versions

29/05 2018

dev-develop

dev-develop

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

02/05 2018

dev-feature/disabled-bug

dev-feature/disabled-bug

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

24/04 2018

dev-master

9999999-dev

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

24/04 2018

v1.0.8

1.0.8.0

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

24/04 2018

v1.0.7.1

1.0.7.1

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

24/04 2018

1.0.7

1.0.7.0

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

23/04 2018

dev-feature/migration

dev-feature/migration

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

16/04 2018

v1.0.6

1.0.6.0

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

31/03 2018

v1.0.5

1.0.5.0

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

30/03 2018

v1.0.4

1.0.4.0

One link field to rule them all.

  Sources   Download

proprietary

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

27/03 2018

1.0.3

1.0.3.0

One link field to rule them all.

  Sources   Download

Craft

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

27/03 2018

1.0.2

1.0.2.0

One link field to rule them all.

  Sources   Download

Craft

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

27/03 2018

1.0.0

1.0.0.0

One link field to rule them all.

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

13/03 2018

1.0.0-beta.4

1.0.0.0-beta4

One link field to rule them all.

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

13/03 2018

v1.0.0-beta.3

1.0.0.0-beta3

One link field to rule them all.

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

13/03 2018

v1.0.0-beta.2

1.0.0.0-beta2

One link field to rule them all.

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios

13/03 2018

v1.0.0-beta.1

1.0.0.0-beta1

One link field to rule them all.

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft link it linkit fruit studios