0

JoomFish, add editor to extra fields

Over a year now i started working on sites with Joomla! 2.5 combined with K2 plugin and Joomfish 2.5.1 installed. I noticed that in Joomfish extra fields didn’t appeared like they should, instead they where looking as a JSON string. With little googling i found how to fix this problem here.

Next thing to face was adding the editor to textareas… I added the following code to render the editor to textareas and also to save them correctly to the database, without html code for search.

  1. Added the editor to textareas
    Lines: 981, 1068

    $editor =& JFactory::getEditor();
    $output= $editor->display( 'K2ExtraField_'.$extraField->id, $active, '100%', '400', '70', '15',false);
    
  2. Added slashes for JavaScript conflicts
    Lines: 665, 843

    $output= str_replace("'","\'",$output);
    
  3. Added function to keep search value clean, without html code
    Line: 531

    //this is for saving search
    foreach ($variables as $key => $value) {
     if ((bool) JString::stristr($key, 'K2ExtraField_')) {
      $object = new JObject;
      $object->set('id', JString::substr($key, 13));
      $object->set('value', $value);
      unset($object->_errors);
      $objectsa[] = $object;
     }
    }
    $extra_fields_search = '';
    foreach ($objectsa as $object) {
     $extra_fields_search .= $this->getSearchValue($object->id, $object->value);
     $extra_fields_search .= ' ';
    }
    //search ends here
    //this is for saving extra fields
    foreach ($_POST as $key => $value) {
     if ((bool) JString::stristr($key, 'K2ExtraField_')) {
      $object = new JObject;
      $object->set('id', JString::substr($key, 13));
      $object->set('value', $value);
      unset($object->_errors);
      $objectsb[] = $object;
     }
    }
    $json = new Services_JSON;
    $extra_fields = $json->encode($objectsb);
    //extra fields ends here
    

I’ve attached my source code with the original file from K2

  1. Remove extra_fields and extra_fields_search from

    /administrator/components/com_joomfish/contentelements/k2_items.xml

  2. Copy k2.php to

    /plugins/system/k2/

Download: joomfishExtrafields

stvakis

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.