Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aelvan committed Apr 28, 2020
0 parents commit 822c328
Show file tree
Hide file tree
Showing 33 changed files with 2,903 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.idea
/etc
/tests/coverage
/vendor
.DS_Store
composer.lock
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release Notes for LinkMate

## 1.0.0 - 2020-04-28
- Initial release
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Sebastian Lenz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# LinkMate plugin for Craft CMS

_Let's hook you up, mate!_

This is a link field for Craft CMS, forked from Sebastian Lenz' [Typed Link Field](https://github.com/sebastian-lenz/craft-linkfield).
It's made for Værsågod & friends - no support is given whatsoever. You should probably use the original instead.
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "vaersaagod/linkmate",
"description": "Let's hook you up, mate!",
"type": "craft-plugin",
"version": "1.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"linkmate",
"link"
],
"support": {
"docs": "https://github.com/vaersaagod/linkmate/blob/master/README.md",
"issues": "https://github.com/vaersaagod/linkmate/issues"
},
"license": "MIT",
"authors": [
{
"name": "Værsågod",
"homepage": "https://www.vaersaagod.no/"
}
],
"require": {
"craftcms/cms": "^3.0.0"
},
"autoload": {
"psr-4": {
"vaersaagod\\linkmate\\": "src/"
}
},
"extra": {
"name": "LinkMate",
"handle": "linkmate",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/vaersaagod/linkmate/master/CHANGELOG.md",
"components": {
},
"class": "vaersaagod\\linkmate\\LinkMate"
}
}
142 changes: 142 additions & 0 deletions src/LinkMate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace vaersaagod\linkmate;

use Craft;
use craft\base\Plugin;
use craft\elements\Asset;
use craft\elements\Category;
use craft\elements\Entry;
use craft\elements\User;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;
use vaersaagod\linkmate\events\LinkTypeEvent;
use vaersaagod\linkmate\fields\LinkField;
use vaersaagod\linkmate\models\ElementLinkType;
use vaersaagod\linkmate\models\InputLinkType;
use vaersaagod\linkmate\models\SiteLinkType;
use vaersaagod\linkmate\models\LinkTypeInterface;
use yii\base\Event;

/**
* Class LinkMate
* @package linkmate
*/
class LinkMate extends Plugin
{
/**
* @var LinkTypeInterface[]
*/
private $linkTypes;

/**
* @event events\LinkTypeEvent
*/
const EVENT_REGISTER_LINK_TYPES = 'registerLinkTypes';


/**
* @return void
*/
public function init()
{
parent::init();

Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
[$this, 'onRegisterFieldTypes']
);
}

/**
* @return LinkTypeInterface[]
*/
public function getLinkTypes()
{
if (!isset($this->linkTypes)) {
$event = new LinkTypeEvent();
$event->linkTypes = $this->createDefaultLinkTypes();
$this->trigger(self::EVENT_REGISTER_LINK_TYPES, $event);

$this->linkTypes = $event->linkTypes;
}

return $this->linkTypes;
}

/**
* @return LinkTypeInterface[]
*/
private function createDefaultLinkTypes()
{
$result = [
'url' => new InputLinkType([
'displayName' => 'Url',
'displayGroup' => 'Input fields',
'inputType' => 'url'
]),
'custom' => new InputLinkType([
'displayName' => 'Custom',
'displayGroup' => 'Input fields',
'inputType' => 'text'
]),
'email' => new InputLinkType([
'displayName' => 'Mail',
'displayGroup' => 'Input fields',
'inputType' => 'email'
]),
'tel' => new InputLinkType([
'displayName' => 'Telephone',
'displayGroup' => 'Input fields',
'inputType' => 'tel'
]),
'asset' => new ElementLinkType([
'displayGroup' => 'Craft CMS',
'elementType' => Asset::class,
]),
'category' => new ElementLinkType([
'displayGroup' => 'Craft CMS',
'elementType' => Category::class
]),
'entry' => new ElementLinkType([
'displayGroup' => 'Craft CMS',
'elementType' => Entry::class
]),
'user' => new ElementLinkType([
'displayGroup' => 'Craft CMS',
'elementType' => User::class
]),
'site' => new SiteLinkType([
'displayGroup' => 'Craft CMS',
'displayName' => 'Site',
]),
];

// Add craft commerce elements
if (class_exists('craft\commerce\elements\Product')) {
$result['craftCommerce-product'] = new ElementLinkType([
'displayGroup' => 'Craft commerce',
'elementType' => 'craft\commerce\elements\Product'
]);
}

// Add solspace calendar elements
if (class_exists('Solspace\Calendar\Elements\Event')) {
$result['solspaceCalendar-event'] = new ElementLinkType([
'displayGroup' => 'Solspace calendar',
'elementType' => 'Solspace\Calendar\Elements\Event'
]);
}

return $result;
}

/**
* @param RegisterComponentTypesEvent $event
*/
public function onRegisterFieldTypes(RegisterComponentTypesEvent $event)
{
$event->types[] = LinkField::class;
}
}
17 changes: 17 additions & 0 deletions src/events/LinkTypeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace vaersaagod\linkmate\events;

use vaersaagod\linkmate\models\LinkTypeInterface;
use yii\base\Event;

/**
* LinkTypeEvent class.
*/
class LinkTypeEvent extends Event
{
/**
* @var LinkTypeInterface[]
*/
public $linkTypes;
}
Loading

0 comments on commit 822c328

Please sign in to comment.