- Posts: 157
- Thank you received: 7
Extra field Link Option
- wrina iamwe
-
Topic Author
- Offline
Less
More
10 years 8 months ago #226619
by wrina iamwe
Extra field Link Option was created by wrina iamwe
-- HikaShop version -- : 2.6.1
I need to create a link to samples in the product display.
I am using the extra fields' link plugin field - however the url link display is too long - is their a link field or a different field type that can be used to shorten the link url? I have tried an <a href in the link field to generate a text display, but, that does not work.
Example:
< a href="http:// ... ">Display Field < / a >
thanks
I need to create a link to samples in the product display.
I am using the extra fields' link plugin field - however the url link display is too long - is their a link field or a different field type that can be used to shorten the link url? I have tried an <a href in the link field to generate a text display, but, that does not work.
Example:
< a href="http:// ... ">Display Field < / a >
thanks
Please Log in or Create an account to join the conversation.
10 years 8 months ago #226639
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Replied by Jerome on topic Extra field Link Option
Hi,
The idea would be to update the HikaShop link field (in the classes/field.php file).
With a code like
It would support special format for the links
Regards,
The idea would be to update the HikaShop link field (in the classes/field.php file).
With a code like
Code:
$link = $value;
$text = $value;
if(preg_match('#"([^"]+)":(.*)#iU', $value, $m)) {
$link = $m[2];
$text = $m[1];
}
return '<a'.$target.' href="'.$this->trans($link).'">'.$this->trans($text).'</a>';
"Display field":http://website/link.html
"Display field":/link.html
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Please Log in or Create an account to join the conversation.
- wrina iamwe
-
Topic Author
- Offline
Less
More
- Posts: 157
- Thank you received: 7
10 years 8 months ago #227015
by wrina iamwe
Replied by wrina iamwe on topic Extra field Link Option
Hello Jerome, thanks for your help,
I have attempted to add the script you suggested.
I dont believe i have added to the correct class
Q. Where should the statement be placed? I dont believe the additional has affected the view, as it looks similar to the output that was rendered prior.
The script links to the external url, but the display text is doubled and displays a symbol. see image.
Thanks,
Wrina
Wrina
Thanks
I have attempted to add the script you suggested.
I dont believe i have added to the correct class
Code:
$fieldtype->load($field->field_table);
if(!empty($fieldtype->externalOptions) && isset($fieldtype->allValues[$field->field_type])) {
$linkedOptions = $fieldtype->allValues[$field->field_type]['options'];
foreach($fieldtype->externalOptions as $key => $extraOption) {
if(in_array($key, $linkedOptions)) {
$o = is_array($extraOption) ? $extraOption['obj'] : $extraOption->obj;
if(is_string($o))
$o = new $o();
if(method_exists($o, 'save'))
$o->save($fieldOptions);
//wrina add //
$link = $value;
$text = $value;
if(preg_match('#"([^"]+)":(.*)#iU', $value, $m)) {
$link = $m[2];
$text = $m[1];
}
return '<a'.$target.' href="'.$this->trans($link).'">'.$this->trans($text).'</a>';
//end add//
}
}
}
The script links to the external url, but the display text is doubled and displays a symbol. see image.
Thanks,
Wrina
Wrina
Thanks
Please Log in or Create an account to join the conversation.
10 years 8 months ago #227046
by nicolas
Replied by nicolas on topic Extra field Link Option
Hi,
I think that Jerome meant that you should improve the link type class:
So that it would be more adapted to your needs.
I think that Jerome meant that you should improve the link type class:
Code:
class hikashopLink extends hikashopText {
function show(&$field,$value) {
$target = '';
if(isset($field->field_options['target_blank']) && $field->field_options['target_blank'] == '1')
$target = ' target="_blank"';
return '<a'.$target.' href="'.$this->trans($value).'">'.$this->trans($value).'</a>';
}
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.165 seconds