Dedicated Authors admin panel, optimised use of event hooks, updated documentation
This commit is contained in:
parent
ea84035fee
commit
ba03692b2f
11 changed files with 220 additions and 167 deletions
11
README.md
11
README.md
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
The **Aura Authors** Plugin for [Grav CMS](https://github.com/getgrav/grav) enables you to store author bios in a centrally managed repository and have them displayed across various pages of your site.
|
The **Aura Authors** Plugin for [Grav CMS](https://github.com/getgrav/grav) enables you to store author bios in a centrally managed repository and have them displayed across various pages of your site.
|
||||||
|
|
||||||
![Aura Authors Plugin for Grav - Demo](assets/demo-min.png)
|
![Aura Authors Plugin for Grav - Demo](assets/demo.jpg)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ The **Aura Authors** Plugin for [Grav CMS](https://github.com/getgrav/grav) enab
|
||||||
* Central repository ensures that a single change to an author's bio will automatically update it across multiple pages
|
* Central repository ensures that a single change to an author's bio will automatically update it across multiple pages
|
||||||
* Optionally include author's image and links to social media accounts such as Twitter, LinkedIn etc.
|
* Optionally include author's image and links to social media accounts such as Twitter, LinkedIn etc.
|
||||||
* Use the included mobile and desktop responsive styling or provide your own
|
* Use the included mobile and desktop responsive styling or provide your own
|
||||||
|
* Supports `author` taxonomy type for page collections based on author's individual taxonomy label
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ It is recommended to install Aura Authors directly through the Admin Plugin by b
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
* Enter author details via the Admin Plugin by browsing to `Plugins` > `Aura Authors` and selecting `Add Item`.
|
* Enter author details via the `Authors` section of the Admin Plugin.
|
||||||
|
|
||||||
* Copy the following code snippet to the relevant Twig template within your theme, at the place where you would like the author bio to be displayed.
|
* Copy the following code snippet to the relevant Twig template within your theme, at the place where you would like the author bio to be displayed.
|
||||||
|
|
||||||
|
@ -25,13 +26,13 @@ It is recommended to install Aura Authors directly through the Admin Plugin by b
|
||||||
{% include 'partials/author-bio.html.twig' ignore missing %}
|
{% include 'partials/author-bio.html.twig' ignore missing %}
|
||||||
```
|
```
|
||||||
|
|
||||||
* The above will output the relevant author bio on all pages of that type, once an author is defined at the page level (see Usage below). Alternatively if you do not have access or do not wish to edit the theme you can include the code snippet directly within a page via the page editor. For this option to work you will need ensure Twig processing is enabled either at the page level (`Page Editor` > `Advanced` > `Overrides` > `Process`) or the site level (`Configuration` > `System` > `Content` > `Process`).
|
* Once an author is defined at the page level (see Usage below) the relevant author bio will now be displayed on that page (provided it uses the template updated above). Alternatively if you do not have access or do not wish to edit the theme you can include the code snippet directly within a page via the page editor. For this option to work you will need ensure Twig processing is enabled either at the page level (`Page Editor` > `Advanced` > `Overrides` > `Process`) or the site level (`Configuration` > `System` > `Content` > `Process`).
|
||||||
|
|
||||||
* Optionally customise the layout of the author bio by copying the included templates/partials/author-bio.html.twig into the same location under your theme and editing it. Default styling can be disabled via the Plugin configuration panel if you wish to provide your own.
|
* Optionally customise the layout of the author bio by copying the included file `templates/partials/author-bio.html.twig` into the same location under your theme and editing it. Default styling can be disabled via the Plugin configuration panel if you wish to provide your own.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Authors can be selected per page via the page editor, on the `Aura` tab. The list of authors will be automatically populated with author records you create via the Plugins panel.
|
Authors can be selected per page via the page editor, on the `Aura` tab. The list of authors will be automatically populated with author records you create via the `Authors` menu item.
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
|
1
admin/assets/admin.min.js
vendored
Normal file
1
admin/assets/admin.min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$('<i class="fa fa-check"></i> ').prependTo('#authorSave');
|
1
admin/assets/style.min.css
vendored
Normal file
1
admin/assets/style.min.css
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#authorSave{margin-left: 1.5rem;}#authorSave:active{margin:1px 0 -1px 1.5rem;}
|
90
admin/pages/authors.md
Normal file
90
admin/pages/authors.md
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
---
|
||||||
|
title: Authors
|
||||||
|
|
||||||
|
access:
|
||||||
|
admin.authors: true
|
||||||
|
admin.super: true
|
||||||
|
form:
|
||||||
|
name: authors
|
||||||
|
action: '/authors'
|
||||||
|
template: authors
|
||||||
|
refresh_prevention: true
|
||||||
|
|
||||||
|
fields:
|
||||||
|
authors:
|
||||||
|
type: list
|
||||||
|
display_label: false
|
||||||
|
collapsed: true
|
||||||
|
style: vertical
|
||||||
|
help: "Add or edit author details"
|
||||||
|
data-default@: ['\Grav\Plugin\AuraAuthorsPlugin::getAuthors']
|
||||||
|
|
||||||
|
fields:
|
||||||
|
.name:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: Name
|
||||||
|
validate:
|
||||||
|
required: true
|
||||||
|
.label:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: Taxonomy Label
|
||||||
|
validate:
|
||||||
|
pattern: "[a-z][a-z0-9_\-]+"
|
||||||
|
message: "Use all lowercase letters and replace spaces with hyphens."
|
||||||
|
required: true
|
||||||
|
.image:
|
||||||
|
type: file
|
||||||
|
size: large
|
||||||
|
label: Image
|
||||||
|
multiple: false
|
||||||
|
destination: 'user/images'
|
||||||
|
accept:
|
||||||
|
- image/*
|
||||||
|
.description:
|
||||||
|
type: textarea
|
||||||
|
size: long
|
||||||
|
label: Description
|
||||||
|
.person-facebook-url:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: Facebook URL
|
||||||
|
placeholder: 'https://www.facebook.com/username'
|
||||||
|
.person-twitter-user:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: Twitter Username
|
||||||
|
placeholder: 'username'
|
||||||
|
.person-instagram-url:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: Instagram URL
|
||||||
|
placeholder: 'https://www.instagram.com/username'
|
||||||
|
.person-linkedin-url:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: LinkedIn URL
|
||||||
|
placeholder: 'https://www.linkedin.com/in/name'
|
||||||
|
.person-pinterest-url:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: Pinterest URL
|
||||||
|
placeholder: 'https://www.pinterest.com/user/username'
|
||||||
|
.person-youtube-url:
|
||||||
|
type: text
|
||||||
|
size: large
|
||||||
|
label: YouTube URL
|
||||||
|
placeholder: 'https://www.youtube.com/username'
|
||||||
|
.person-website-url:
|
||||||
|
type: text
|
||||||
|
label: Website URL
|
||||||
|
placeholder: 'https://www.example.com'
|
||||||
|
|
||||||
|
buttons:
|
||||||
|
submit:
|
||||||
|
type: submit
|
||||||
|
value: ' Save'
|
||||||
|
classes: button
|
||||||
|
id: authorSave
|
||||||
|
---
|
11
admin/templates/authors.html.twig
Normal file
11
admin/templates/authors.html.twig
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends 'partials/base.html.twig' %}
|
||||||
|
|
||||||
|
{% block titlebar %}
|
||||||
|
<h1><i class="fa fa-fw fa-users"></i> Authors</h1>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include "forms/form.html.twig" %}
|
||||||
|
{% do assets.addCss('user://plugins/aura-authors/admin/assets/style.min.css') %}
|
||||||
|
{% do assets.addInlineJs('$("<i class=\"fa fa-check\"></i> ").prependTo(\"#authorSave\");') %}
|
||||||
|
{% endblock %}
|
Binary file not shown.
Before Width: | Height: | Size: 60 KiB |
BIN
assets/demo.jpg
Normal file
BIN
assets/demo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
149
aura-authors.php
149
aura-authors.php
|
@ -1,9 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Grav\Plugin;
|
namespace Grav\Plugin;
|
||||||
|
|
||||||
use Grav\Common\Data;
|
|
||||||
use Grav\Common\Plugin;
|
use Grav\Common\Plugin;
|
||||||
|
use Grav\Common\Page\Page;
|
||||||
use RocketTheme\Toolbox\Event\Event;
|
use RocketTheme\Toolbox\Event\Event;
|
||||||
|
use RocketTheme\Toolbox\File\File;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AuraAuthorsPlugin
|
* Class AuraAuthorsPlugin
|
||||||
|
@ -11,112 +13,101 @@ use RocketTheme\Toolbox\Event\Event;
|
||||||
*/
|
*/
|
||||||
class AuraAuthorsPlugin extends Plugin
|
class AuraAuthorsPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
protected static $authorsFile = DATA_DIR . 'authors/authors.yaml';
|
||||||
|
protected $route = 'authors';
|
||||||
|
static protected $authorList = [];
|
||||||
|
|
||||||
/** @var array */
|
public static function getAuthors()
|
||||||
static protected $authorList = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getSubscribedEvents()
|
|
||||||
{
|
{
|
||||||
return [
|
$fileInstance = File::instance(self::$authorsFile);
|
||||||
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
if (!$fileInstance->content()) {
|
||||||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
return;
|
||||||
'onPageInitialized' => ['onPageInitialized', 0],
|
}
|
||||||
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
|
return Yaml::parse($fileInstance->content());
|
||||||
'onBlueprintCreated' => ['onBlueprintCreated', 0],
|
}
|
||||||
];
|
|
||||||
|
public static function saveAuthors(array $authors)
|
||||||
|
{
|
||||||
|
$file = File::instance(self::$authorsFile);
|
||||||
|
$file->save(Yaml::dump($authors));
|
||||||
|
echo json_encode('Saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize configuration
|
|
||||||
*/
|
|
||||||
public function onPluginsInitialized()
|
public function onPluginsInitialized()
|
||||||
{
|
{
|
||||||
|
// Admin only events
|
||||||
// Add author to site taxonomies
|
if ($this->isAdmin()) {
|
||||||
$taxonomies = $this->config->get('site.taxonomies');
|
$this->enable([
|
||||||
$taxonomies[] = 'author';
|
'onAdminMenu' => ['onAdminMenu', 0],
|
||||||
$this->config->set('site.taxonomies', $taxonomies);
|
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
||||||
|
'onPageInitialized' => ['onPageInitialized', 0],
|
||||||
// Populate author list for use in blueprint
|
'onGetPageBlueprints' => ['onGetPageBlueprints', 0],
|
||||||
$authors = $this->grav['config']->get('plugins.aura-authors.authors');
|
'onAdminSave' => ['onAdminSave', 0],
|
||||||
if ($authors) {
|
]);
|
||||||
foreach ($authors as $author) {
|
return;
|
||||||
if (!array_key_exists($author['label'], self::$authorList)) {
|
|
||||||
self::$authorList[$author['label']] = $author['name'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
asort(self::$authorList);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend page blueprints with additional configuration options.
|
* Extend page blueprints with additional configuration options.
|
||||||
*
|
*
|
||||||
* @param Event $event
|
* @param Event $event
|
||||||
*/
|
*/
|
||||||
public function onBlueprintCreated(Event $event)
|
public function onGetPageBlueprints($event)
|
||||||
{
|
{
|
||||||
static $inEvent = false;
|
$types = $event->types;
|
||||||
|
$types->scanBlueprints('plugins://' . $this->name . '/blueprints');
|
||||||
/** @var Data\Blueprint $blueprint */
|
|
||||||
$blueprint = $event['blueprint'];
|
|
||||||
if (!$inEvent && $blueprint->get('form/fields/tabs', null, '/')) {
|
|
||||||
$inEvent = true;
|
|
||||||
$blueprints = new Data\Blueprints(__DIR__ . '/blueprints/');
|
|
||||||
$extends = $blueprints->get('aura-authors');
|
|
||||||
$blueprint->extend($extends, true);
|
|
||||||
$inEvent = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function onAdminSave(Event $event)
|
||||||
* Add plugin directory to twig lookup paths
|
|
||||||
*/
|
|
||||||
public function onTwigTemplatePaths()
|
|
||||||
{
|
{
|
||||||
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
|
// Don't proceed if Admin is not saving a Page
|
||||||
}
|
if (!$event['object'] instanceof Page) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Add author to page taxonomy
|
|
||||||
*
|
|
||||||
* @param Event $e
|
|
||||||
*/
|
|
||||||
public function onPageInitialized()
|
|
||||||
{
|
|
||||||
if ($this->isAdmin()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$page = $event['object'];
|
||||||
|
if (isset($page->header()->aura['author'])) {
|
||||||
|
$author = array('author' => array($page->header()->aura['author']));
|
||||||
|
$page->header()->taxonomy = array_merge($page->header()->taxonomy, $author);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPageInitialized()
|
||||||
|
{
|
||||||
$page = $this->grav['page'];
|
$page = $this->grav['page'];
|
||||||
$header = $page->header();
|
if ($page->template() === 'authors') {
|
||||||
if ((isset($header->aura['author'])) && ($header->aura['author'] != '')) {
|
$post = $this->grav['uri']->post();
|
||||||
$taxonomy = $page->taxonomy();
|
if ($post) {
|
||||||
$taxonomy['author'][] = $header->aura['author'];
|
$authors = isset($post['data']['authors']) ? $post['data']['authors'] : [];
|
||||||
$page->taxonomy($taxonomy);
|
$file = File::instance(self::$authorsFile);
|
||||||
|
$file->save(Yaml::dump($authors));
|
||||||
|
$admin = $this->grav['admin'];
|
||||||
|
$admin->setMessage($admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function onTwigTemplatePaths()
|
||||||
* Create structured authors array and expose to Twig
|
|
||||||
*/
|
|
||||||
public function onTwigSiteVariables()
|
|
||||||
{
|
{
|
||||||
$authors = array();
|
$this->grav['twig']->twig_paths[] = __DIR__ . '/admin/templates';
|
||||||
$raw = $this->grav['config']->get('plugins.aura-authors.authors');
|
}
|
||||||
if ($raw) {
|
|
||||||
foreach ($raw as $author) {
|
public function onAdminMenu()
|
||||||
$authors[$author['label']] = $author;
|
{
|
||||||
}
|
$this->grav['twig']->plugins_hooked_nav['Authors'] = ['route' => $this->route, 'icon' => 'fa-users'];
|
||||||
}
|
|
||||||
$this->grav['twig']->twig_vars['authors'] = $authors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function listAuthors() {
|
public static function listAuthors() {
|
||||||
return self::$authorList;
|
$authorList = [];
|
||||||
|
$authors = self::getAuthors();
|
||||||
|
foreach ($authors as $author) {
|
||||||
|
$authorList[$author['label']] = $author['name'];
|
||||||
|
}
|
||||||
|
asort($authorList);
|
||||||
|
return $authorList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -34,68 +34,3 @@ form:
|
||||||
0: PLUGIN_ADMIN.DISABLED
|
0: PLUGIN_ADMIN.DISABLED
|
||||||
validate:
|
validate:
|
||||||
type: bool
|
type: bool
|
||||||
authors:
|
|
||||||
type: list
|
|
||||||
label: Author details
|
|
||||||
help: "Add or edit author details"
|
|
||||||
fields:
|
|
||||||
.name:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: Name
|
|
||||||
validate:
|
|
||||||
required: true
|
|
||||||
.label:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: Taxonomy Label
|
|
||||||
validate:
|
|
||||||
pattern: "[a-z][a-z0-9_\-]+"
|
|
||||||
message: "Use all lowercase letters and replace spaces with hyphens."
|
|
||||||
required: true
|
|
||||||
.image:
|
|
||||||
type: file
|
|
||||||
size: large
|
|
||||||
label: Image
|
|
||||||
multiple: false
|
|
||||||
destination: 'user/plugins/aura-authors/assets'
|
|
||||||
accept:
|
|
||||||
- image/*
|
|
||||||
.description:
|
|
||||||
type: textarea
|
|
||||||
size: long
|
|
||||||
label: Description
|
|
||||||
.facebook-url:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: Facebook URL
|
|
||||||
placeholder: 'https://www.facebook.com/username'
|
|
||||||
.twitter-url:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: Twitter URL
|
|
||||||
placeholder: 'https://twitter.com/username'
|
|
||||||
.instagram-url:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: Instagram URL
|
|
||||||
placeholder: 'https://www.instagram.com/username'
|
|
||||||
.linkedin-url:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: LinkedIn URL
|
|
||||||
placeholder: 'https://www.linkedin.com/in/name'
|
|
||||||
.pinterest-url:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: Pinterest URL
|
|
||||||
placeholder: 'https://www.pinterest.com/user/username'
|
|
||||||
.youtube-url:
|
|
||||||
type: text
|
|
||||||
size: large
|
|
||||||
label: YouTube URL
|
|
||||||
placeholder: 'https://www.youtube.com/username'
|
|
||||||
.website-url:
|
|
||||||
type: text
|
|
||||||
label: Website URL
|
|
||||||
placeholder: 'https://www.example.com'
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
form:
|
|
||||||
fields:
|
|
||||||
tabs:
|
|
||||||
fields:
|
|
||||||
aura:
|
|
||||||
type: tab
|
|
||||||
title: Aura
|
|
||||||
|
|
||||||
fields:
|
|
||||||
|
|
||||||
header.aura.author:
|
|
||||||
type: select
|
|
||||||
label: Author
|
|
||||||
size: medium
|
|
||||||
data-options@: '\Grav\Plugin\AuraAuthorsPlugin::listAuthors'
|
|
||||||
options:
|
|
||||||
'': ''
|
|
40
blueprints/default.yaml
Normal file
40
blueprints/default.yaml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
title: Aura
|
||||||
|
'@extends':
|
||||||
|
type: default
|
||||||
|
context: blueprints://pages
|
||||||
|
|
||||||
|
form:
|
||||||
|
fields:
|
||||||
|
tabs:
|
||||||
|
type: tabs
|
||||||
|
active: 1
|
||||||
|
|
||||||
|
fields:
|
||||||
|
|
||||||
|
options:
|
||||||
|
type: tab
|
||||||
|
title: PLUGIN_ADMIN.OPTIONS
|
||||||
|
|
||||||
|
fields:
|
||||||
|
publishing:
|
||||||
|
type: section
|
||||||
|
title: PLUGIN_ADMIN.PUBLISHING
|
||||||
|
underline: true
|
||||||
|
|
||||||
|
fields:
|
||||||
|
header.metadata:
|
||||||
|
unset@: true
|
||||||
|
|
||||||
|
aura:
|
||||||
|
type: tab
|
||||||
|
title: Aura
|
||||||
|
|
||||||
|
fields:
|
||||||
|
|
||||||
|
header.aura.author:
|
||||||
|
type: select
|
||||||
|
label: Author
|
||||||
|
size: medium
|
||||||
|
data-options@: '\Grav\Plugin\AuraAuthorsPlugin::listAuthors'
|
||||||
|
options:
|
||||||
|
'': ''
|
Loading…
Reference in a new issue