Skip to Content Skip to Menu

Variables in joomla_onContentBeforeSave

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
6 months 2 weeks ago #338037 by rbuelund
Variables in joomla_onContentBeforeSave was created by rbuelund
I would like to create a Code Auto Action the triggers on joomla_onContentBeforeSave.
The condition that it is a joomla article with catID = 8 has to be correct and the code should check if a certain custom field in the article is filled correct.
If the condition is correct and the field is filled correct the article should be saved, otherwise the article is not possible to save and and alert is given.

Is that possible ? And how would I use the var1_, var2_ etc of the article ?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
6 months 2 weeks ago #338044 by krileon
Replied by krileon on topic Variables in joomla_onContentBeforeSave
Joomla triggers all contain whatever variables those triggers normally would contain. See Joomla's documentation below for their variables.

docs.joomla.org/Plugin/Events/Content#onContentBeforeSave

Variables always start with var1 and increment from left to right. Objects and arrays can be substitution accessed by using underscores. So if var2 is the article and it has a object key of catid you can substitute it with [var2_catid].

Anywhere PHP is available (e.g. PHP conditions, Code actions, and PHP outputs) you've direct access to the raw data from the triggers as well using $variables.


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.

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
6 months 2 weeks ago #338045 by rbuelund
Replied by rbuelund on topic Variables in joomla_onContentBeforeSave
But how would I get values of custom fields ? They are in $article->custom_field_name
I cannot see how I can get that value from the $article objec ?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
6 months 2 weeks ago #338047 by krileon
Replied by krileon on topic Variables in joomla_onContentBeforeSave
If they're in the object then you can access them. I cannot tell you what all Joomla has in its objects as I don't know. The substitution parsing goes 2 levels deep. So you can even access param columns (e.g. var1_params_myparam). You'll need to look into Joomla API to see how those are structured in its article object. If it's really $article->custom_field_name exactly then it'd just be var2_custom_field_name. They're all accessed by object property name and array key.


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.

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
6 months 2 weeks ago - 6 months 2 weeks ago #338050 by rbuelund
Replied by rbuelund on topic Variables in joomla_onContentBeforeSave
Well.. when I create a new article with custom fields with an auto action I use this array:

$article = [
    'catid' => 8,
    'com_fields' => array('cvr' => $cvr, 'adresse' => $address, 'postnr' => $postnr, 'by' => $city, 'telefon' => $telefon, 'webshop-url' => $webshopurl, 'billede' => $imagename , 'beskrivelse' => $description),
    'alias' => '',
    'title' => '[username]',
    'introtext' => '',
    'fulltext' => '',
    'created_by' => $user->id,
    'state' => 1,
    'attribs' => '{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',
   'metadata' => '{"robots":"","author":"","rights":"","xreference":""}',
    'language' => '*'
];

That works just fine.

But I cannot seem to get hold of the com_fields array on an allready created article from another auto action that is triggered by onContentBeforeSave. I need to grap the webshop-url - is that not possible ?
Last edit: 6 months 2 weeks ago by rbuelund.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
6 months 2 weeks ago - 6 months 2 weeks ago #338054 by krileon
Replied by krileon on topic Variables in joomla_onContentBeforeSave
You access data from object property name and array key. So if that data does exist on the article object you would access it with the following.

[var2_com_fields_webshop-url]

I cannot guarantee you will be able to. That's entirely up to Joomla as we have no control over what their events do and do not contain.

If this is in PHP you can also just directly get the article object. Example as follows.
Code:
$article = $variables['var2'];


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.
Last edit: 6 months 2 weeks ago by krileon.

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

Moderators: beatnantkrileon
Powered by Kunena Forum