Skip to content

Commit

Permalink
Fix issue around "Class 'Grav\Plugin\Shortcodes\Shortcode' not found".
Browse files Browse the repository at this point in the history
This patch fixes #4.

Context:

    Before this patch (after 4.2.0 of shortcode-core), I could
    not run Grav (bin/grav and webserver) anymore.

    Indeed, I got "Class 'Grav\Plugin\Shortcodes\Shortcode' not found"
    as error and asked for help on the discord server of the
    Grav Core Team.

    @mahagr & @rhukster tried to help me with a patch+release
    (shortcode-core 4.2.1) but it still did not solve the issue.
    So I decided to fix it myself.

Resolution:

    I first followed the new structure by moving the shortcodes classes
    inside the `classes` directory.
    Same for `classes/SSEShortcode.php` which I moved to
    `classes/plugin/SSEShortcode.php`.

    In the `static-social-embeds.php` file, I just fixed the autoloader.
    In particularly the `getSubscribedEvents()` method. From now,
    `classes/plugin/SSEShortcode.php` is only loaded when we are not
    in the admin section.

    After, applying and testing those changes, onto my fresh development
    environment (latest grav-admin+docker-compose), everything worked
    back properly.
  • Loading branch information
funilrys committed Feb 16, 2020
1 parent b84a0cb commit d19349c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 22 additions & 12 deletions static-social-embeds.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin;

use Grav\Common\Assets;
Expand All @@ -23,24 +24,36 @@ class StaticSocialEmbedsPlugin extends Plugin
*/
public static function getSubscribedEvents()
{
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/classes/SSEShortcode.php';

return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
'onPluginsInitialized' => [
['autoload', 100001],
['onPluginsInitialized', 0]
],
];
}

/**
* [onPluginsInitialized:100000] Composer autoload.
*
* @return ClassLoader
*/
public function autoload()
{
return require __DIR__ . '/vendor/autoload.php';
}

/**
* Initialize the plugin
*/
public function onPluginsInitialized()
{
// Don't proceed if we are in the admin plugin
if ($this->isAdmin()) {
// Don't proceed if we are in the admin plugin
return;
}

require_once __DIR__ . '/classes/plugin/SSEShortcode.php';

// Enable the main event we are interested in
$this->enable([
'onShortcodeHandlers' => ['onShortcodeHandlers', 0],
Expand All @@ -65,18 +78,15 @@ public function onAssetsInitialized()
/** @var $assets Assets */
$assets = $this->grav['assets'];

if ($this->config->get('plugins.static-social-embeds.include_font_awesome_5', true))
{
if ($this->config->get('plugins.static-social-embeds.include_font_awesome_5', true)) {
$assets->add('https://use.fontawesome.com/releases/v5.1.0/css/all.css');
}

if ($this->config->get('plugins.static-social-embeds.built_in_css', true))
{
if ($this->config->get('plugins.static-social-embeds.built_in_css', true)) {
$assets->add('plugin://static-social-embeds/assets/css-compiled/sse.min.css', 4);
}

if ($this->config->get('plugins.static-social-embeds.built_in_js', true))
{
if ($this->config->get('plugins.static-social-embeds.built_in_js', true)) {
$assets->addJs('plugin://static-social-embeds/assets/js/sse.js', 4, true, 'defer');
}
}
Expand All @@ -86,6 +96,6 @@ public function onAssetsInitialized()
*/
public function onShortcodeHandlers()
{
$this->grav['shortcode']->registerAllShortcodes(__DIR__.'/shortcodes');
$this->grav['shortcode']->registerAllShortcodes(__DIR__ . '/classes/shortcodes');
}
}

0 comments on commit d19349c

Please sign in to comment.