name = 'forms';
$this->label = __('Gravity Form', 'gravityforms');
$this->category = __('Relational', 'acf'); // Basic, Content, Choice, etc
$this->defaults = [
'return_format' => 'form_object',
'multiple' => 0,
'allow_null' => 0
];
// Get our notices up and running
$this->notices = new Notices();
// Execute the parent constructor as well
parent::__construct();
}
/**
* Create extra settings for our gravityforms field. These are visible when editing a field.
*
* @param $field
*/
public function create_options($field)
{
// defaults?
$field = array_merge($this->defaults, $field);
// key is needed in the field names to correctly save the data
$key = $field['name'];
// Create Field Options HTML
?>
forms = GFFormsModel::get_forms(true, false, 'title');
}
// Set our defaults
$field = array_merge($this->defaults, $field);
$choices = [];
// Check if we have some valid forms
$fieldObject = new Field();
if (!$fieldObject->hasValidForms()) {
return false;
}
foreach ($this->forms as $form) {
$choices[$form->id] = $form->title;
}
// Override field settings and start rendering
$field['choices'] = $choices;
$field['type'] = 'select';
do_action('acf/create_field', $field);
}
/**
* This filter is applied to the $value before it is updated in the db
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
public function update_value($value, $post_id, $field)
{
// Strip empty array values
if (is_array($value)) {
$value = array_values(array_filter($value));
}
return $value;
}
/**
* Return a form object when not empty
*
* @param $value
* @param $postId
* @param $field
* @return array|bool
*/
public function format_value_for_api($value, $postId, $field)
{
$fieldObject = new Field();
return $fieldObject->processValue($value, $field);
}
}