2017 © Pedro PelĆ”ez
 

craft-plugin craft3-fields

Address, telephone and email fields for CraftCMS 3.x

image

newism/craft3-fields

Address, telephone and email fields for CraftCMS 3.x

  • Monday, April 23, 2018
  • by leevigraham
  • Repository
  • 1 Watchers
  • 45 Stars
  • 1,939 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 8 Open issues
  • 12 Versions
  • 45 % Grown

The README.md

A collection of custom Fields CraftCMS

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:, (*1)

$ composer require newism/craft-fields && ./craft plugin/install nsm-fields

Configuration

  • If you're using Address Autocomplete you'll need an api key.
  • If you're embedding Instagram you'll need an api key.
  • If you're embedding Facebook you'll need an api key.

Add the api keys to your environment and set in the plugin settings. See: https://craftcms.com/docs/3.x/config/#environmental-configuration, (*2)

Alternativelyā€¦, (*3)

Copy src/config.php to CRAFT_CONFIG_PATH and rename the file to nsm-fields.php., (*4)


Fields

Address

Address field powered by Google's dataset (commerceguys/addressing)., (*5)

Features:, (*6)

  • Auto-complete powered by Google Place API
  • Map powered by Google Maps Javascript API and Google Maps Geocoding API
  • Address form formatting based on country powered by commerceguys/addressing
  • Validation / Geo-coding on submission (TODO)

Template Tags:, (*7)

The normalizeValue method always returns an AddressModel. All public properties are available:, (*8)

Given entry.address is your fieldā€¦, (*9)

See: https://github.com/commerceguys/addressing/blob/master/src/AddressInterface.php
{{ entry.address.countryCode }}
{{ entry.address.administrativeArea }}
{{ entry.address.locality }}
{{ entry.address.dependentLocality }}
{{ entry.address.postalCode }}
{{ entry.address.sortingCode }}
{{ entry.address.addressLine1 }}
{{ entry.address.addressLine2 }}
{{ entry.address.organization }}
{{ entry.address.recipient }}
{{ entry.address.locale }}

See: https://github.com/commerceguys/addressing/blob/master/src/Country/Country.php
{{ entry.address.country.countryCode }}
{{ entry.address.country.name }}
{{ entry.address.country.threeLetterCode }}
{{ entry.address.country.numericCode }}
{{ entry.address.country.currencyCode }}
{{ entry.address.country.locale }}

{{ entry.address.placeData }}
{{ entry.address.latitude }}
{{ entry.address.longitude }}
{{ entry.address.mapUrl }}

Address Demo, (*10)

Telephone

Telephone field powered by Googles phone number library implemented via giggsey/libphonenumber-for-php, (*11)

Features:, (*12)

  • Validate phone number based on country code
  • Format phone number as E164, international, national or RFC3966
  • Stores Telephone model and raw user input

Template Tags:, (*13)

Given entry.telephone is your fieldā€¦, (*14)

{{ entry.telephone }} outputs the phone number in international format., (*15)

You can also choose a specific format:, (*16)

{{ entry.telephone.format('E164') }}
{{ entry.telephone.format('international') }}
{{ entry.telephone.format('national') }}
{{ entry.telephone.format('RFC3966') }}

The raw input from the user is also available:, (*17)

{{ entry.telephone.rawInput }}, (*18)

Telephone Demo, (*19)

Email

Features:, (*20)

  • Email validation using Yii validation

Email Demo, (*21)

Embed

Features:, (*22)

  • Embed social media posts / media directly from a URL
  • Live preview

Template Tags:, (*23)

Given entry.embedField is your fieldā€¦, (*24)

  • {{ entry.embedField.embedData }} outputs the returned embed object.
  • {{ entry.embedField.embedData.code | raw }} outputs the returned embed javascript code.

Additional data:, (*25)

{{ entry.embedField.embedData.authorName }} // The resource author
{{ entry.embedField.embedData.authorUrl }} // The author url
{{ entry.embedField.embedData.cms }} // The cms used
{{ entry.embedField.embedData.code.html }} // The code to embed the image, video, etc
{{ entry.embedField.embedData.code.width }} // The exact width of the embed code (if exists)
{{ entry.embedField.embedData.code.height }} // The exact height of the embed code (if exists)
{{ entry.embedField.embedData.code.aspectRatio }} // The aspect ratio (width/height)
{{ entry.embedField.embedData.description }} //The page description
{{ entry.embedField.embedData.favicon }} // The favicon of the site (an .ico file or a png with up to 32x32px)
{{ entry.embedField.embedData.feeds }} // The RSS/Atom feeds
{{ entry.embedField.embedData.icon }} // The big icon of the site
{{ entry.embedField.embedData.image }} // The thumbnail or main image
{{ entry.embedField.embedData.keywords }} // The page keywords
{{ entry.embedField.embedData.language }} // The language of the page
{{ entry.embedField.embedData.languages }} // The alternative languages
{{ entry.embedField.embedData.license }} // The license url of the resource
{{ entry.embedField.embedData.providerName }} // The provider name of the page (Youtube, Twitter, Instagram, etc)
{{ entry.embedField.embedData.providerUrl }} // The provider url
{{ entry.embedField.embedData.publishedTime }} // The published time of the resource
{{ entry.embedField.embedData.redirect }}
{{ entry.embedField.embedData.title }} //The page title
{{ entry.embedField.embedData.url }} //The canonical url
{{ entry.embedField.embedData.ombed }} // oembed data 
{{ entry.embedField.embedData.linkedData }} // json-LD data

Note: embed data saved with v1 saved the html to {{entry.embedField.embedData.code}}. In v2 {{ entry.embedField.embedData.code }} changed to an array. Your templates will need to account for both versionsā€¦ something like:, (*26)

{{ (entry.embedField.embedData.code.html|default ?: entry.embedField.embedData.code|default) | raw }}

Embed Demo, (*27)

Person Name

Person name field with:, (*28)

  • Honorific Prefix
  • Given Names
  • Additional Names
  • Family Names
  • Honorific Suffix

Person Name Demo, (*29)

Gender

Non-binary gender field with:, (*30)

  • Sex
  • Identity

Gender, (*31)

Road Map

Some things to do, and ideas for potential features:, (*32)

  • Split out each field into it's own plugin. Keep this plugin as a single composer file which pulls all fields in
  • Address validation / Geo-coding on submission
  • Display address as text in field with option to "Edit" to reduce size of field in UI
  • Update commerceguys/addressing when next stable version is released

Credits

Brought to you by Newism, (*33)

, (*34)

The Versions

23/04 2018

dev-master

9999999-dev

Address, telephone and email fields for CraftCMS 3.x

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft nsm-fields

01/03 2018

0.0.10

0.0.10.0

Address, telephone and email fields for CraftCMS 3.x

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft nsm-fields

19/02 2018

0.0.9

0.0.9.0

Address, telephone and email fields for CraftCMS 3.x

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft nsm-fields

01/08 2017
27/07 2017

dev-feature/name

dev-feature/name

Address, telephone and email fields for CraftCMS 3.x

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft nsm-fields

12/07 2017
06/07 2017

dev-feature/beta.20

dev-feature/beta.20

Address, telephone and email fields for CraftCMS 3.x

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft nsm-fields

05/06 2017

0.0.1

0.0.1.0

Address, telephone and email fields for CraftCMS 3.x

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft nsm-fields