Skip to Content Skip to Menu

CB Blogs K2 model when updating CB

  • activha
  • activha
  • ONLINE
  • Posts: 2334
  • Thanks: 117
  • Karma: 13
7 years 11 months ago #288942 by activha
CB Blogs K2 model when updating CB was created by activha
Hello,

CB new updating system is great but we would need a way to retain a modification in k2 model for CB Blogs.

We insert the following code to be able to use K2 extra fields in CB blogs
Code:
/** * Begin of custom development */ $value = new stdClass(); $value->id = 7; $value->value = $_POST['article_classes']; $currentValues = json_decode($article->get('extra_fields')); //If no previous Value if(empty($currentValues) || !is_array($currentValues)) { $currentValues = array(); $currentValues[] = $value; } else { foreach ($currentValues as $key => $oneValue) { if($oneValue->id == 7) { $currentValues[$key] = $value; } } } $article->set('extra_fields', json_encode($currentValues)); /** * End of custom development */

For each CB update, this code has to be reinserted manually.
No problem for the Blog template as we added the fields in the edit blog template.

Is this possible :
- either to implement the extra field code in the default CB Blog K2 model for next versions ?
- or to have an auto action changing the code ?
- or to have an override for this model in our template ?

Thanks
Jean

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
7 years 11 months ago #288952 by krileon
Replied by krileon on topic CB Blogs K2 model when updating CB
CB Blogs has triggers. There's no reason to be editing its core code. You can use cbblogs_onBeforeCreateBlog and cbblogs_onBeforeUpdateBlog to modify the $article variable to add your custom storage behavior. Can actually be done from CB Auto Actions as well, but you'll need to set variables 1 and 2 as reference variables under the parameters tab of your action. You'd then use a Code action with Method set to PHP. You can then modify the article using the following.

Code:
$vars['var2']->set('extra_fields', json_encode($currentValues));

The variables for those two triggers are as follows.

&$this, &$article, $user, $plugin


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
  • ONLINE
  • Posts: 2334
  • Thanks: 117
  • Karma: 13
7 years 11 months ago #288982 by activha
Replied by activha on topic CB Blogs K2 model when updating CB
I tried with the following code :
Code:
$value = new stdClass(); $value->id = 7; $value->value = $_POST['article_classes']; $currentValues = json_decode($vars['var1']-->get('extra_fields')); //If no previous Value if(empty($currentValues) || !is_array($currentValues)) { $currentValues = array(); $currentValues[] = $value; } else { foreach ($currentValues as $key => $oneValue) { if($oneValue->id == 7) { $currentValues[$key] = $value; } } } $vars['var2']->set('extra_fields', json_encode($currentValues));

This seems to get the extra fields value when updating a blog, however I have two problems :

- a validation issue when selecting a value in the field
- a fatal error with Call to undefined function get() when trying to save the blog

Can you help me on those ?
Thanks
Jean

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
7 years 11 months ago #288992 by krileon
Replied by krileon on topic CB Blogs K2 model when updating CB

- a validation issue when selecting a value in the field

You should be able to set an error using the following, but I don't see any error handling in your code.

Code:
$vars['var1']->setError( 'ERROR_MESSAGE_HERE' );

- a fatal error with Call to undefined function get() when trying to save the blog

Your code has 2 dashes in the get usage, but should only have 1.


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
  • ONLINE
  • Posts: 2334
  • Thanks: 117
  • Karma: 13
7 years 11 months ago #289007 by activha
Replied by activha on topic CB Blogs K2 model when updating CB
Oupsss did not see the 2 dashes :-(
Thanks a lot for pointing it.
Of course it works much better now...

BTW is it possible to also add code to template or do you suggest our own like now ?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
7 years 11 months ago #289035 by krileon
Replied by krileon on topic CB Blogs K2 model when updating CB
There's no trigger for the blog edit view so you'll have to continue to use your own template file. Have added a feature ticket to add triggers to the edit view though so new field rows can be inserted through CB Auto Actions.

forge.joomlapolis.com/issues/6349


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