1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 3.0.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\View\Form;
16:
17: /**
18: * Interface for FormHelper context implementations.
19: *
20: * @method string|null getRequiredMessage($field) Gets the default "required" error message for a field
21: * @method int|null getMaxLength($field) Get maximum length of a field from model validation
22: */
23: interface ContextInterface
24: {
25:
26: /**
27: * Get the fields used in the context as a primary key.
28: *
29: * @return array
30: */
31: public function primaryKey();
32:
33: /**
34: * Returns true if the passed field name is part of the primary key for this context
35: *
36: * @param string $field A dot separated path to the field a value
37: * is needed for.
38: * @return bool
39: */
40: public function isPrimaryKey($field);
41:
42: /**
43: * Returns whether or not this form is for a create operation.
44: *
45: * @return bool
46: */
47: public function isCreate();
48:
49: /**
50: * Get the current value for a given field.
51: *
52: * Classes implementing this method can optionally have a second argument
53: * `$options`. Valid key for `$options` array are:
54: *
55: * - `default`: Default value to return if no value found in request
56: * data or context record.
57: * - `schemaDefault`: Boolean indicating whether default value from
58: * context's schema should be used if it's not explicitly provided.
59: *
60: * @param string $field A dot separated path to the field a value
61: * is needed for.
62: * @return mixed
63: */
64: public function val($field);
65:
66: /**
67: * Check if a given field is 'required'.
68: *
69: * In this context class, this is simply defined by the 'required' array.
70: *
71: * @param string $field A dot separated path to check required-ness for.
72: * @return bool
73: */
74: public function isRequired($field);
75:
76: /**
77: * Get the fieldnames of the top level object in this context.
78: *
79: * @return string[] A list of the field names in the context.
80: */
81: public function fieldNames();
82:
83: /**
84: * Get the abstract field type for a given field name.
85: *
86: * @param string $field A dot separated path to get a schema type for.
87: * @return null|string An abstract data type or null.
88: * @see \Cake\Database\Type
89: */
90: public function type($field);
91:
92: /**
93: * Get an associative array of other attributes for a field name.
94: *
95: * @param string $field A dot separated path to get additional data on.
96: * @return array An array of data describing the additional attributes on a field.
97: */
98: public function attributes($field);
99:
100: /**
101: * Check whether or not a field has an error attached to it
102: *
103: * @param string $field A dot separated path to check errors on.
104: * @return bool Returns true if the errors for the field are not empty.
105: */
106: public function hasError($field);
107:
108: /**
109: * Get the errors for a given field
110: *
111: * @param string $field A dot separated path to check errors on.
112: * @return array An array of errors, an empty array will be returned when the
113: * context has no errors.
114: */
115: public function error($field);
116: }
117: