Cuztom_Meta::build PHP Method

build() public method

This array builds the complete array with the right key => value pairs
Since: 1.1
Author: Gijs Jorissen
public build ( array $data, $parent = null ) : array
$data array
return array
    function build($data, $parent = null)
    {
        $return = array();
        if (is_array($data) && !empty($data)) {
            if (self::is_tabs($data) || self::is_accordion($data)) {
                $tabs = self::is_tabs($data) ? new Cuztom_Tabs($this->id) : new Cuztom_Accordion($this->id);
                $tabs->meta_type = $this->get_meta_type();
                foreach ($data[1] as $title => $fields) {
                    $tab = new Cuztom_Tab($title);
                    $tab->meta_type = $this->get_meta_type();
                    if (isset($fields[0]) && self::is_bundle($fields[0])) {
                        $tab->fields = $this->build($fields[0]);
                    } else {
                        foreach ($fields as $field) {
                            $class = 'Cuztom_Field_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $field['type'])));
                            if (class_exists($class)) {
                                $field = new $class($field, $this->id);
                                $field->meta_type = $this->get_meta_type();
                                $this->fields[$field->id] = $field;
                                $tab->fields[$field->id] = $field;
                            }
                        }
                    }
                    $tabs->tabs[$title] = $tab;
                }
                $return = $tabs;
            } elseif (self::is_bundle($data)) {
                $bundle = new Cuztom_Bundle($this->id, $data);
                foreach ($data[1] as $field) {
                    $class = 'Cuztom_Field_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $field['type'])));
                    if (class_exists($class)) {
                        $field = new $class($field, '');
                        //$field->repeatable 		= false;
                        $field->ajax = false;
                        $field->meta_type = $this->get_meta_type();
                        $field->in_bundle = true;
                        $this->fields[$field->id] = $field;
                        $bundle->fields[$field->id] = $field;
                        $bundle->meta_type = $this->get_meta_type();
                    }
                }
                $return = $bundle;
            } else {
                foreach ($data as $field) {
                    $class = 'Cuztom_Field_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $field['type'])));
                    if (class_exists($class)) {
                        $field = new $class($field, $this->id);
                        $field->meta_type = $this->get_meta_type();
                        $this->fields[$field->id] = $field;
                        $return[$field->id] = $field;
                    }
                }
            }
        }
        return $return;
    }