1 | <?php |
||
24 | trait ElementListTrait |
||
25 | { |
||
26 | use ModifyElementQueryTrait, |
||
27 | NormalizeValueTrait, |
||
28 | InputTrait; |
||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $ignoreSearchKeywords = true; |
||
34 | |||
35 | /** |
||
36 | * Prepares the field’s value to be stored somewhere, like the content table or JSON-encoded in an entry |
||
37 | * revision table. |
||
38 | * |
||
39 | * Data types that are JSON-encodable are safe (arrays, integers, strings, booleans, etc). |
||
40 | * Whatever this returns should be something [[normalizeValue()]] can handle. |
||
41 | * |
||
42 | * @param mixed $value The raw field value |
||
43 | * @param ElementInterface|null $element The element the field is associated with, if there is one |
||
44 | * @return mixed The serialized field value |
||
45 | */ |
||
46 | public function serializeValue($value, ElementInterface $element = null) |
||
50 | |||
51 | /** |
||
52 | * Returns whether the given value should be considered “empty” to a validator. |
||
53 | * |
||
54 | * @param mixed $value The field’s value |
||
55 | * @param ElementInterface $element The element the field is associated with, if there is one |
||
56 | * @return bool Whether the value should be considered “empty” |
||
57 | * @see Validator::$isEmpty |
||
58 | */ |
||
59 | public function isValueEmpty($value, ElementInterface $element): bool |
||
63 | |||
64 | /** |
||
65 | * /** |
||
66 | * Returns a static (non-editable) version of the field’s input HTML. |
||
67 | * |
||
68 | * This function is called to output field values when viewing entry drafts. |
||
69 | * |
||
70 | * @param mixed $value The field’s value |
||
71 | * @param ElementInterface $element The element the field is associated with |
||
72 | * @return string The static version of the field’s input HTML |
||
73 | * @throws \Twig\Error\LoaderError |
||
74 | * @throws \Twig\Error\RuntimeError |
||
75 | * @throws \Twig\Error\SyntaxError |
||
76 | */ |
||
77 | public function getStaticHtml($value, ElementInterface $element): string |
||
107 | |||
108 | /** |
||
109 | * Returns the HTML that should be shown for this field in Table View. |
||
110 | * |
||
111 | * @param mixed $value The field’s value |
||
112 | * @param ElementInterface $element The element the field is associated with |
||
113 | * @return string The HTML that should be shown for this field in Table View |
||
114 | * @throws \Twig\Error\LoaderError |
||
115 | * @throws \Twig\Error\RuntimeError |
||
116 | * @throws \Twig\Error\SyntaxError |
||
117 | */ |
||
118 | public function getTableAttributeHtml($value, ElementInterface $element): string |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | public function getSearchKeywords($value, ElementInterface $element): string |
||
149 | |||
150 | /** |
||
151 | * Identify whether a sort order should be enforced. |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function ensureSortOrder(): bool |
||
159 | |||
160 | /** |
||
161 | * Allow the settings to identify whether the element should be sortable |
||
162 | * |
||
163 | * @param bool $sortable |
||
164 | * @return $this |
||
165 | */ |
||
166 | public function setSortable(bool $sortable = null) |
||
171 | |||
172 | /** |
||
173 | * Get the sortable attribute value |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function getSortable(): bool |
||
181 | |||
182 | /** |
||
183 | * @inheritDoc |
||
184 | * @throws \Twig\Error\LoaderError |
||
185 | * @throws \Twig\Error\RuntimeError |
||
186 | * @throws \Twig\Error\SyntaxError |
||
187 | */ |
||
188 | public function getSettingsHtml() |
||
202 | |||
203 | /** |
||
204 | * Our value is not an ElementQueryInterface and therefore we should handle it |
||
205 | * differently. |
||
206 | * |
||
207 | * @inheritdoc |
||
208 | */ |
||
209 | public function afterElementSave(ElementInterface $element, bool $isNew) |
||
230 | } |
||
231 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: