lcollong
FabriKant d'applications web
Hi,
I had the need to let a phone number field act as a direct call when Fabrik's app is used from a smartphone.
The "guess link" standard feature is building a link but without using the "phone possibility" (href="tel:010101010").
I've modified the file plugins/fabrik_element/field/field.php. If a field element is set to "input type: phone Number" in advanced tab and guess link is set to yes, it makes the phone number click launching the phone app.
Maybe it could also be achieved with the JLayouts ?
Here is my code. I could make a github request but one may do it a better way (fabrik helper ?)....
If any better suggestions ?
I had the need to let a phone number field act as a direct call when Fabrik's app is used from a smartphone.
The "guess link" standard feature is building a link but without using the "phone possibility" (href="tel:010101010").
I've modified the file plugins/fabrik_element/field/field.php. If a field element is set to "input type: phone Number" in advanced tab and guess link is set to yes, it makes the phone number click launching the phone app.
Maybe it could also be achieved with the JLayouts ?
Here is my code. I could make a github request but one may do it a better way (fabrik helper ?)....
PHP:
protected function _guessLinkType(&$value, $data)
{
$params = $this->getParams();
if ($params->get('guess_linktype') == '1')
{
$w = new FabrikWorker;
$opts = $this->linkOpts();
$title = $params->get('link_title', '');
$attrs = $params->get('link_attributes', '');
$inputType = $params->get('password'); /////<----- ADDED LINE
if (!empty($attrs))
{
$attrs = $w->parseMessageForPlaceHolder($attrs);
$attrs = explode(' ', $attrs);
foreach ($attrs as $attr)
{
list($k, $v) = explode('=', $attr);
$opts[$k] = trim($v, '"');
}
}
else
{
$attrs = array();
}
if ((new MediaHelper)->isImage($value))
{
$alt = empty($title) ? '' : 'alt="' . strip_tags($w->parseMessageForPlaceHolder($title, $data)) . '"';
$value = '<img src="' . $value . '" ' . $alt . ' ' . implode(' ', $attrs) . ' />';
}
///// begin of ADDED BLOCK
elseif ($inputType == '2') // if input type is "phone number" add a smartphone link to call the phone number
{
$value = '<a href="tel:' . preg_replace('/\D/', '', $value) . '">'.$value.'</a>';
}
///// end of ADDED BLOCK
else
{
if (FabrikWorker::isEmail($value) || JString::stristr($value, 'http'))
{
}
elseif (JString::stristr($value, 'www.'))
{
$value = 'http://' . $value;
}
if ($title !== '')
{
$opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data));
}
$label = FArrayHelper::getValue($opts, 'title', '') !== '' ? $opts['title'] : $value;
$value = FabrikHelperHTML::a($value, $label, $opts);
}
}
}
If any better suggestions ?