Skip to content

Instantly share code, notes, and snippets.

@abdusco
Created October 4, 2017 18:45
Show Gist options
  • Save abdusco/750cfacfe376dc8d038a2a5106d27c41 to your computer and use it in GitHub Desktop.
Save abdusco/750cfacfe376dc8d038a2a5106d27c41 to your computer and use it in GitHub Desktop.
Remove changeable template options from Page editor
<?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