1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 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: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245:
<?php
/**
* MvcCore
*
* This source file is subject to the BSD 3 License
* For the full copyright and license information, please view
* the LICENSE.md file that are distributed with this source code.
*
* @copyright Copyright (c) 2016 Tom Flidr (https://github.com/mvccore)
* @license https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
*/
namespace MvcCore\Ext\Forms\Field;
/**
* Trait for class `\MvcCore\Ext\Forms\Field` containing field configurable
* and internal properties.
*/
trait Props {
/************************************************************************************************
* Configurable Properties *
************************************************************************************************/
/**
* Form field HTML id attribute, completed from form name and field name.
* This value is completed automatically, but you can customize it.
* @var string|NULL
*/
protected $id = NULL;
/**
* Form field specific name, used to identify submitted value.
* This value is required for all form fields.
* @requires
* @var string|NULL
*/
protected $name = NULL;
/**
* Form field type, used in `<input type="...">` attribute value.
* Every typed field has it's own string value, but base field type
* `\MvcCore\Ext\Forms\Field` has `NULL`.
* @var string|NULL
*/
protected $type = NULL;
/**
* Form field value. It could be string or array, in or float, it depends
* on field implementation. Default value is `NULL`.
* @var string|array|int|float|NULL
*/
protected $value = NULL;
/**
* Form field HTML element css classes strings.
* Default value is an empty array to not render HTML `class` attribute.
* @var \string[]
*/
protected $cssClasses = [];
/**
* Field title, global HTML attribute, optional.
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#attr-title
* @var string|NULL
*/
protected $title = NULL;
/**
* Boolean to translate title text, `TRUE` by default.
* @var boolean
*/
protected $translateTitle = TRUE;
/**
* Collection with field HTML element
* additional attributes by array keys/values.
* Do not use system attributes as: `id`, `name`,
* `value`, `readonly`, `disabled`, `class` ...
* Those attributes has it's own configurable properties
* by setter methods or by constructor config array.
* HTML field elements are meant: `<input>,
* <button>, <select>, <textarea> ...`.
* Default value is an empty array to not
* render any additional attributes.
* @var array
*/
protected $controlAttrs = [];
/**
* List of predefined validator classes ending names or validator instances.
* Keys are validators ending names and values are validators ending names or instances.
* Validator class must exist in any validators namespace(s) configured by default:
* - `array('\MvcCore\Ext\Forms\Validators\');`
* Or it could exist in any other validators namespaces, configured by method(s):
* - `\MvcCore\Ext\Form::AddValidatorsNamespaces(...);`
* - `\MvcCore\Ext\Form::SetValidatorsNamespaces(...);`
* Every given validator class (ending name) or given validator instance has to
* implement interface `\MvcCore\Ext\Forms\IValidator` or it could be extended
* from base abstract validator class: `\MvcCore\Ext\Forms\Validator`.
* Every typed field has it's own predefined validators, but you can define any
* validator you want and replace them.
* @var \string[]|\MvcCore\Ext\Forms\Validator[]
*/
protected $validators = [];
/**
* Boolean `TRUE` or string with template relative path
* without `.phtml` or `.php` extension, if you want to render
* field by any custom template.
*
* If `TRUE`, path to template is completed by configured
* `\MvcCore\Ext\Forms\view::SetFieldsDir(...);` value,
* which is `/App/Views/Forms/Fields` by default.
*
* If any string with relative path given, path must be relative
* from configured `\MvcCore\Ext\Forms\view::SetFieldsDir(...);` value,
* which is again `/App/Views/Forms/Fields` by default.
*
* To render field naturally, set `FALSE`, empty string or `NULL` (`NULL` is default).
*
* Example:
* ```
* // To render field template prepared in:
* // '/App/Views/Forms/Fields/my-specials/my-field-type.phtml':
*
* \MvcCore\Ext\Forms\View::SetFieldsDir('Forms/Fields'); // by default
* $field->viewScript = 'my-specials/my-field-type';
*
* // Or you can do the same by:
* \MvcCore\Ext\Forms\View::SetFieldsDir('Forms/Fields/my-specials');
* $field->type = 'my-field-type';
* ```
* @var bool|string|NULL
*/
protected $viewScript = NULL;
/**
* Supporting javascript full javascript class name.
* If you want to use any custom supporting javascript prototyped class
* for any additional purposes for your custom field, you need to use
* `$field->jsSupportingFile` property to define path to your javascript file
* relatively from configured `\MvcCore\Ext\Form::SetJsSupportFilesRootDir(...);`
* value. Than you have to add supporting javascript file path into field form
* in `$field->PreDispatch();` method to render those files immediately after form
* (once) or by any external custom assets renderer configured by:
* `$form->SetJsSupportFilesRenderer(...);` method.
* Or you can add your custom supporting javascript files into response by your
* own and also you can run your helper javascripts also by your own. Is up to you.
* `NULL` by default.
* @var string|NULL
*/
protected $jsClassName = NULL;
/**
* Field supporting javascript file relative path.
* If you want to use any custom supporting javascript file (with prototyped
* class) for any additional purposes for your custom field, you need to
* define path to your javascript file relatively from configured
* `\MvcCore\Ext\Form::SetJsSupportFilesRootDir(...);` value.
* Than you have to add supporting javascript file path into field form
* in `$field->PreDispatch();` method to render those files immediately after form
* (once) or by any external custom assets renderer configured by:
* `$form->SetJsSupportFilesRenderer(...);` method.
* Or you can add your custom supporting javascript files into response by your
* own and also you can run your helper javascripts also by your own. Is up to you.
* `NULL` by default.
* @var string|NULL
*/
protected $jsSupportingFile = NULL;
/**
* Field supporting css file relative path.
* If you want to use any custom supporting css file
* for any additional purposes for your custom field, you need to
* define path to your css file relatively from configured
* `\MvcCore\Ext\Form::SetCssSupportFilesRootDir(...);` value.
* Than you have to add supporting css file path into field form
* in `$field->PreDispatch();` method to render those files immediately after form
* (once) or by any external custom assets renderer configured by:
* `$form->SetCssSupportFilesRenderer(...);` method.
* Or you can add your custom supporting css files into response by your
* own and also you can run your helper css also by your own. Is up to you.
* `NULL` by default.
* @var string|NULL
*/
protected $cssSupportingFile = NULL;
/**
* Boolean flag about field visible texts and error messages translation.
* This flag is automatically assigned from `$field->form->GetTranslate();`
* flag in `$field->Init();` method.
* @var bool|NULL
*/
protected $translate = NULL;
/**
* Fields (and labels) default templates
* for natural (not customized) field rendering.
* @var \stdClass
*/
protected static $templates = [
'label' => '<label for="{id}"{attrs}>{label}</label>',
'control' => '<input id="{id}" name="{name}" type="{type}" value="{value}"{attrs} />',
'togetherLabelLeft' => '<label for="{id}"{attrs}><span>{label}</span>{control}</label>',
'togetherLabelRight'=> '<label for="{id}"{attrs}>{control}<span>{label}</span></label>',
];
/************************************************************************************************
* Internal Properties *
************************************************************************************************/
/**
* Internal array with errors for rendering.
* Main errors collection is stored inside form instance.
* @var \string[]
*/
protected $errors = [];
/**
* Internal field view object, created for custom field rendering purposes,
* if property `$field->viewScript` is `TRUE` or any string with relative template path.
* @var \MvcCore\Ext\Forms\View|\MvcCore\Ext\Forms\IView
*/
protected $view = NULL;
/**
* Internal reference to form instance, where current fields is added.
* @var \MvcCore\Ext\Form
*/
protected $form = NULL;
/**
* Protected properties, which is not possible
* to configure through field constructor config array.
* @var \string[]
*/
protected static $declaredProtectedProperties = [
'view', 'form', 'translate', 'errors'
];
}