From 323d04d5d927a5fd89a413d0eebf30c0adc15563 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Tue, 20 Feb 2018 21:34:31 +1100 Subject: [PATCH] =?UTF-8?q?Fix=20fatal=20error=20when=20the=20Redactor=20p?= =?UTF-8?q?lugin=20isn=E2=80=99t=20installed,=20due=20to=20utalising=20its?= =?UTF-8?q?=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ExpandedSingles.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ExpandedSingles.php b/src/ExpandedSingles.php index 6cfb5bb..975d425 100755 --- a/src/ExpandedSingles.php +++ b/src/ExpandedSingles.php @@ -60,26 +60,28 @@ public function init() }); // Hook onto a special hook from Redactor - it handles singles a little differently! - Event::on(RedactorField::class, RedactorField::EVENT_REGISTER_LINK_OPTIONS, function(RegisterLinkOptionsEvent $event) { - - // Have we enabled the plugin? - if ($this->getSettings()->expandSingles) { - - foreach ($event->linkOptions as $i => $linkOption) { - - // Only apply this for entries, and if there are any singles - if ($linkOption['refHandle'] === 'entry') { - if (in_array('singles', $linkOption['sources'])) { - $modifiedSources = $this->singlesList->createSectionedSinglesList($linkOption['sources']); - - if ($modifiedSources) { - $event->linkOptions[$i]['sources'] = $modifiedSources; + if (class_exists(RedactorField::class)) { + Event::on(RedactorField::class, RedactorField::EVENT_REGISTER_LINK_OPTIONS, function(RegisterLinkOptionsEvent $event) { + + // Have we enabled the plugin? + if ($this->getSettings()->expandSingles) { + + foreach ($event->linkOptions as $i => $linkOption) { + + // Only apply this for entries, and if there are any singles + if ($linkOption['refHandle'] === 'entry') { + if (in_array('singles', $linkOption['sources'])) { + $modifiedSources = $this->singlesList->createSectionedSinglesList($linkOption['sources']); + + if ($modifiedSources) { + $event->linkOptions[$i]['sources'] = $modifiedSources; + } } } } } - } - }); + }); + } } // Protected Methods