$value) { if(isset($this->config[$key]) || in_array($key, $this->keepconfig)) { $this->config[$key] = $value; } } } $this->initTransConfig(); $this->label = $label; $this->ismulti = (bool) $ismulti; $this->tid = $tid; } /** * Add the translatable keys to the configuration * * This checks if a configuration for the translation plugin exists and if so * adds all configured languages to the config array. This ensures all types * can have translatable labels. */ protected function initTransConfig() { global $conf; $lang = $conf['lang']; if(isset($conf['plugin']['translation']['translations'])) { $lang .= ' ' . $conf['plugin']['translation']['translations']; } $langs = explode(' ', $lang); $langs = array_map('trim', $langs); $langs = array_filter($langs); $langs = array_unique($langs); if(!isset($this->config['label'])) $this->config['label'] = array(); if(!isset($this->config['hint'])) $this->config['hint'] = array(); // initialize missing keys foreach($langs as $lang) { if(!isset($this->config['label'][$lang])) $this->config['label'][$lang] = ''; if(!isset($this->config['hint'][$lang])) $this->config['hint'][$lang] = ''; } // strip unknown languages foreach(array_keys($this->config['label']) as $key) { if(!in_array($key, $langs)) unset($this->config['label'][$key]); } foreach(array_keys($this->config['hint']) as $key) { if(!in_array($key, $langs)) unset($this->config['hint'][$key]); } } /** * Returns data as associative array * * @return array */ public function getAsEntry() { return array( 'config' => json_encode($this->config), 'label' => $this->label, 'ismulti' => $this->ismulti, 'class' => $this->getClass() ); } /** * The class name of this type (no namespace) * @return string */ public function getClass() { return substr(get_class($this), 20); } /** * Return the current configuration for this type * * @return array */ public function getConfig() { return $this->config; } /** * @return boolean */ public function isMulti() { return $this->ismulti; } /** * @return string */ public function getLabel() { return $this->label; } /** * Returns the translated label for this type * * Uses the current language as determined by $conf['lang']. Falls back to english * and then to the Schema label * * @return string */ public function getTranslatedLabel() { global $conf; $lang = $conf['lang']; if(!blank($this->config['label'][$lang])) { return $this->config['label'][$lang]; } if(!blank($this->config['label']['en'])) { return $this->config['label']['en']; } return $this->label; } /** * Returns the translated hint for this type * * Uses the current language as determined by $conf['lang']. Falls back to english. * Returns empty string if no hint is configured * * @return string */ public function getTranslatedHint() { global $conf; $lang = $conf['lang']; if(!blank($this->config['hint'][$lang])) { return $this->config['hint'][$lang]; } if(!blank($this->config['hint']['en'])) { return $this->config['hint']['en']; } return ''; } /** * @return int */ public function getTid() { return $this->tid; } /** * @throws StructException * @return Column */ public function getContext() { if(is_null($this->context)) throw new StructException('Empty column context requested. Type was probably initialized outside of Schema.'); return $this->context; } /** * @param Column $context */ public function setContext($context) { $this->context = $context; } /** * Split a single value into multiple values * * This function is called on saving data when only a single value instead of an array * was submitted. * * Types implementing their own @see multiValueEditor() will probably want to override this * * @param string $value * @return array */ public function splitValues($value) { return array_map('trim', explode(',', $value)); } /** * Return the editor to edit multiple values * * Types can override this to provide a better alternative than multiple entry fields * * @param string $name the form base name where this has to be stored * @param string[] $values the current values * @return string html */ public function multiValueEditor($name, $values) { $html = ''; foreach($values as $value) { $html .= '