| | |
| | | use JVBase\registrar\fields\Field; |
| | | use JVBase\registrar\fields\GroupedField; |
| | | use JVBase\registrar\fields\OptionsField; |
| | | use JVBase\registrar\fields\TaxonomyField; |
| | | use JVBase\registrar\fields\Upload; |
| | | use JVBase\registrar\fields\RepeaterField; |
| | | use JVBase\registrar\fields\TagListField; |
| | | use JVBase\registrar\fields\SelectorField; |
| | | use JVBase\registrar\fields\UploadField; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | protected Registrar $registrar; |
| | | |
| | | public function __construct(?string $type = null, ?Registrar $registrar = null) { |
| | | $this->registrar = $registrar; |
| | | switch ($type) { |
| | | case 'post': |
| | | $this->addPostFields(); |
| | |
| | | $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), |
| | | 'upload', 'image', 'gallery' => new UploadField($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), |
| | | '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), |
| | | }; |
| | | |
| | |
| | | 'label' => 'Description', |
| | | ] |
| | | ]; |
| | | if ($this->registrar->registrar->hierarchical){ |
| | | if ($this->registrar->args()['hierarchical']??false){ |
| | | $fields['parent'] = [ |
| | | 'type' => 'taxonomy', |
| | | 'taxonomy_type' => 'reference', |
| | | 'isReference' => true, |
| | | 'autocomplete' => true, |
| | | 'label' => 'Term Parent' |
| | | ]; |
| | |
| | | |
| | | public function modifyField(string $name, string $property, mixed $value):void |
| | | { |
| | | $property = 'set'.implode('',array_map('ucfirst',explode('_', $property))); |
| | | $field = $this->fields[$name]; |
| | | $field->$property = $value; |
| | | $field->$property($value); |
| | | } |
| | | |
| | | public function getFields():array |
| | | { |
| | | return $this->fields; |
| | | } |
| | | |
| | | public function addCommon(string $name):self |
| | | { |
| | | $method = 'add'.implode('',array_map('ucfirst',explode('_', $name))).'Field'; |
| | | if (method_exists($this, $method)) { |
| | | $this->$method(); |
| | | } else { |
| | | error_log('[Field]addCommon: No configuration found for '.$name.'.'); |
| | | } |
| | | return $this; |
| | | } |
| | | |
| | | protected function addWikiField(?string $label = null):void |
| | | { |
| | | $this->addField( |
| | | 'wiki', |
| | | [ |
| | | 'type' => 'url', |
| | | 'label' => $label ?: 'Wikipedia Page', |
| | | 'description' => 'For the schema', |
| | | 'quickEdit' => true, |
| | | ] |
| | | ); |
| | | } |
| | | |
| | | protected function addLinksField(?string $label = null):void |
| | | { |
| | | $this->addField( |
| | | 'links', |
| | | [ |
| | | 'type' => 'repeater', |
| | | 'quickEdit' => true, |
| | | 'add_label' => 'title', |
| | | 'label' => $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.', |
| | | 'default' => 'ref=edmonton_ink' |
| | | ], |
| | | ], |
| | | '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(?string $label = null):void |
| | | { |
| | | $this->addField( |
| | | 'reviews', |
| | | [ |
| | | 'type' => 'repeater', |
| | | 'add_label' => 'name', |
| | | 'label' => $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 addAlternateNameField():void |
| | | { |
| | | $this->addField( |
| | | 'alternate_name', |
| | | [ |
| | | 'type' => 'repeater', |
| | | 'label' => 'Alternate Name', |
| | | 'fields' => [ |
| | | 'name' => [ |
| | | 'type' => 'text', |
| | | 'label' => 'Name', |
| | | ] |
| | | ], |
| | | 'section' => 'seo' |
| | | ] |
| | | ); |
| | | } |
| | | protected function addKeywordsField():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, |
| | | ] |
| | | ); |
| | | } |
| | | |
| | | protected function addOutsidePhotoField():void |
| | | { |
| | | $this->addField( |
| | | 'outside_photo', |
| | | [ |
| | | 'type' => 'image', |
| | | 'limit' => 1, |
| | | 'label' => __('Outside Photo', 'jvb') |
| | | ] |
| | | ); |
| | | } |
| | | |
| | | protected function addSloganField():void |
| | | { |
| | | $this->addField( |
| | | 'slogan', |
| | | [ |
| | | 'type' => 'text', |
| | | 'label' => __('Tagline or Slogan', 'jvb') |
| | | ] |
| | | ); |
| | | } |
| | | |
| | | protected function addPaymentField():void |
| | | { |
| | | $this->addField( |
| | | 'payment_accepted', |
| | | [ |
| | | 'type' => 'set', |
| | | 'label' => __('Payment Accepted', 'jvb'), |
| | | 'options' => [ |
| | | 'Cash' => 'Cash', |
| | | 'Credit Card' => 'Credit Card', |
| | | 'Debit' => 'Debit', |
| | | 'Google Pay' => 'Google Pay', |
| | | 'Apple Pay' => 'Apple Pay', |
| | | 'PayPal' => 'PayPal', |
| | | 'Interac' => 'Interac', |
| | | 'AMEX' => 'AMEX', |
| | | ], |
| | | ] |
| | | ); |
| | | } |
| | | |
| | | protected function addAmenitiesField():void |
| | | { |
| | | $this->addField( |
| | | 'amenities', |
| | | [ |
| | | 'type' => 'set', |
| | | 'label' => __('Amenities', 'jvb'), |
| | | 'options' => [ |
| | | 'Wheelchair Accessible' => 'Wheelchair Accessible', |
| | | 'Free Parking' => 'Free Parking', |
| | | 'Private Rooms' => 'Private Rooms', |
| | | 'Air Conditioning' => 'Air Conditioning', |
| | | 'WiFi' => 'WiFi', |
| | | 'Gender Neutral Restroom' => 'Gender Neutral Restroom', |
| | | 'LGBTQ+ Friendly' => 'LGBTQ+ Friendly', |
| | | 'Sterilization Room' => 'Sterilization Room', |
| | | 'Refreshments Available' => 'Refreshments Available', |
| | | 'Street Level Access' => 'Street Level Access', |
| | | 'Single Use Needles' => 'Single Use Needles', |
| | | 'Consultation Room' => 'Consultation Room', |
| | | 'Aftercare Products Available' => 'Aftercare Products Available', |
| | | 'Walk-Ins Welcome' => 'Walk-Ins Welcome', |
| | | ] |
| | | ] |
| | | ); |
| | | } |
| | | } |