function _enfactor_field($field, $mb, $in_group = false) { $is_multi = VP_Util_Reflection::is_multiselectable($field['type']); if (!$is_multi) { $mb->the_field($field['name']); } else { $mb->the_field($field['name'], WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); } $field['name'] = $mb->get_the_name(); // create the object $make = VP_Util_Reflection::field_class_from_type($field['type']); $vp_field = call_user_func("{$make}::withArray", $field); // get value from mb $value = $mb->get_the_value(); // get default from array $default = $vp_field->get_default(); // if tocopy always assign default if ($mb->is_parent_multi() and $mb->is_in_multi_last()) { $value = $default; } else { // if value is null and default exist, use default if (is_null($value) and !is_null($default) and empty($this->meta)) { $value = $default; } else { if (VP_Util_Reflection::is_multiselectable($field['type'])) { if (!is_array($value)) { $value = array($value); } } } } $vp_field->set_value($value); if (!$in_group) { $vp_field->add_container_extra_classes(array('vp-meta-single')); } return $vp_field; }
function print_form($attributes) { ?> <div class="vp-sc-fields"> <?php foreach ($attributes as $attr) { // create the object $make = VP_Util_Reflection::field_class_from_type($attr['type']); // prefix name $attr['name'] = '_' . $attr['name']; $field = call_user_func("{$make}::withArray", $attr); $default = $field->get_default(); if (!is_null($default)) { $field->set_value($default); } ?> <?php if ($attr['type'] !== 'notebox') { ?> <div class="vp-sc-field vp-<?php echo $attr['type']; ?> " data-vp-type="vp-<?php echo $attr['type']; ?> "> <div class="label"><label><?php echo $attr['label']; ?> </label></div> <div class="field"><div class="input"><?php echo $field->render(true); ?> </div></div> </div> <?php } else { ?> <?php $status = isset($attr['status']) ? $attr['status'] : 'normal'; ?> <div class="vp-sc-field vp-<?php echo $attr['type']; ?> note-<?php echo $status; ?> " data-vp-type="vp-<?php echo $attr['type']; ?> "> <?php echo $field->render(true); ?> </div> <?php } ?> <?php } ?> </div> <div class="vp-sc-action"> <button class="vp-sc-insert button"><?php _e('Insert', 'vp_textdomain'); ?> </button> <button class="vp-sc-cancel button"><?php _e('Cancel', 'vp_textdomain'); ?> </button> </div> <?php }
/** * Output the settings update form. * * @see WP_Widget::form * @param array $instance Current settings. * * @access public * @return string */ public function form($instance) { foreach ($this->controls as $control) { $control->addHtmlAttribute('id', $this->get_field_id($control->getName())); $control->addHtmlAttribute('class', 'widefat'); $attributes = $control->getSettings(); $attributes['name'] = $this->get_field_name($control->getName()); // create field object $make = \VP_Util_Reflection::field_class_from_type($attributes['type']); $field = call_user_func("{$make}::withArray", $attributes); $default = $field->get_default(); //@todo rebuild this!!! if ($attributes['type'] == 'checkbox') { $value = isset($instance[$control->getName()]) ? $instance[$control->getName()] : ''; $field->set_value($value); } else { if (isset($instance[$control->getName()]) && !empty($instance[$control->getName()])) { $field->set_value($instance[$control->getName()]); } else { if (!is_null($default)) { $field->set_value($default); } } } ?> <p> <label for="<?php echo $this->get_field_id($field->get_name()); ?> "> <?php echo $field->get_label(); ?> <?php echo $field->render(true); ?> <?php \VP_Util_Text::print_if_exists($field->get_description(), '<div class="description">%s</div>'); ?> </label> </p> <?php } }
private function parse_field($field) { if (sh_set($field, 'type') == 'group') { foreach ($field['fields'] as $f) { //printr($f); $this->parse_field($f); } } else { $class = VP_Util_Reflection::field_class_from_type($field['type']); $vp_field = call_user_func("{$class}::withArray", $field); return $vp_field; } }
private function parse_field($field) { $class = VP_Util_Reflection::field_class_from_type($field['type']); $vp_field = call_user_func("{$class}::withArray", $field); return $vp_field; }