Created
September 19, 2017 07:01
-
-
Save abdusco/758342696d2a8bdb2f1de413f3bc0fea to your computer and use it in GitHub Desktop.
Limit Image field to maximum 1 file for a template in ProcessWire
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 namespace ProcessWire; | |
// put this in /site/ready.php | |
wire()->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $e) { | |
/** @var ProcessPageEdit $edit */ | |
$templates = ['post', 'basic']; | |
$edit = $e->object; | |
$page = $edit->getPage(); | |
if (!in_array($page->template->name, $templates)) return; | |
/** @var InputfieldForm $form */ | |
$form = $e->return; | |
/** @var InputfieldImage $imageField */ | |
$imageField = $form->children->findOne('name=images'); | |
if (!$imageField) return; | |
$imageField->maxFiles = 1; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment