#91 Posted in ‘Econa’

Latest post by Lefteris Kavadas on Tuesday, 12 December 2017 21:48 EET

Oliver Rockwell
We discovered a problem today with a common workflow that our team uses. We have many categories on our magazine sites so if someone is entering a number of articles in the same category it saves time to filter the Articles listing by that category. This way when hitting the New button to create a new article the category is already set. The problem is that when filtering or when an article has multiple categories the category is an array of integers instead of an integer which causes a 500 error of Unknown column 'Array' in where clause.

Poking around in the content plugin onContentPrepareForm() function I was able to write a fix that is more general than the assumption of a single category for determining if the Image field tab loads. I made the assumption that if ANY category in the list enables the field then the field is enabled and only loaded once. I also generalized by converting the category ID to a single element array if it is not an array already. Hopefully you can fold this fix into your next release so we don't have to maintain a patch here.

Thanks,

Oliver

code snippet from plugins/content/econa/econa.php - onContentPrepareForm()

// Article form
elseif ($name == 'com_content.article') {
  $categoryIds = is_object($data) ? $data->catid : $data['catid'];
  if ($categoryIds) {
      // force array
      if (!is_array($categoryIds)) {
          $categoryIds = [ $categoryIds ];
      }
      foreach ($categoryIds as $categoryId) {
          $category = JTable::getInstance('Category');
          $category->load($categoryId);
          $categoryParams = new Registry();
          $categoryParams->loadString($category->params);
          if ($categoryParams->get('enable_image_tab', 1)) {
	          JForm::addFormPath(__DIR__ . '/forms');
	          $form->loadFile('econa', false);
	          // only load field once
	          break;
          }
      }
  } else {
      JForm::addFormPath(__DIR__ . '/forms');
      $form->loadFile('econa', false);
  }
}

Lefteris Kavadas
Hello,
I will test the code you provided and if I don't find any issues I will merge it to the plugin codebase so you do not have to patch it.
Thank you for reporting.
Let me know if you need anything else.

Regards

Lefteris Kavadas
Version 1.6.0 has been released and includes your fix.

Thank you for reporting.

Regards

Note: An active subscription is required in order to get support for our paid extensions. For our free extensions, if you don't have an account, register and then submit your support request.  In case you just want to ask a question, you can also use the contact form .

Firecoders
Are you using our extensions? Please post a review at the Joomla extensions directory!
Post a review