basic.inc in Display Suite 6.3
File
plugins/ds_field/basic.inc
View source
<?php
$plugin = array(
'type' => DS_FIELD_TYPE_BASIC,
'name' => t('Basic field'),
'description' => t('Basic field handler on which all others are based.'),
'class' => 'dsField',
);
class dsField {
public $key;
public $content;
public $settings = array();
protected $attributes = array();
public function setting($key, $value) {
$this->settings[$key] = $value;
}
protected function defaults() {
return array();
}
public function initialise($settings) {
$defaults = array(
'labelformat' => DS_DEFAULT_LABEL_FORMAT,
'label' => '',
'theme' => DS_DEFAULT_THEME_FIELD,
'weight' => DS_DEFAULT_WEIGHT,
'content' => NULL,
);
$type_defaults = array_merge($defaults, $this
->defaults());
$this->settings = array_merge($type_defaults, $settings);
}
function build() {
$classes = array();
$classes[] = 'field-' . strtr($field_key, '_', '-');
if (isset($field_settings['properties']['css-class']) && !empty($field_settings['properties']['css-class'])) {
$classes[] = $field_settings['properties']['css-class'];
unset($field_settings['properties']['css-class']);
}
if (isset($field_settings['css-class']) && !empty($field_settings['css-class'])) {
$classes[] = $field_settings['css-class'];
unset($field_settings['css-class']);
}
$field_defaults = array(
'labelformat' => DS_DEFAULT_LABEL_FORMAT,
'label' => '',
'theme' => DS_DEFAULT_THEME_FIELD,
'weight' => DS_DEFAULT_WEIGHT,
'content' => NULL,
);
$field = array_merge($field_defaults, $field_settings);
$field['key'] = $field_key;
$field['type'] = empty($field_settings) ? 'other' : 'ds';
if (isset($field_settings['weight'])) {
$field['weight'] = $field_settings['weight'];
}
$field['parent'] = isset($field_settings['parent']) ? $field_settings['parent'] : NULL;
if ($field['field_type'] == DS_FIELD_TYPE_GROUP || $field['field_type'] == DS_FIELD_TYPE_MULTIGROUP) {
if (isset($field_settings['format'])) {
$field['theme'] = $field_settings['format'];
}
else {
$field['theme'] = DS_DEFAULT_THEME_FIELDSET;
}
if ($field_settings['field_type'] == DS_FIELD_TYPE_GROUP) {
$classes[] = 'field-group';
}
if ($field_settings['field_type'] == DS_FIELD_TYPE_MULTIGROUP) {
$field['subgroup_theme'] = isset($field_settings['subgroup_format']) ? $field_settings['subgroup_format'] : DS_DEFAULT_THEME_FIELDSET;
$classes[] = 'field-multigroup';
}
}
$field['class'] = implode(' ', $classes);
if (isset($field_settings['label_value']) && $field['labelformat'] != DS_DEFAULT_LABEL_FORMAT) {
$field['title'] = t(check_plain($field_settings['label_value']));
}
$field['key'] = $field_key;
switch ($field['field_type']) {
case DS_FIELD_TYPE_PREPROCESS:
case DS_FIELD_TYPE_IGNORE:
if (isset($field_settings['properties']['key']) && !empty($field_settings['properties']['key'])) {
$field['preprocess_settings'] = array(
'type' => $field['type'],
'key' => $field['properties']['key'],
);
}
else {
$field['preprocess_settings'] = array(
'type' => $field['type'],
);
}
break;
case DS_FIELD_TYPE_CODE:
$field['formatter'] = isset($field['format']) ? $field['format'] : 'ds_eval_code';
break;
case DS_FIELD_TYPE_BLOCK:
$field['formatter'] = 'ds_eval_block';
break;
case DS_FIELD_TYPE_FUNCTION:
$field['function'] = isset($field_settings['format']) ? $field_settings['format'] : key($field_settings['properties']['formatters']);
break;
case DS_FIELD_TYPE_THEME:
$field['formatter'] = isset($field_settings['format']) ? $field_settings['format'] : key($field_settings['properties']['formatters']);
break;
}
$field['content'] = ds_field_format_content($field);
return $field;
}
function getContent($content_vars = array(), $vars_key = NULL) {
if (!empty($this->content)) {
return $this->content;
}
if (empty($vars_key)) {
$vars_key = $this->key;
}
if (!empty($content_vars)) {
if (isset($content_vars[$vars_key . '_rendered'])) {
$this->content = $content_vars[$vars_key . '_rendered'];
}
elseif (isset($content_vars[$vars_key])) {
$this->content = $content_vars[$vars_key];
}
}
if (!empty($this->content)) {
return $this->content;
}
return FALSE;
}
public function formatContent() {
return filter_xss($this->content);
}
public function render() {
if (empty($this->settings['theme'])) {
$this->settings['theme'] = DS_DEFAULT_THEME_FIELD;
}
$this->content = theme($this->settings['theme'], $this);
if (isset($this->content) && strlen($this->content) > 0) {
return $this->content;
}
return FALSE;
}
}