__('Icon', __FILE__), // Module Title 'summary' => __('Select an icon', __FILE__), // Module Summary 'version' => 3, ); } const prefix = 'fa-'; protected $options = array(); /** * Construct * */ public function __construct() { parent::__construct(); $this->options = file(__DIR__ . '/icons.inc', FILE_IGNORE_NEW_LINES); $this->set('prefixValue', true); // should value attr always start with prefix? (externally) } /** * Init * */ public function init() { parent::init(); $this->icon = 'puzzle-piece'; } /** * Render * * @return string * */ public function ___render() { $out = ''; $attrs = $this->getAttributes(); $value = $attrs['value']; if($value && strpos($value, self::prefix) !== 0) $value = self::prefix . $value; if($value) $this->icon = $value; unset($attrs['value']); $out .= " "; $out .= "" . "" . "" . $this->_('Show All Icons') . "" . "
"; return $out; } /** * Set attribute * * @param array|string $key * @param array|bool|int|string $value * @return Inputfield * */ public function setAttribute($key, $value) { if($key === 'value' && !empty($value)) { if(strpos($value, self::prefix) !== 0) $value = self::prefix . $value; $index = array_search($value, $this->options); if(is_int($index)) { $value = $this->options[$index]; } else { $value = ''; } } return parent::setAttribute($key, $value); } /** * Get attribute * * @param string $key * @return bool|mixed|null|string * */ public function getAttribute($key) { if($key === 'value') { $value = parent::getAttribute($key); if(empty($value)) return $value; if($this->getSetting('prefixValue')) { if(strpos($value, self::prefix) !== 0) { // add prefix $value = self::prefix . $value; } } else { if(strpos($value, self::prefix) === 0) { // remove prefix $value = substr($value, strlen(self::prefix)); } } return $value; } return parent::getAttribute($key); } }