/** * Return array of fields' id and label, for a given Form ID * * @access public * @param string|array $form_id (default: '') or $form object * @param bool $add_default_properties * @param bool $include_parent_field * @return array */ public static function get_form_fields($form = '', $add_default_properties = false, $include_parent_field = true) { if (!is_array($form)) { $form = self::get_form($form); } $fields = array(); $has_product_fields = false; $has_post_fields = false; if ($form) { foreach ($form['fields'] as $field) { if ($include_parent_field || empty($field['inputs'])) { $fields["{$field->id}"] = array('label' => rgar($field, 'label'), 'parent' => null, 'type' => rgar($field, 'type'), 'adminLabel' => rgar($field, 'adminLabel'), 'adminOnly' => rgar($field, 'adminOnly')); } if ($add_default_properties && !empty($field->inputs)) { foreach ($field->inputs as $input) { /** * @hack * In case of email/email confirmation, the input for email has the same id as the parent field */ if ('email' === $field->type && false === strpos($input['id'], '.')) { continue; } $fields["{$input['id']}"] = array('label' => rgar($input, 'label'), 'customLabel' => rgar($input, 'customLabel'), 'parent' => $field, 'type' => rgar($field, 'type'), 'adminLabel' => rgar($field, 'adminLabel'), 'adminOnly' => rgar($field, 'adminOnly')); } } if (GFCommon::is_product_field($field->type)) { $has_product_fields = true; } if (GFCommon::is_post_field($field)) { $has_post_fields = true; } } } /** * @since 1.7 */ if ($has_post_fields) { $fields['post_id'] = array('label' => __('Post ID', 'gravityview'), 'type' => 'post_id'); } if ($has_product_fields) { $payment_fields = GravityView_Fields::get_all('pricing'); foreach ($payment_fields as $payment_field) { if (isset($fields["{$payment_field->name}"])) { continue; } $fields["{$payment_field->name}"] = array('label' => $payment_field->label, 'desc' => $payment_field->description, 'type' => $payment_field->name); } } /** * @filter `gravityview/common/get_form_fields` Modify the form fields shown in the Add Field field picker. * @since 1.17 * @param array $fields Associative array of fields, with keys as field type, values an array with the following keys: (string) `label` (required), (string) `type` (required), `desc`, (string) `customLabel`, (GF_Field) `parent`, (string) `adminLabel`, (bool)`adminOnly` * @param array $form GF Form array * @param bool $include_parent_field Whether to include the parent field when getting a field with inputs */ $fields = apply_filters('gravityview/common/get_form_fields', $fields, $form, $include_parent_field); return $fields; }