bmcclure/CakePHP-Media-Plugin — Issue #7: File Upload shoud be required
Author: PHANTOMIAS
Created: 2012-02-01 10:21:21+00:00
State: open

I have a file upload, but i want that it is a mandatory field, so the file upload is required.

In my model I tried this:

public $validate = array(
'file' => array(
'required' => true,
'extension' => array('rule' => array('checkExtension', false, array('jpg', 'jpeg', 'png', 'tif', 'tiff', 'gif'))),
'mimeType' => array('rule' => array('checkMimeType', false, array('image/jpeg', 'image/png', 'image/tiff', 'image/gif')))
)
);

But an error occurs in TransferBehavior.php:

public function setup($Model, $settings = array()) {
/* If present validation rules get some sane default values */
if (isset($Model->validate['file'])) {
$default = array('allowEmpty' => true, 'required' => false, 'last' => true);

foreach ($Model->validate['file'] as &$rule) {
$rule = array_merge($default, $rule);
}
}
...

This line fails
$rule = array_merge($default, $rule);
I think because it tries to merge my "required" with the "required" which is defined in this method.
So, of course I can change the $default, but it is not very nice especially updating the plugin, I have to change it every time :-(

Are there any better solutions?