registrar = $registrar; switch ($type) { case 'post': $this->addPostFields(); break; case 'term': $this->addTermFields(); break; case 'user': $this->addUserFields(); break; } } public function addField(string $name, array $config):self { $this->fields[$name] = match ($config['type']) { 'upload', 'image', 'gallery' => new UploadField($name, $config), 'checkbox', 'radio', 'select', 'set' => new OptionsField($name, $config), 'group' => new GroupedField($name, $config), 'repeater' => new RepeaterField($name, $config), 'tagList' => new TagListField($name, $config), 'selector', 'taxonomy', 'user', 'post' => new SelectorField($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->args()['hierarchical']??false && $this->registrar->args()['hierarchical'] === true){ $fields['parent'] = [ 'type' => 'taxonomy', 'isReference' => true, '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; } public function addCommon(string $name):self { match ($name) { 'wiki' => $this->addWikiField(), 'links' => $this->addLinksField(), 'contact' => $this->addContactField(), 'reviews', 'review' => $this->addReviewField(), 'alternate_name' => $this->addAlternateName(), 'keywords' => $this->addKeywords(), default => error_log('[Field]addCommon: No configuration found for '.$name.'.') }; return $this; } protected function addWikiField():void { $this->addField( 'wiki', [ 'type' => 'url', 'label' => 'Wikipedia Page', 'description' => 'For the schema', 'quickEdit' => true, ] ); } protected function addLinksField():void { $this->addField( 'links', [ 'type' => 'repeater', 'quickEdit' => true, 'add_label' => 'title', 'label' => 'Online Links', 'description' => 'These are listed publicly on the website', 'fields' => [ 'url' => [ 'type' => 'url', 'label' => 'URL', ], 'title' => [ 'type' => 'text', 'label' => 'Label', ], 'tracker' => [ 'type' => 'text', 'label' => 'Tracker', 'description' => 'If you are set up to track link referrals, add what comes after the ? here.', ], ], 'section' => 'contact' ] ); } protected function addContactField():void { $this->addField( 'admin_contact', [ 'type' => 'set', 'label' => 'Admin Contact', 'quickEdit' => true, 'options' => [ 'text' => 'Text', 'call' => 'Call', 'email' => 'Email', 'insta' => 'Instagram', ], 'section' => 'contact' ] ); $this->addField( 'public_contact', [ 'type' => 'set', 'label' => 'Public Contact', 'quickEdit' => true, 'options' => [ 'text' => 'Text', 'call' => 'Call', 'email' => 'Email', 'insta' => 'Instagram', ], 'section' => 'contact' ] ); } protected function addReviewField():void { $this->addField( 'reviews', [ 'type' => 'repeater', 'add_label' => 'name', 'label' => 'Reviews', 'fields' => [ 'name' => [ 'type' => 'text', 'label' => 'Reviewer Name', ], 'review' => [ 'type' => 'textarea', 'quill' => false, 'label' => 'Review', ], 'rating' => [ 'type' => 'select', 'label' => 'Rating', 'options' => [ 'none' => 'Not Given', '0.5' => '0.5', '1' => '1', '1.5' => '1.5', '2' => '2', '2.5' => '2.5', '3' => '3', '3.5' => '3.5', '4' => '4', '4.5' => '4.5', '5' => '5', ], 'default' => 'none' ], 'date' => [ 'type' => 'date', 'label' => 'Date of Review', ], 'url' => [ 'type' => 'url', 'label' => 'Link to Review (optional)', ], ], 'section' => 'seo' ] ); } protected function addAlternateName():void { $this->addField( 'alternate_name', [ 'type' => 'repeater', 'label' => 'Alternate Name', 'fields' => [ 'name' => [ 'type' => 'text', 'label' => 'Name', ] ], 'section' => 'seo' ] ); } protected function addKeywords():void { $this->addField( 'keywords', [ 'type' => 'repeater', 'label' => 'Keywords', 'fields' => [ 'keyword' => [ 'type' => 'text', 'label' => 'Keyword', ], ], 'default' => $labels ?? [ 'Edmonton tattoos', 'Edmonton tattoo artist', 'Edmonton tattooist' ], 'section' => 'seo', 'quickEdit' => true, ] ); } }