xddesigners/iconselectfield

Adds a configurable icon select field

Installs: 175

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

dev-main 2023-10-06 07:53 UTC

This package is auto-updated.

Last update: 2024-12-06 10:22:01 UTC


README

Add a icon select field to the Silverstripe CMS.

Installation

composer require xddesigners/iconselectfield

Usage

Add a icon field to your db. This field will automaticly scaffold a IconSelectField.

class YourClass extends DataObject
{
  private static $db = [
    'Icon' => 'Icon'
  ];

  public function getCMSFields()
  {
    $fields = parent::getCMSFields();
    $fields->addFieldsToTab('Root.Main', [
      // this field is automaticly scaffolded
      IconSelectField::create('Icon', 'Icon')
    ]);

    $fields;
  }
}

In your template you can now access the Icon property and this will be replaced by the selected icon.

$Icon

You can confugure the icons you want to use trough a yml config.

---
Name: vivabasicIcons
---
XD\IconSelectField\Forms\IconSelectField:
  fonts_include:
  # add your own link to a font awesome version your using
    - '<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.12.1/css/all.css" crossorigin="anonymous">'
  icons:
    system:
      arrow-right: 'fas fa-arrow-right'
      arrow-left: 'fas fa-arrow-left'
      custom-icon: '<svg />' # you can also configure custom svg icons