PodsUI::form PHP Method

form() public method

public form ( boolean $create = false, boolean $duplicate = false ) : boolean | mixed
$create boolean
$duplicate boolean
return boolean | mixed
    public function form($create = false, $duplicate = false)
    {
        if (in_array('duplicate', $this->actions_disabled)) {
            $duplicate = false;
        }
        if (false !== $this->callback('form')) {
            return null;
        }
        $label = $this->label['add'];
        $id = null;
        $vars = array('action' . $this->num => $this->action_after['add'], 'do' . $this->num => 'create', 'id' . $this->num => 'X_ID_X');
        $alt_vars = $vars;
        $alt_vars['action'] = 'manage';
        unset($alt_vars['id']);
        if (false === $create) {
            if (empty($this->row)) {
                $this->get_row();
            }
            if (empty($this->row) && (!is_object($this->pod) || 'settings' != $this->pod->pod_data['type'])) {
                return $this->error(sprintf(__('<strong>Error:</strong> %s not found.', 'pods'), $this->item));
            }
            if ($this->restricted($this->action, $this->row)) {
                return $this->error(sprintf(__('<strong>Error:</strong> You do not have access to this %s.', 'pods'), $this->item));
            }
            $label = $this->do_template($this->label['edit']);
            $id = $this->row[$this->sql['field_id']];
            $vars = array('action' . $this->num => $this->action_after['edit'], 'do' . $this->num => 'save', 'id' . $this->num => $id);
            $alt_vars = $vars;
            $alt_vars['action'] = 'manage';
            unset($alt_vars['id']);
            if ($duplicate) {
                $label = $this->do_template($this->label['duplicate']);
                $id = null;
                $vars = array('action' . $this->num => $this->action_after['duplicate'], 'do' . $this->num => 'create', 'id' . $this->num => 'X_ID_X');
                $alt_vars = $vars;
                $alt_vars['action'] = 'manage';
                unset($alt_vars['id']);
            }
        }
        $fields = array();
        if (isset($this->fields[$this->action])) {
            $fields = $this->fields[$this->action];
        }
        if (is_object($this->pod)) {
            $object_fields = (array) pods_var_raw('object_fields', $this->pod->pod_data, array(), null, true);
            if (empty($object_fields) && in_array($this->pod->pod_data['type'], array('post_type', 'taxonomy', 'media', 'user', 'comment'))) {
                $object_fields = $this->pod->api->get_wp_object_fields($this->pod->pod_data['type'], $this->pod->pod_data);
            }
            if (empty($fields)) {
                // Add core object fields if $fields is empty
                $fields = array_merge($object_fields, $this->pod->fields);
            }
        }
        $form_fields = $fields;
        // Temporary
        $fields = array();
        foreach ($form_fields as $k => $field) {
            $name = $k;
            $defaults = array('name' => $name);
            if (!is_array($field)) {
                $name = $field;
                $field = array('name' => $name);
            }
            $field = array_merge($defaults, $field);
            $field['name'] = trim($field['name']);
            $default_value = pods_var_raw('default', $field);
            $value = pods_var_raw('value', $field);
            if (empty($field['name'])) {
                $field['name'] = trim($name);
            }
            if (isset($object_fields[$field['name']])) {
                $field = array_merge($field, $object_fields[$field['name']]);
            } elseif (isset($this->pod->fields[$field['name']])) {
                $field = array_merge($this->pod->fields[$field['name']], $field);
            }
            if (pods_var_raw('hidden', $field, false, null, true)) {
                $field['type'] = 'hidden';
            }
            $fields[$field['name']] = $field;
            if (empty($this->id) && null !== $default_value) {
                $this->pod->row_override[$field['name']] = $default_value;
            } elseif (!empty($this->id) && null !== $value) {
                $this->pod->row[$field['name']] = $value;
            }
        }
        unset($form_fields);
        // Cleanup
        $fields = $this->do_hook('form_fields', $fields, $this->pod);
        $pod =& $this->pod;
        $thank_you = pods_query_arg($vars, self::$allowed, $this->exclusion());
        $thank_you_alt = pods_query_arg($alt_vars, self::$allowed, $this->exclusion());
        $obj =& $this;
        $singular_label = $this->item;
        $plural_label = $this->items;
        if (is_object($this->pod) && 'settings' == $this->pod->pod_data['type'] && 'settings' == $this->style) {
            pods_view(PODS_DIR . 'ui/admin/form-settings.php', compact(array_keys(get_defined_vars())));
        } else {
            pods_view(PODS_DIR . 'ui/admin/form.php', compact(array_keys(get_defined_vars())));
        }
    }