Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions resources/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct()
$this->defaults = [
'return_format' => 'form_object',
'multiple' => 0,
'default_value' => '',
'allow_null' => 0
];

Expand Down Expand Up @@ -63,6 +64,15 @@ public function render_field_settings($field)
],
]);

// Render a field setting that will provide the option of selecting a default form.
acf_render_field_setting( $field, array(
'label' => __('Default Form','acf'),
'instructions' => __('Choose a default form','acf'),
'name' => 'default_value',
'type' => 'select',
'choices' => $this->getFormChoices()
));

// Render a field setting that will tell us if an empty field is allowed or not.
acf_render_field_setting($field, [
'label' => __('Allow Null?', 'acf'),
Expand Down Expand Up @@ -105,9 +115,7 @@ public function render_field($field)
return false;
}

foreach ($this->forms as $form) {
$choices[$form->get_id()] = $form->get_setting('title');
}
$choices = $this->getFormChoices();

// Override field settings and start rendering
$field['choices'] = $choices;
Expand Down Expand Up @@ -250,4 +258,18 @@ public function hasValidForms()

return true;
}

/**
* Get the Ninja Form choices - normally used by select field.
*
* @return array The key value pairs for the select.
*/
protected function getFormChoices() {

$choices = [];
foreach ($this->forms as $form) {
$choices[$form->get_id()] = $form->get_setting('title');
}
return $choices;
}
}
34 changes: 31 additions & 3 deletions resources/FieldForV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct()
$this->defaults = [
'return_format' => 'form_object',
'multiple' => 0,
'default_value' => '',
'allow_null' => 0
];

Expand Down Expand Up @@ -91,6 +92,21 @@ public function create_options($field)
</td>
</tr>

<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php echo __('Default Form', 'acf'); ?></label>
</td>
<td>
<?php
do_action('acf/create_field', [
'type' => 'select',
'name' => 'fields[' . $key . '][default_value]',
'value' => $field['default_value'],
'choices' => $this->getFormChoices()
]); ?>
</td>
</tr>

<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php echo __('Allow Null?', 'acf'); ?></label>
Expand Down Expand Up @@ -150,9 +166,7 @@ public function create_field($field)
return false;
}

foreach ($this->forms as $form) {
$choices[$form['id']] = $form['title'];
}
$choices = $this->getFormChoices();

// Override field settings and start rendering
$field['choices'] = $choices;
Expand Down Expand Up @@ -192,4 +206,18 @@ public function format_value_for_api($value, $postId, $field)
$fieldObject = New Field();
return $fieldObject->processValue($value, $field);
}

/**
* Get the Ninja Form choices - normally used by select field.
*
* @return array The key value pairs for the select.
*/
protected function getFormChoices() {

$choices = [];
foreach ($this->forms as $form) {
$choices[$form['id']] = $form['title'];
}
return $choices;
}
}