Created
October 4, 2017 18:45
-
-
Save abdusco/750cfacfe376dc8d038a2a5106d27c41 to your computer and use it in GitHub Desktop.
Remove changeable template options from Page editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
wire()->addHookAfter('ProcessPageEdit::buildFormSettings', function (HookEvent $e) { | |
$page = $e->object->getPage(); | |
if ($page->template != "basic") return; | |
/** @var $templatesField InputfieldSelect */ | |
$templatesField = $e->return->children->get('id=template'); | |
$templates = $templatesField->getOptions(); | |
// sort first | |
asort($templates); | |
foreach ($templates as $tid => $tname) { | |
// remove incompatible fields | |
$template = $e->templates->get($tid); | |
if (!$template) continue; | |
if (strpos($template->tags, 'allow') === false) unset($templates[$tid]); | |
} | |
$templatesField->set('options', $templates); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment