Unknown.php 1.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Class NF_Fields_Unknown
 */
class NF_Fields_Unknown extends NF_Fields_Hidden
{
    protected $_name = 'unknown';

    protected $_type = 'unknown';

    protected $_section = '';

    protected $_icon = 'question';

16 17
    protected $_templates = 'null';

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    protected $_aliases = array();

    protected $_settings_only = array(
        'label', 'default'
    );

    public function __construct()
    {
        parent::__construct();

        $this->_nicename = __( 'Unknown', 'ninja-forms' );

        $this->_settings[ 'message' ] = array(
            'name' => 'message',
            'type' => 'html',
            'label' => '',
            'width' => 'full',
            'group' => 'primary',
        );

        $this->_settings[ 'label' ][ 'group' ] = '';

        unset( $this->_settings[ 'default' ] ); // TODO: Seeing an error when removing default form the $_settings_only property, so just unsetting it here for now.

        add_filter( 'nf_sub_hidden_field_types', array( $this, 'hide_field_type' ) );
    }

45 46 47 48 49
    public function validate( $field, $data )
    {
        return array(); // Return empty array with no errors.
    }

50 51 52 53 54 55 56 57 58 59 60 61 62
    function hide_field_type( $field_types )
    {
        $field_types[] = $this->_name;
        return $field_types;
    }

    public static function create( $field )
    {
        $unknown = Ninja_Forms()->form()->field()->get();
        $unknown->update_settings(array(
            'id'      => $field->get_id(),
            'label'   => $field->get_setting( 'label' ),
            'order'   => $field->get_setting( 'order' ),
63
            'key'     => $field->get_setting( 'key' ),
64 65 66 67 68 69
            'type'    => 'unknown',
            'message' => sprintf( __( 'Field type "%s" not found.', 'ninja-forms' ), $field->get_setting( 'type' ) )
        ));
        return $unknown;
    }
}