Add a link to call by skype in Drupal 8

Submitted by Richard Papp on Tue, 01/10/2017 - 13:29

Websites can use protocol handlers to provide a convenient way for users to open default applications directly from a web page. A common example is a mailto: link for sending an email:

<a href="mailto:info@example.com">info@example.com</a>

When the link is activated, the browser should launch the default email application.

This is becoming even more popular with the proliferation of touch devices like smartphones and tablets. Instead of typing e.g. a long phone number from a web page, the user can call that number by simply clicking on it:

<a href="tel:+1234567890">+1 234 567 890</a>

limits the allowed protocols. If you use a text filter that strips certain HTML tags, protocols that are not allowed get filtered out. There is no administration page in Drupal core where you could add more protocols to the list.

In 7 the contributed Filter allowed protocols provides such an administration page. Or you can add protocols directly in the file /sites/default/settings.php:

<?php

$conf['filter_allowed_protocols'] = array('ftp', 'http', ...);

In 8 you can add protocols by editing the default filter protocols list in the file /sites/default/services.yml:

parameters:
  # Allowed protocols for URL generation.
  filter_protocols:
    - http
    - https
    - ftp
    - news
    - nntp
    - tel
    - telnet
    - mailto
    - irc
    - ssh
    - sftp
    - webcal
    - rtsp
    - skype

This allows to create a link that visitors can click on to call a skype user (replace the text in brackets with a valid skype user name):

<a href="skype:<username>?call">Skype user name</a>
Tools

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.