@@ 111-136 (lines=26) @@ | ||
108 | * @param string $key |
|
109 | * @param mixed $value |
|
110 | */ |
|
111 | public function setAttribute($key, $value) |
|
112 | { |
|
113 | if (!$parent = $this->getParent()) { |
|
114 | return null; |
|
115 | } |
|
116 | ||
117 | /* @var AssignmentInterface $assignment */ |
|
118 | $assignment = $parent->getAssignment($key); |
|
119 | ||
120 | if (!$assignment) { |
|
121 | parent::setAttribute($key, $value); |
|
122 | ||
123 | return; |
|
124 | } |
|
125 | ||
126 | $type = $assignment->getFieldType($this); |
|
127 | ||
128 | $type->setEntry($this); |
|
129 | $type->setLocale($this->locale); |
|
130 | ||
131 | $accessor = $type->getAccessor(); |
|
132 | $modifier = $type->getModifier(); |
|
133 | ||
134 | $accessor->set($modifier->modify($value)); |
|
135 | } |
|
136 | ||
137 | /** |
|
138 | * Fire field type events. |
|
139 | * |
@@ 304-331 (lines=28) @@ | ||
301 | * @param $fieldSlug |
|
302 | * @return null|FieldType |
|
303 | */ |
|
304 | public function getFieldType($fieldSlug) |
|
305 | { |
|
306 | $locale = config('app.locale'); |
|
307 | ||
308 | $assignment = $this->getAssignment($fieldSlug); |
|
309 | ||
310 | if (!$assignment) { |
|
311 | return null; |
|
312 | } |
|
313 | ||
314 | $type = $assignment->getFieldType(); |
|
315 | ||
316 | if ($assignment->isTranslatable()) { |
|
317 | $entry = $this->translateOrDefault($locale); |
|
318 | ||
319 | $type->setLocale($locale); |
|
320 | } else { |
|
321 | $entry = $this; |
|
322 | } |
|
323 | ||
324 | $type->setEntry($entry); |
|
325 | ||
326 | $type->setValue($this->getFieldValue($fieldSlug)); |
|
327 | $type->setEntry($this); |
|
328 | ||
329 | return $type; |
|
330 | } |
|
331 | ||
332 | /** |
|
333 | * Get the field type query. |
|
334 | * |