2017 © Pedro Peláez
 

silverstripe-module silverstripe-externalurlfield

Provides SilverStripe with a DBField and FormField for handling external URLs.

image

burnbright/silverstripe-externalurlfield

Provides SilverStripe with a DBField and FormField for handling external URLs.

  • Monday, February 6, 2017
  • by jedateach
  • Repository
  • 1 Watchers
  • 6 Stars
  • 3,102 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 4 Open issues
  • 7 Versions
  • 12 % Grown

The README.md

SilverStripe External URL Field

Build Status Scrutinizer Code Quality Code Coverage, (*1)

Provides a DBField and FormField for handling external URLs., (*2)

Validate and tidy urls as they are captured from users. Configuration is highly flexible. Makes use of php's parse_url and http_build_url to do the actual work., (*3)

Installation

composer require burnbright/silverstripe-externalurlfield "*@stable"

Requirements

Makes use of the http_build_url function from the PECL pecl_http library. However the module's composer requirements include a PHP fallback/shim/polyfill. The composer replacement does check for the presence of http_build_url., (*4)

  • SilverStripe ^4

DataObject / Template Usage

Handled by ExternalURL class (Varchar)., (*5)

use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{
    private static $db = array(
        'Website' => 'ExternalURL'
    );
}
<% with $MyDataObject %>
    <p>Website: $Website</p>
    <p>Website Nice: $Website.Nice</p>
    <p>Website Domain: $Website.Domain</p>
    <p>Website Domain No WWW: $Website.Domain.NoWWW</p>
<% end_with %>

Given the url http://username:password@www.hostname.com:81/path?arg=value#anchor, the above produces:, (*6)

Website: http://username:password@www.hostname.com:81/path?arg=value#anchor
Website Nice: www.hostname.com/path
Website Domain: www.hostname.com
Website Domain No WWW: hostname.com

Form Usage

Handled by ExternalURLField (FormField)., (*7)

Validation is handled by the html5 pattern attribute, and also server side by a more robust regular expression. The field uses the html5 type="url" attribute., (*8)

You can configure various parts of the url to be stripped out, or populated with defaults when missing., (*9)

use BurnBright\ExternalURLField\ExternalURLField;

//default
$websitefield = new ExternalURLField('Website');

//set options (with defaults shown)
$websitefield->setConfig(array(
    //these will be added, if missing
    'defaultparts' => array(
        'scheme' => 'http'
    ),
    //these parts are removed from saved urls
    'removeparts' => array(
        'scheme' => false,
        'user' => true,
        'pass' => true,
        'host' => false,
        'port' => false,
        'path' => false,
        'query' => false,
        'fragment' => false
    ),
    'html5validation' => true
));

//say you want to store nice tidy facebook urls
$websitefield->setConfig('removeparts',array(
    'query' => true,
    'fragment' => 'true',
    'port' => 'true'
));
//a urls like https://www.facebook.com/joe.bloggs?fref=nf&pnref=story
//would become https://www.facebook.com/joe.bloggs

HTML5 validation

Enabled by default, the html5 validation sets the field type atribute to url, and adds a pattern attribute which is set to https?://.+., (*10)

Disable using the html5validation config:, (*11)

$field->setConfig("html5validation", false);

Disabling html5 validation is particularly useful if you want to allow users to enter urls that have no scheme/protocol e.g: mywebsite.com instead of http://www.mywebsite.com., (*12)

The Versions

06/02 2017

dev-master

9999999-dev

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url form silverstripe link field

12/09 2016

0.3.2

0.3.2.0

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url form silverstripe link field

12/09 2016

0.3.1

0.3.1.0

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url form silverstripe link field

19/11 2014

0.3.0

0.3.0.0

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url silverstripe link

19/11 2014

0.2.1

0.2.1.0

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url silverstripe link

19/11 2014

0.2.0

0.2.0.0

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url silverstripe link

19/11 2014

0.1.0

0.1.0.0

Provides SilverStripe with a DBField and FormField for handling external URLs.

  Sources   Download

MIT

The Requires

 

url silverstripe link