- Posts: 3
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- Extra Field 'Link' values are not added to extra_fields_search
Extra Field 'Link' values are not added to extra_fields_search
- Woodus
- Topic Author
- Offline
- New Member
Less
More
15 years 2 weeks ago #75277
by Woodus
Extra Field 'Link' values are not added to extra_fields_search was created 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
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
15 years 2 weeks ago #75278
by Woodus
Replied by Woodus on topic Extra Field 'Link' values are not added to extra_fields_search
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
15 years 2 weeks ago #75279
by Woodus
Replied by Woodus on topic Extra Field 'Link' values are not added to extra_fields_search
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
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.
- Lefteris
- Offline
- Moderator
Less
More
- Posts: 8743
15 years 2 weeks ago #75280
by Lefteris
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Lefteris on topic Extra Field 'Link' values are not added to extra_fields_search
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.
- Forum
- K2 Community Forum
- English K2 Community
- Extra Field 'Link' values are not added to extra_fields_search