Skip to content

Commit

Permalink
Update settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean committed Mar 27, 2018
1 parent 43222b7 commit 760a547
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 25 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ 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/).

## 1.0.3 - 2018-03-27

* Updated settings page to group link types.
* Enabling link types is now done with lightswitches instead of checkboxes

## 1.0.2 - 2018-03-27

Updated icon and license
* Updated icon and license.


## 1.0.0 - 2018-03-27
Expand Down
4 changes: 2 additions & 2 deletions 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.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand Down Expand Up @@ -43,7 +43,7 @@
"extra": {
"name": "Linkit",
"handle": "linkit",
"schemaVersion": "1.0.2",
"schemaVersion": "1.0.3",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl":
Expand Down
5 changes: 5 additions & 0 deletions src/base/ElementLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ abstract class ElementLink extends Link
// Static
// =========================================================================

public static function group(): string
{
return Craft::t('linkit', 'Element');
}

public static function elementType()
{
return Element::class;
Expand Down
10 changes: 10 additions & 0 deletions src/base/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ abstract class Link extends SavableComponent implements LinkInterface
// Static
// =========================================================================

public static function group(): string
{
return Craft::t('linkit', 'Basic');
}

public static function groupTitle(): string
{
return static::group().' '.Craft::t('linkit', 'Links');
}

public static function defaultLabel(): string
{
$classNameParts = explode('\\', static::class);
Expand Down
2 changes: 2 additions & 0 deletions src/base/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface LinkInterface extends SavableComponentInterface
// Static
// =========================================================================

public static function group(): string;
public static function groupTitle(): string;
public static function defaultLabel(): string;
public static function defaultPlaceholder(): string;
public static function settingsTemplatePath(): string;
Expand Down
5 changes: 5 additions & 0 deletions src/models/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Facebook extends Link
// Static
// =========================================================================

public static function group(): string
{
return Craft::t('linkit', 'Social');
}

public static function defaultLabel(): string
{
return Craft::t('linkit', 'Facebook');
Expand Down
5 changes: 5 additions & 0 deletions src/models/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Instagram extends Link
// Static
// =========================================================================

public static function group(): string
{
return Craft::t('linkit', 'Social');
}

public static function defaultLabel(): string
{
return Craft::t('linkit', 'Instagram');
Expand Down
5 changes: 5 additions & 0 deletions src/models/LinkedIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class LinkedIn extends Link
// Static
// =========================================================================

public static function group(): string
{
return Craft::t('linkit', 'Social');
}

public static function defaultLabel(): string
{
return Craft::t('linkit', 'Linked In');
Expand Down
5 changes: 5 additions & 0 deletions src/models/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Twitter extends Link
// Static
// =========================================================================

public static function group(): string
{
return Craft::t('linkit', 'Social');
}

public static function defaultLabel(): string
{
return Craft::t('linkit', 'Twitter');
Expand Down
54 changes: 32 additions & 22 deletions src/templates/fields/_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,50 @@
}) }} #}

{{ forms.field({
label: "Link Types"|t('linkit'),
instructions: "Select and configure the link types you would like to make available"|t('linkit'),
errors: field.getErrors('enabledLinkTypes'),
first: true
}) }}

{% for linkType in field.availableLinkTypes %}
{% set availableLinkFieldsByGroup = field.availableLinkTypes|group('groupTitle') %}

{% set name = 'types['~linkType.type~']' %}
{% set isEnabled = field.types[linkType.type].enabled ?? false %}
{% for groupTitle, linksTypesInGroup in availableLinkFieldsByGroup %}

{{ forms.checkboxField({
id: linkType.type|id,
name: name~'[enabled]',
label: linkType.defaultLabel(),
value: true,
toggle: linkType.hasSettings ? '#' ~ linkType.type|id ~ '-settings' : null,
checked: isEnabled,
{{ forms.field({
label: groupTitle,
instructions: "Select and configure the {groupTitle} you would like to make available."|t('linkit', {groupTitle: groupTitle|lower}),
first: true
}) }}

{% if linkType.hasSettings %}
<div id="{{ linkType.type|id }}-settings" class="{{ not isEnabled ? 'hidden' }}">
{% namespace name %}
{{ linkType.getSettingsHtml()|raw }}
{% endnamespace %}
</div>
{% endif %}
{% for linkType in linksTypesInGroup %}

{% endfor %}
{% set name = 'types['~linkType.type~']' %}
{% set isEnabled = 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,
}) }}

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

<hr>
{% endfor %}

<hr>

{% endfor %}

{{ forms.textField({
label: "Default Link Text"|t('linkit'),
instructions: "Set a default text value for this link, can be overridden if custom link text option is selected."|t('linkit'),
instructions: "Set a default text value for this link, can be overridden if 'Allow custom link text' is selected."|t('linkit'),
name: 'defaultText',
value: field.defaultText,
errors: field.getErrors('defaultText'),
Expand Down

0 comments on commit 760a547

Please sign in to comment.