Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 25th)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

CB Gallery autoaction to create an item

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
8 months 1 week ago #337791 by activha
Replied by activha on topic CB Gallery autoaction to create an item
Great, second question : I would like to pass the privacy settings in the formData together with the file.

Would it be automatically retrieved by the privacy autoaction after this code autoaction ? and How ?

Thanks for your ideas

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
8 months 1 week ago #337793 by krileon
Replied by krileon on topic CB Gallery autoaction to create an item
The privacy for CB Gallery is handled by the system actions in CB Auto Actions. All it's expecting is the privacy rule id to be in the input data with a key of gallery_privacy. So for example gallery_privacy = 99 would be privacy of private. The auto action ideally should work fine if using the CB Gallery object explained earlier, but I can't say for sure as none of this was designed for what you're trying to do. We won't have official RESTful API endpoints until CB 3.x (and this will be a gradual roll-out so it will be awhile) so until then keep in mind none of this takes into consideration external API calls.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
8 months 1 week ago #337800 by activha
Replied by activha on topic CB Gallery autoaction to create an item
I have a few issues finding the proper sequence to detect the type with posting from a formData

I tried 
Code:
$item = new \CB\Plugin\Gallery\Table\ItemTable(); //var_dump($input); $item->set('user_id', $user->id); $item->set('value',''); $item->set( '_input', $input ); $item->set( '_files', $input->getNamespaceRegistry( 'files' ) ); $item->discoverType(); $item->store();

My userid is ok thanks to the token decryption
The formData seems fine in Postman and returns a 200 ok, the item is added to the DB but the file is not saved nor published as the extension is not properly retrieved.

For info my formData in postman is :
token : string
file : file selected
title: string
gallery_privacy[]: 99 //for instance


Could you tell me what's wrong here ?
 

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
8 months 1 week ago #337804 by krileon
Replied by krileon on topic CB Gallery autoaction to create an item
The files need to be set properly in a way that they're accessible to $_FILES in PHP. If this is from JavaScript the easiest way to do this is create a FormData object and add the file input data to it or serialize an existing forms data and send that. Your alternative is to build the same array structure that $_FILES provides and set it into a Registry object into _files. Sorry, there's nothing more I can suggest here as I cannot help you with custom coding.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • activha
  • activha
  • OFFLINE
  • Posts: 2336
  • Thanks: 117
  • Karma: 13
8 months 1 week ago #337805 by activha
Replied by activha on topic CB Gallery autoaction to create an item

If this is from JavaScript the easiest way to do this is create a FormData object and add the file input data to it 

This is exactly what I do as I'm using Postman Post to test

The code snippet is very standard 
Code:
const formdata = new FormData(); formdata.append("token", "xxx"); formdata.append("file", fileInput.files[0], "test.pdf"); formdata.append("gallery_privacy[]", "99"); const requestOptions = {   method: "POST",   headers: myHeaders,   body: formdata,   redirect: "follow" }; fetch("https://devel.cercle.business/index.php?option=com_comprofiler&view=pluginclass&plugin=cbautoactions&action=action&actions=340", requestOptions)   .then((response) => response.text())   .then((result) => console.log(result))   .catch((error) => console.error(error));

Nothing difficult here and it's not custom coding, but it does not work 

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
8 months 1 week ago #337809 by krileon
Replied by krileon on topic CB Gallery autoaction to create an item
You don't need to call ->discoverType() as it will be called in ->store() automatically.

As for the files. The file input in CB Gallery isn't named "file" it's named "upload". So just changing the name should probably be sufficient for that.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum