Keyword

Extra Field 'Link' values are not added to extra_fields_search

  • Woodus
  • Woodus's Avatar Topic Author
  • Offline
  • New Member
More
15 years 2 weeks ago #75277 by Woodus
I have noticed that Link extra fields are not searchable. I have also noted that the link values are not being added to the search field extra_fields_search. I am sure this is just a slight modification required.

I believe I have identified the offending code in the extarfield.php file at roughly line 208. Link and Multiselect types are processed together and I suspect this is the problem. Any talent out there that can knock this one out for me??

Best,
Rob

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

  • Woodus
  • Woodus's Avatar Topic Author
  • Offline
  • New Member
More
15 years 2 weeks ago #75278 by Woodus
Oh, and I guess I need to confirm this really is a bug. Can others search for links (name or value)?

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

  • Woodus
  • Woodus's Avatar Topic Author
  • Offline
  • New Member
More
15 years 2 weeks ago #75279 by Woodus
Okay, so you guys were just waiting for me to figure this out to boost my confidence right? Heh. Well, here's the hacking I've put together. Decide for yourself if it's acceptable.

In the "component\admin\models\extrafield.php" file the problem originates around line 208 at the getSearchValue function due to the fact that the Link type is treated like a multiselect type. The loop compares current values against the options available in the extra fields table and when it finds a match it simply stores the name of that option from the extra fields table as the value to search, Not that actual value (although they are clearly equal).

This method will obviously not work for links due to the fact that there are no options to compare against. So, instead we simply need to store the current array values for Name and Value. (By default the component typically references on the name value for searches, but I wanted to include the link URL as well.)

Here's my hack of the function:
function getSearchValue($id, $currentValue){

$row = & JTable::getInstance('K2ExtraField', 'Table');
$row->load($id);

require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'lib'.DS.'JSON.php');
$json=new Services_JSON;
$jsonObject=$json->decode($row->value);

$value='';
if ( $row->type=='textfield'|| $row->type=='textarea'){
$value=$currentValue;
}
else if ($row->type=='multipleSelect'){
foreach ($jsonObject as $option){
if (in_array($option->value,$currentValue))
$value.=$option->name.' ';
}
}
else if ($row->type=='link'){
$value.=$currentValue[0].' '; /* Add Name */
$value.=$currentValue[1].' '; /* Add URL */
}
else {
foreach ($jsonObject as $option){
if ($option->value==$currentValue)
$value.=$option->name;
}
}
return $value;
}

Basically all I did was the link type it's own "else if " in order to simply assign the values for name and url. Hope this works for you.
-Rob

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

More
15 years 2 weeks ago #75280 by Lefteris
Hi. The fix has been added to K2 for the next release. Thanks for reporting this issue and committing the fix.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum