addPostFields(); break; case 'term': $this->addTermFields(); break; case 'user': $this->addUserFields(); break; } $this->registrar = $registrar; } public function addField(string $name, array $config):self { $this->fields[$name] = match ($config['type']) { 'upload', 'image', 'gallery' => new Upload($name, $config), 'checkbox', 'radio', 'select', 'set' => new OptionsField($name, $config), 'repeater', 'group', 'tagList' => new GroupedField($name, $config), 'selector', 'taxonomy', 'user', 'post' => new TaxonomyField($name, $config), default => new Field($name, $config), }; return $this; } public function addPostFields():void { $fields = [ 'post_thumbnail' => [ 'type' => 'upload', 'multiple'=> false, 'label' => 'Main Image', ], 'post_date' => [ 'type' => 'datetime', 'label' => 'Date', ], 'post_content' => [ 'type' => 'textarea', 'quill' => true, 'label' => 'Content' ], 'post_title' => [ 'type' => 'text', 'label' => 'Title', 'required' => true, ], 'post_excerpt' => [ 'type' => 'textarea', 'label' => 'TLDR', 'maxLength' => 158, ], 'post_status' => [ 'type' => 'radio', 'label' => 'Status', 'default' => 'draft', 'options' => [ 'all' => [ 'icon' => 'infinity', 'label' => 'Everything', ], 'publish' => [ 'icon' => 'eye', 'label' => 'Live', ], 'draft' => [ 'icon' => 'eye-closed', 'label' => 'Hidden', ], 'trash' => [ 'label' => 'Scrapped', 'icon' => 'trash', ], 'delete' => [ 'label' => 'Permanently Delete', 'icon' => 'trash' ] ] ] ]; foreach ($fields as $name => $config) { $this->addField($name, $config); } } public function addTermFields():void { $fields = [ 'name' => [ 'type' => 'text', 'label' => 'Title', 'required' => true, ], 'description' => [ 'type' => 'textarea', 'quill' => true, 'label' => 'Description', ] ]; if ($this->registrar->registrar->hierarchical){ $fields['parent'] = [ 'type' => 'taxonomy', 'taxonomy_type' => 'reference', 'autocomplete' => true, 'label' => 'Term Parent' ]; } foreach ($fields as $name => $config) { $this->addField($name, $config); } } public function addUserFields():void { $fields = [ 'first_name' => [ 'type' => 'text', 'label' => 'First Name', ], 'last_name' => [ 'type' => 'text', 'label' => 'Last Name', ], 'display_name' => [ 'type' => 'text', 'label' => 'Display Name', ], 'website' => [ 'type' => 'url', 'label' => 'Website', ], 'description' => [ 'type' => 'textarea', 'quill' => true, 'label' => 'Description', ] ]; foreach ($fields as $name => $config) { $this->addField($name, $config); } } public function modifyField(string $name, string $property, mixed $value):void { $field = $this->fields[$name]; $field->$property = $value; } public function getFields():array { return $this->fields; } }