Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hibberd committed Aug 23, 2018
1 parent 48a2248 commit 664ecd7
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 39 deletions.
19 changes: 7 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
# Linkit Changelog
> One link field to rule them all, built for [Craft 3](http://craftcms.com)
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## 1.1.0 - 2018-08-23

### Changed

* Changed - Improved Linked In link validation
* Changed - Improved url link validation
* Changed - Element link types now allowed to select disabled elements to match the first party Craft element fieldtypes
* Changed - Updated element select to match first party fields
* Changed - Improved support for multisite setup

### Added

* Added `isElementLink()` check to link models to quickly determine if the link is an element type
* Added `isAvailable()` check to link models to quickly determine if the link is an element type
* Added `hasElement()` method to link models to quickly determine if the link is an element link type
* Added `isAvailable()` method to link models to quickly determine if a link is available
* Added setting to override the default placeholder text for basic and social link types
* Added `getTableAttributeHtmlLink()` Linkit fields are now previewable table colums in table view
* Added `getTableAttributeHtmlLink()` method, Linkit fields are now previewable table colums in table view
* Added status indicators to preview to determine if a link is available
* Added plugin setting to configure how you handle disabled element types

### Fixed

* Fixed issue with the Craft 2 normailize function when a type is not specified
* Fixed cp translation bug on element link types when using multiple sites


## 1.1.0 - 2018-04-24

* Fixed an issue with the Craft 2 > Craft 3 migration script related to an undefined type index

## 1.0.8 - 2018-04-24

Expand Down
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ Each Linkit field returns a Linkit model with the following tags...

{{ 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.avialable }} or {{ entry.linkItField.isAvialable() }}

{{ entry.linkItField.target }}
{{ entry.linkItField.targetString }}
{{ entry.linkItField.linkAttributes }}
Expand All @@ -114,18 +118,40 @@ or via the specific element types...
{{ 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**

If you have created a field called 'link' with a User link type like so...
If you have created a field called 'linkItField' with a User link type like so...

<p align="left"><img width="450px" src="resources/img/member-select.png" alt="Linkit"></a></p>

{{ entry.link.getLink }}
{{ 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...

{{ entry.link.user }}
{{ entry.linkItField.user }}


**A Note On Element Status**

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

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

you can use this to work out if you should display a link

{% 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

{# 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 %}

## Custom Link Types

Expand Down Expand Up @@ -159,13 +185,4 @@ Hook up the requirements and register custom link types in your plugin (or modul

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

## Roadmap

* [x] Craft 2 migration script
* [x] Add Product link type
* [ ] Enable third party field type registration
* [ ] Add docs for creating third party field types
* [x] Restructure linkit field settings template (it's a bit busy we know!)
* [ ] Improve link model docs

Brought to you by [FRUIT](https://fruitstudios.co.uk)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fruitstudios/linkit",
"description": "One link field to rule them all.",
"type": "craft-plugin",
"version": "1.0.9",
"version": "1.1.0",
"keywords": [
"craft",
"cms",
Expand Down
8 changes: 7 additions & 1 deletion src/base/ElementLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static function inputTemplatePath(): string
// Public Methods
// =========================================================================

public function __toString(): string
{
return $this->isAvailable() ? $this->getLink([], false) : '';
}

public function defaultSelectionLabel(): string
{
return Craft::t('linkit', 'Select') . ' ' . $this->defaultLabel();
Expand Down Expand Up @@ -84,7 +89,8 @@ public function getElement()

public function isAvailable(): bool
{
return $this->getElement()->enabled ?? false;
$element = $this->getElement();
return $element && $element->enabled && $element->enabledForSite;
}

public function rules()
Expand Down
2 changes: 1 addition & 1 deletion src/base/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function elementType()
return null;
}

public static function isElementLink(): bool
public static function hasElement(): bool
{
return (static::elementType() ?? false) ? true : false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function settingsTemplatePath(): string;
public static function inputTemplatePath(): string;
public static function hasSettings(): bool;
public static function elementType();
public static function isElementLink(): bool;
public static function hasElement(): bool;

// Public Methods
// =========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function _migrateFieldSettings($oldSettings)
$newSettings['allowTarget'] = $oldSettings['allowTarget'] ?? 0;
$newSettings['allowCustomText'] = $oldSettings['allowCustomText'] ?? 0;

if($oldSettings['types'])
if($oldSettings['types'] ?? false)
{
foreach ($oldSettings['types'] as $oldType)
{
Expand Down
2 changes: 1 addition & 1 deletion src/models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getAsset()
{
if(is_null($this->_asset))
{
$this->_asset = Craft::$app->getAssets()->getAssetById((int) $this->value, static::elementType(), $this->ownerElement->siteId ?? null);
$this->_asset = Craft::$app->getAssets()->getAssetById((int) $this->value, $this->ownerElement->siteId ?? null);
}
return $this->_asset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getCategory()
{
if(is_null($this->_category))
{
$this->_category = Craft::$app->getCategories()->getCategoryById((int) $this->value, static::elementType(), $this->ownerElement->siteId ?? null);
$this->_category = Craft::$app->getCategories()->getCategoryById((int) $this->value, $this->ownerElement->siteId ?? null);
}
return $this->_category;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getEntry()
{
if(is_null($this->_entry))
{
$this->_entry = Craft::$app->getEntries()->getEntryById((int) $this->value, static::elementType(), $this->ownerElement->siteId ?? null);
$this->_entry = Craft::$app->getEntries()->getEntryById((int) $this->value, $this->ownerElement->siteId ?? null);
}
return $this->_entry;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getProduct()
{
if(is_null($this->_product))
{
$this->_product = CraftCommercePlugin::getInstance()->getProducts()->getProductById((int) $this->value, static::elementType(), $this->ownerElement->siteId ?? null);
$this->_product = CraftCommercePlugin::getInstance()->getProducts()->getProductById((int) $this->value, $this->ownerElement->siteId ?? null);
}
return $this->_product;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getUser()
{
if(is_null($this->_user))
{
$this->_user = Craft::$app->getUsers()->getUserById((int) $this->value, static::elementType(), $this->ownerElement->siteId ?? null);
$this->_user = Craft::$app->getUsers()->getUserById((int) $this->value, $this->ownerElement->siteId ?? null);
}
return $this->_user;
}
Expand Down
19 changes: 14 additions & 5 deletions src/templates/fields/_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
<div class="linkit--fieldSettings">

{# TODO: Feels a bit too loose to select the first item. Rework to include reordering #}
{# {{ forms.textField({
{#
{{ forms.textField({
label: "Select Link Text"|t('linkit'),
instructions: "Set the first item to be displayed in the link select."|t('linkit'),
name: 'selectLinkText',
placeholder: field.selectLinkText,
placeholder: field.defaultSelectLinkText,
errors: field.getErrors('selectLinkText'),
}) }} #}
}) }}
#}

{{ forms.lightSwitchField({
id: 'enableAllTypes',
label: 'Enable all link types',
instructions: 'Switch on all link types for this field',
on: false,
}) }}

{{ forms.field({
errors: field.getErrors('enabledLinkTypes'),
Expand All @@ -30,18 +39,18 @@
{% for linkType in linksTypesInGroup %}

{% set name = 'types['~linkType.type~']' %}
{% set isEnabled = field.types[linkType.type].enabled ?? false %}
{% set isAvailable = field.types[linkType.type].enabled ?? false %}

{{ forms.lightSwitchField({
id: linkType.type|id,
name: name~'[enabled]',
label: linkType.defaultLabel(),
toggle: linkType.hasSettings ? '#' ~ linkType.type|id ~ '-settings' : null,
on: isEnabled,
on: isAvailable,
}) }}

{% if linkType.hasSettings %}
<div id="{{ linkType.type|id }}-settings" class="{{ not isEnabled ? 'hidden' }}">
<div id="{{ linkType.type|id }}-settings" class="{{ not isAvailable ? 'hidden' }}">
{% namespace name %}
{{ linkType.getSettingsHtml()|raw }}
{% endnamespace %}
Expand Down

0 comments on commit 664ecd7

Please sign in to comment.