| @@ 112-137 (lines=26) @@ | ||
| 109 | * @param string $key |
|
| 110 | * @param mixed $value |
|
| 111 | */ |
|
| 112 | public function setAttribute($key, $value) |
|
| 113 | { |
|
| 114 | if (!$parent = $this->getParent()) { |
|
| 115 | return null; |
|
| 116 | } |
|
| 117 | ||
| 118 | /* @var AssignmentInterface $assignment */ |
|
| 119 | $assignment = $parent->getAssignment($key); |
|
| 120 | ||
| 121 | if (!$assignment) { |
|
| 122 | ||
| 123 | parent::setAttribute($key, $value); |
|
| 124 | ||
| 125 | return; |
|
| 126 | } |
|
| 127 | ||
| 128 | $type = $assignment->getFieldType($this); |
|
| 129 | ||
| 130 | $type->setEntry($this); |
|
| 131 | $type->setLocale($this->locale); |
|
| 132 | ||
| 133 | $accessor = $type->getAccessor(); |
|
| 134 | $modifier = $type->getModifier(); |
|
| 135 | ||
| 136 | $accessor->set($modifier->modify($value)); |
|
| 137 | } |
|
| 138 | ||
| 139 | /** |
|
| 140 | * Fire field type events. |
|
| @@ 268-295 (lines=28) @@ | ||
| 265 | * @param $fieldSlug |
|
| 266 | * @return null|FieldType |
|
| 267 | */ |
|
| 268 | public function getFieldType($fieldSlug) |
|
| 269 | { |
|
| 270 | $locale = config('app.locale'); |
|
| 271 | ||
| 272 | $assignment = $this->getAssignment($fieldSlug); |
|
| 273 | ||
| 274 | if (!$assignment) { |
|
| 275 | return null; |
|
| 276 | } |
|
| 277 | ||
| 278 | $type = $assignment->getFieldType(); |
|
| 279 | ||
| 280 | if ($assignment->isTranslatable()) { |
|
| 281 | ||
| 282 | $entry = $this->translateOrDefault($locale); |
|
| 283 | ||
| 284 | $type->setLocale($locale); |
|
| 285 | } else { |
|
| 286 | $entry = $this; |
|
| 287 | } |
|
| 288 | ||
| 289 | $type->setEntry($entry); |
|
| 290 | ||
| 291 | $type->setValue($this->getFieldValue($fieldSlug)); |
|
| 292 | $type->setEntry($this); |
|
| 293 | ||
| 294 | return $type; |
|
| 295 | } |
|
| 296 | ||
| 297 | /** |
|
| 298 | * Get the field type query. |
|