GrafiteInc/Forms

View on GitHub
src/Commands/stubs/field.stub

Summary

Maintainability
Test Coverage
<?php

namespace DummyNamespace;

use Grafite\Forms\Fields\Field;

class DummyClass extends Field
{
    /**
     * Input type
     *
     * @return string
     */
    protected static function getType()
    {
        return 'text';
    }

    /**
     * Input attributes
     *
     * @return array
     */
    protected static function getAttributes()
    {
        return [];
    }

    /**
     * Field maker options
     *
     * @return array
     */
    protected static function getOptions()
    {
        return [];
    }

    /**
     * View path for a custom template
     *
     * @return mixed
     */
    protected static function getView()
    {
        return null;
    }

    /**
     * Field template string, performs a basic string swap
     * of name, id, field, label, errors etc
     *
     * @return string
     */
    public static function getTemplate($options)
    {
        return null;
    }

    /**
     * Field related scripts
     *
     * @param array $options
     * @return array
     */
    public static function scripts($options)
    {
        return [];
    }

    /**
     * The onload method call for when FormsJS loads
     *
     * @param integer $id
     * @param array $options
     * @return string
     */
    public static function onLoadJs($id, $options)
    {
        return '_formsjs_DummyClass';
    }

    /**
     * The config details passed to the field for its onload method call
     *
     * @param integer $id
     * @param array $options
     * @return string
     */
    public static function onLoadJsData($id, $options)
    {
        return json_encode([]);
    }

    /**
     * Field related JavaScript for onload call
     *
     * @param integer $id
     * @param array $options
     * @return string|null
     */
    public static function js($id, $options)
    {
        return <<<JS
            _formsjs_DummyClass = function (element) {
                // Get the config from the element
                let _config = JSON.parse(element.getAttribute('data-formsjs-onload-data'));

                // this is code to run on the element AFTER its been rendered
                // this is where you could add further bindings etc
                if (! element.getAttribute('data-formsjs-rendered')) {
                    // put JS code here
                }
            }
        JS;
    }

    /**
     * Field related stylesheets
     *
     * @param array $options
     * @return array
     */
    public static function stylesheets($options)
    {
        return [];
    }

    /**
     * Field related styles
     *
     * @param string $id
     * @param array $options
     * @return string|null
     */
    public static function styles($id, $options)
    {
        return null;
    }
}