Microweber\Providers\FieldsManager::make PHP Method

make() public method

make_field.
Author: Microweber
public make ( string $field_id, string $field_type = 'text', array $settings = false )
$field_id string
$field_type string
$settings array
    public function make($field_id = 0, $field_type = 'text', $settings = false)
    {
        if (is_array($field_id)) {
            if (!empty($field_id)) {
                $data = $field_id;
            }
        } else {
            if ($field_id != 0) {
                $data = $this->get_by_id($id = $field_id);
            }
        }
        if (isset($data['settings']) or isset($_REQUEST['settings']) and trim($_REQUEST['settings']) == 'y') {
            $settings = true;
        }
        if (isset($data['copy_from'])) {
            $copy_from = intval($data['copy_from']);
            if (is_admin() == true) {
                $table_custom_field = $this->table;
                $form_data = $this->app->database_manager->get_by_id($table_custom_field, $id = $copy_from);
                if (is_array($form_data)) {
                    $field_type = $form_data['type'];
                    $data['id'] = 0;
                    if (isset($data['save_on_copy'])) {
                        $cp = $form_data;
                        $cp['id'] = 0;
                        $cp['copy_of_field'] = $copy_from;
                        if (isset($data['rel_type'])) {
                            $cp['rel_type'] = $data['rel_type'];
                        }
                        if (isset($data['rel_id'])) {
                            $cp['rel_id'] = $data['rel_id'];
                        }
                        $this->save($cp);
                        $data = $cp;
                    } else {
                        $data = $form_data;
                    }
                }
            }
        } elseif (isset($data['field_id'])) {
            $data = $this->get_by_id($id = $data['field_id']);
        }
        if (isset($data['type'])) {
            $field_type = $data['type'];
        }
        if (!isset($data['custom_field_required'])) {
            $data['custom_field_required'] = 'n';
        }
        if (isset($data['type'])) {
            $field_type = $data['type'];
        }
        if (isset($data['field_type'])) {
            $field_type = $data['field_type'];
        }
        if (isset($data['field_values']) and !isset($data['value'])) {
            $data['values'] = $data['field_values'];
        }
        $data['type'] = $field_type;
        if (isset($data['options']) and is_string($data['options'])) {
            $data['options'] = $this->_decode_options($data['options']);
        }
        $data = $this->app->url_manager->replace_site_url_back($data);
        $dir = mw_includes_path();
        $dir = $dir . DS . 'custom_fields' . DS;
        $field_type = str_replace('..', '', $field_type);
        $load_from_theme = false;
        if (defined('ACTIVE_TEMPLATE_DIR')) {
            $custom_fields_from_theme = ACTIVE_TEMPLATE_DIR . 'modules' . DS . 'custom_fields' . DS;
            if (is_dir($custom_fields_from_theme)) {
                if ($settings == true or isset($data['settings'])) {
                    $file = $custom_fields_from_theme . $field_type . '_settings.php';
                } else {
                    $file = $custom_fields_from_theme . $field_type . '.php';
                }
                if (is_file($file)) {
                    $load_from_theme = true;
                }
            }
        }
        if ($load_from_theme == false) {
            if ($settings == true or isset($data['settings'])) {
                $file = $dir . $field_type . '_settings.php';
            } else {
                $file = $dir . $field_type . '.php';
            }
        }
        if (!is_file($file)) {
            $field_type = 'text';
            if ($settings == true or isset($data['settings'])) {
                $file = $dir . $field_type . '_settings.php';
            } else {
                $file = $dir . $field_type . '.php';
            }
        }
        $file = normalize_path($file, false);
        if (is_file($file)) {
            $l = new \Microweber\View($file);
            //
            $l->assign('settings', $settings);
            if (isset($data['params'])) {
                $l->assign('params', $data['params']);
            } else {
                $l->assign('params', false);
            }
            //  $l->settings = $settings;
            if (isset($data) and !empty($data)) {
                $l->data = $data;
            } else {
                $l->data = array();
            }
            $l->assign('data', $data);
            $layout = $l->__toString();
            return $layout;
        }
    }