| | |
| | | return; |
| | | } |
| | | } |
| | | $current = get_class($this); |
| | | $class = match($config['type']) { |
| | | 'group' => ($current !== GroupedField::class) ? new GroupedField($name, $config) : $this, |
| | | 'select', 'radio', 'checkbox' => ($current !== OptionsField::class) ? new OptionsField($name, $config) : $this, |
| | | 'repeater' => ($current !== RepeaterField::class) ? new RepeaterField($name, $config) : $this, |
| | | 'taglist' => ($current !== TagListField::class) ? new TagListField($name, $config) : $this, |
| | | 'taxonomy', 'post', 'user', 'selector' => ($current !== SelectorField::class) ? new SelectorField($name, $config) : $this, |
| | | 'upload' => ($current !== UploadField::class) ? new UploadField($name, $config) : $this, |
| | | default => $this |
| | | }; |
| | | |
| | | foreach ($config as $key => $value) { |
| | | if (property_exists($this, $key)) { |
| | | if (property_exists($class, $key)) { |
| | | $method = 'set' . ucfirst($key); |
| | | $this->$method($value); |
| | | $class->$method($value); |
| | | } else { |
| | | error_log('Instance: '.print_r($this, true)); |
| | | error_log('Instance: '.print_r($class, true)); |
| | | error_log('[JVBase\registrar\Field] Invalid key for '.$name.': '.$key); |
| | | } |
| | | } |
| | |
| | | public function getConfig():array{ |
| | | $config = get_object_vars($this); |
| | | |
| | | $config = array_map(function ($item) { |
| | | return array_map(function ($item) { |
| | | if (is_a($item, Field::class)) { |
| | | return $item->getConfig(); |
| | | } else if (is_array($item)) { |
| | | $temp = []; |
| | | foreach ($item as $v) { |
| | | foreach ($item as $k => $v) { |
| | | if (is_a($v, Field::class)) { |
| | | $temp[] = $v->getConfig(); |
| | | $temp[$k] = $v->getConfig(); |
| | | } else { |
| | | $temp[] = $v; |
| | | $temp[$k] = $v; |
| | | } |
| | | } |
| | | return $temp; |
| | |
| | | return $item; |
| | | } |
| | | }, $config); |
| | | |
| | | return $config; |
| | | } |
| | | } |