Skip to content

Font Awesome (fontawesome) 6.x icon picker for Silverstripe 4.x

Notifications You must be signed in to change notification settings

bitwingsde/silverstripe-fa-picker

 
 

Repository files navigation

Font Awesome Icon Picker

Adds a Font Awesome 6.x icon picker to SilverStripe 4. This uses the CDN for Fontawesome 6.2.0. This will work with Fontawesome 6.2.0 pro out-of-the-box (but you will need to have a copy of the kit).

With the Free version of Font Awesome

Starts out slim:
Overview of Image Cropper Field
Expands to allow you to seach for your desired icon: Overview of Image Cropper Field
A list of your recently toggled icons:
Overview of Image Cropper Field

With the Pro version of Font Awesome

Everything that you can do in the free version, you can do in the pro version. The pro version however comes with more options.

When enabled, Light and Duotone icon styles are unlocked: Overview of Image Cropper Field

Sharp icons, by default, are enabled when you switch to pro: Overview of Image Cropper Field

Requirements

  • SilverStripe 4.x

Installation

Installation is supported via composer only

composer require buckleshusky/fontawesomeiconpicker
  • Run dev/build?flush=all to regenerate the manifest

Usage

Simply add the field to a DataObject or Page like you normally would. This will save the Font Awesome Icon's class info to a dbfield for use on the front end.

use BucklesHusky\FontAwesomeIconPicker\Forms\FAPickerField;
use SilverStripe\ORM\DataObject;

class TestDataObject extends DataObject
{
    private static $table_name = "TestDataObject";

    private static $db = [
        'FAIcon' => 'Varchar(255)',
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $fields->addFieldToTab(
            'Root.Main',
            FAPickerField::create('FAIcon', 'Font Awesome Icon\'s Name')
        );

        return $fields;
    }
}

If needed, you can add the following to your PageController or any page controller that extends PageController. This can be added to the init() method like below:

protected function init()
{
    parent::init();

    // get the requirements to render fontawesome icons
    $this->fontAwesome();
}

Notes

The field has not been tested for use on the frontend of a site.

Settings

Enable Font Awesome Pro
To enable Font Awesome Pro, add this to your yml file.
Replace all.min.css and sharp-solid.min.css with the Font Awesome Pro css name.
These files should be located in your theme's css folder.

# settings for FontawesomeIcons
FontawesomeIcons:
  unlock_pro_mode: true
  pro_css: 'all.min.css'
  pro_sharp_css: 'sharp-solid.min.css' # not needed if sharp is disabled

Options:

Option Description Values default
free_css_cdn_version for the FREE version. This is the version to get from the fontawesome CDN. This can be used to get the new version. You will still need a copy of icon-families.yml. the version to get from the CDN 6.2.0
unlock_pro_mode enable this to switch to PRO version true/false false
disable_sharp_icons with this enabled, the sharp icons will not be loaded. pro_sharp_css will also not be required. true/false false
pro_css the name of the PRO version css file string
pro_sharp_css the name of the PRO version sharp css file string

How to setup the PRO version of fontawesome?

  • You will need to download a kit from the fontawesome site.
  • Grab the css file for all.min.css and sharp-solid.min.css and place it in your theme's css folder.
  • Grab the webfonts folder and place it in your theme's folder. Example themes\simple.
  • update your config:
    FontawesomeIcons:
        unlock_pro_mode: false
        # the css of all and sharp-solid
        pro_css: 'all.min.css'
        # not needed if sharp is disabled
        pro_sharp_css: 'sharp-solid.min.css'

How do I use a newer version of Fontawesome?

  • Get a copy of icon-families.yml.
    • You can obtain this from their github.
  • Place this file into your app\_config folder.
  • Open the file.
  • Indent everything in the file by 2 spaces and save.
  • Add the following to the top of the file
---
name: my-icon-list
after: buckleshusky-fontawesomeiconpicker-icons
---
FontawesomeIconsList:
  • Your file should look something like the following:
---
name: my-icon-list
after: buckleshusky-fontawesomeiconpicker-icons
---
FontawesomeIconsList-disable:
  '0':
    changes:
      - 6.0.0-beta1
      - 6.2.0
    familyStylesByLicense:
      free:
[...]
  • For the FREE version:
    • add the following to your yml with the desired version you would like from the CDN:
    FontawesomeIcons:
      free_css_cdn_version: '6.3.0'
  • For the PRO version:
    • follow the steps above for How to setup the PRO version of fontawesome?

What's New

  • updated to support 6.x
  • improved icon search
  • uses icon-families.yml (with a small customization), to create the icon list
  • added support for sharp icons

Future

  • add back in removing icons
    • removed for now to clean this up and get it released
  • add documentation for adding your own icons
  • dynamic generating of style types

About

Font Awesome (fontawesome) 6.x icon picker for Silverstripe 4.x

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 67.0%
  • PHP 23.0%
  • SCSS 9.9%
  • Scheme 0.1%