<?php
namespace Wpupgrader\Libraries\WordPress\Plugins\Core\Settings\Page\Callback;

use Wpupgrader\Libraries\WordPress\Plugins\Core\Settings\Page\Callback;

class Gravity_Forms extends Callback
{
    public function callbackAction()
    {
        if (!\class_exists('GFFormsModel')) {
            echo \__('Could not initialize the Gravity Forms plugin.');
            return;
        }

        $functionsargs = isset($args['functionargs']) ? $args['functionargs'] : [];

        $forms = \GFFormsModel::get_forms($functionsargs);

        echo '<select '.$this->getNameIdString().'>
		    		<option value="">- Selecteer een formulier -</form>';

        foreach ($forms as $form) {
            $selected = ($this->settings->options[$args['name']] == $form->id) ? ' SELECTED' : '';

            echo '<option value="'.$form->id.'"'.$selected.'>'.$form->title.'</option>';
        }

        echo '</select>';

        echo $this->getDescription();
    }
}