Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Mar 28, 2019
0 parents commit 28800c0
Show file tree
Hide file tree
Showing 21 changed files with 775 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CRAFT ENVIRONMENT
.env.php
.env.sh
.env

# COMPOSER
/vendor

# BUILD FILES
/bower_components/*
/node_modules/*
/build/*
/yarn-error.log

# MISC FILES
.cache
.DS_Store
.idea
.project
.settings
*.esproj
*.sublime-workspace
*.sublime-project
*.tmproj
*.tmproject
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
config.codekit3
prepros-6.config
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Related Changelog

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.0 - 2019-03-25
### Added
- Initial release
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2019 reganlawton

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.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Related plugin for Craft CMS 3.x

A simple plugin that adds a widget within the Craft CP page sidebar, allowing you to quickly and easily access related entries.

![Screenshot](resources/img/modal.png)

## Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

## Installation

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

cd /path/to/project

2. Then tell Composer to load the plugin:

composer require wrav/related

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Related.

## Change Log

Changes can be viewed [here](https://github.com/wrav/related/blob/master/CHANGELOG.md)

## Support

Get in touch via email or by [creating a Github issue](/wrav/related/issues)

## Show your Support
This is licensed under the MIT license meaning it will always be free. If you like the plugin, please feel free to show your support and buy me a :beers:.

[![Beerpay](https://beerpay.io/wrav/SimpleSharing/badge.svg)](https://beerpay.io/wrav/related)
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "wrav/related",
"description": "A simple plugin that adds a widget within the Craft CP page sidebar, allowing you to quickly and easily access related entries.",
"type": "craft-plugin",
"version": "1.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"related"
],
"support": {
"docs": "https://github.com/wrav/related/blob/master/README.md",
"issues": "https://github.com/wrav/related/issues"
},
"license": "MIT",
"authors": [
{
"name": "reganlawton",
"homepage": "https://github.com/reganlawton"
}
],
"require": {
"craftcms/cms": "^3.0.0-RC1"
},
"autoload": {
"psr-4": {
"wrav\\related\\": "src/"
}
},
"extra": {
"name": "Related",
"handle": "related",
"hasCpSettings": true,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/wrav/related/master/CHANGELOG.md",
"components": {
"relatedService": "wrav\\related\\services\\RelatedService"
},
"class": "wrav\\related\\Related"
}
}
Binary file added resources/img/modal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/plugin-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/sidebar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 143 additions & 0 deletions src/Related.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php
/**
* Related plugin for Craft CMS 3.x
*
* A simple plugin that adds a widget within the Craft CP page sidebar, allowing you to quickly and easily access related entries.
*
* @link https://github.com/reganlawton
* @copyright Copyright (c) 2019 reganlawton
*/

namespace wrav\related;

use craft\events\RegisterCpNavItemsEvent;
use craft\events\RegisterTemplateRootsEvent;
use craft\events\RegisterUrlRulesEvent;
use craft\web\twig\variables\Cp;
use craft\web\UrlManager;
use craft\web\View;
use wrav\related\services\RelatedService as RelatedServiceService;
use wrav\related\models\Settings;

use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;

use yii\base\Event;

/**
* Craft plugins are very much like little applications in and of themselves. We’ve made
* it as simple as we can, but the training wheels are off. A little prior knowledge is
* going to be required to write a plugin.
*
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
*
* https://craftcms.com/docs/plugins/introduction
*
* @author reganlawton
* @package Related
* @since 1.0.0
*
* @property RelatedServiceService $relatedService
* @property Settings $settings
* @method Settings getSettings()
*/
class Related extends Plugin
{

// Static Properties
// =========================================================================

/**
* Static property that is an instance of this plugin class so that it can be accessed via
* Related::$plugin
*
* @var Related
*/
public static $plugin;

// Public Properties
// =========================================================================

/**
* To execute your plugin’s migrations, you’ll need to increase its schema version.
*
* @var string
*/
public $schemaVersion = '1.0.0';

// Public Methods
// =========================================================================

public function init()
{
parent::init();
self::$plugin = $this;

// Do something after we're installed
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
// We were just installed
}
}
);

Event::on(
View::class,
View::EVENT_END_PAGE,
function(Event $event) {
if (Craft::$app->getRequest()->getIsCpRequest()) {
$url = Craft::$app->assetManager->getPublishedUrl('@wrav/related/assetbundles/related/dist/js/Related.js', true);
echo "<script src='$url'></script>";

$url = Craft::$app->assetManager->getPublishedUrl('@wrav/related/assetbundles/related/dist/css/Related.css', true);
echo "<link rel='stylesheet' href='$url'>";
}
}
);

Event::on(View::class, View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS, function (RegisterTemplateRootsEvent $event) {
$event->roots['related'] = __DIR__ . '/templates';
});

Craft::info(
Craft::t(
'related',
'{name} plugin loaded',
['name' => $this->name]
),
__METHOD__
);
}

// Protected Methods
// =========================================================================

protected function createSettingsModel()
{
return new Settings();
}

protected function settingsHtml(): string
{
$sections = Craft::$app->sections->getAllSections('id');
$optionsSections = [];

foreach ($sections as $id => $section) {
$optionsSections[$section->id] = $section->name;
}

return Craft::$app->view->renderTemplate(
'related/settings',
[
'settings' => $this->getSettings(),
'optionsSections' => $optionsSections,
]
);
}
}
65 changes: 65 additions & 0 deletions src/assetbundles/related/RelatedAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Related plugin for Craft CMS 3.x
*
* A simple plugin that adds a widget within the Craft CP page sidebar, allowing you to quickly and easily access related entries.
*
* @link https://github.com/reganlawton
* @copyright Copyright (c) 2019 reganlawton
*/

namespace wrav\related\assetbundles\Related;

use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

/**
* RelatedAsset AssetBundle
*
* AssetBundle represents a collection of asset files, such as CSS, JS, images.
*
* Each asset bundle has a unique name that globally identifies it among all asset bundles used in an application.
* The name is the [fully qualified class name](http://php.net/manual/en/language.namespaces.rules.php)
* of the class representing it.
*
* An asset bundle can depend on other asset bundles. When registering an asset bundle
* with a view, all its dependent asset bundles will be automatically registered.
*
* http://www.yiiframework.com/doc-2.0/guide-structure-assets.html
*
* @author reganlawton
* @package Related
* @since 1.0.0
*/
class RelatedAsset extends AssetBundle
{
// Public Methods
// =========================================================================

/**
* Initializes the bundle.
*/
public function init()
{
// define the path that your publishable resources live
$this->sourcePath = "@wrav/related/assetbundles/related/dist";

// define the dependencies
$this->depends = [
CpAsset::class,
];

// define the relative path to CSS/JS files that should be registered with the page
// when this asset bundle is registered
$this->js = [
'js/Related.js',
];

$this->css = [
'css/Related.css',
];

parent::init();
}
}
30 changes: 30 additions & 0 deletions src/assetbundles/related/dist/css/Related.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Related plugin for Craft CMS
*
* Related CSS
*
* @author reganlawton
* @copyright Copyright (c) 2019 reganlawton
* @link https://github.com/reganlawton
* @package Related
* @since 1.0.0
*/

#nav #nav-related {
display: none;
}

#settings-allowedSections {
min-height: 100px;
min-width: 250px;
}

#related-modal {
margin-bottom: 0;
}

#related-modal header {
margin-bottom: 0;
padding-top: 15px;
padding-bottom: 15px;
}
Loading

0 comments on commit 28800c0

Please sign in to comment.