I would like to do some custom form processing in an Admin form. I am not clear on what events to register or whether I have to enable something if admin (I’ve seen this in several places, not sure when it’s needed!)… The goal is to handle a file upload so that the file gets uploaded to Cloudinary instead of into Grav via their API, and then set the assigned public id as page.header.public_id
. This is what I’ve got so far:
blueprint.yaml
title: Cloudinary
'@extends':
type: default
context: blueprints://pages
form:
fields:
tabs:
fields:
cloudinary:
type: tab
title: Cloudinary
fields:
file_upload:
name: upload_video
type: file
label: Upload file to Cloudinary
destination: 'self@'
accept:
- video/*
process:
- upload: false
- uploadFile:
The file gets uploaded into that folder anyway (and I need to set a destination or the form complains). I have defined an onFormProcessed method in my plugin’s class:
public function onFormProcessed(Event $event)
{
\Cloudinary::config(array(
"cloud_name" => $this->config->get('plugins.cloudinary.cloud_name'),
"api_key" => $this->config->get('plugins.cloudinary.key'),
"api_secret" => $this->config->get('plugins.cloudinary.secret')
));
$form = $event['form'];
$action = $event['action'];
$params = $event['params'];
$post = isset($_POST['data']) ? $_POST['data'] : [];
switch ($action) {
case 'uploadFile':
return $result = \Cloudinary\Uploader::upload($post['file_upload']);
}
}
Feels to me though as if that method doesn’t get called at all. How can I make this work for an Admin form? Or maybe I can just make a function call in the blueprint like:
process: uploadFileToCloudinary()
I know that can’t be right, but maybe something similar? Or with a different field type? Custom field type??