Skip to content

Commit

Permalink
Fix fatal error when the Redactor plugin isn’t installed, due to utal…
Browse files Browse the repository at this point in the history
…ising its hook
  • Loading branch information
engram-design committed Feb 20, 2018
1 parent 9f36226 commit 323d04d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/ExpandedSingles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 323d04d

Please sign in to comment.