Contact Form * @copyright Tamaranga * @property ItemPage $parent */ class ContactFormBlock extends ContactForm { /** @var string tip block title */ public $tip_title = ''; /** @var string tip block description */ public $tip_description = ''; /** @var bool */ public $enabled = true; public function init() { parent::init(); $this->setKey('view.contact.form'); $this->setTitle(_t('@listings', 'Contact Form')); $this->addWrapper('item/contact.form', 'listings'); } public function data() { $data = parent::data(); if (! is_array($data)) { return $data; } $data['visible'] = $this->isFormVisible(); $data['vendor_url'] = $this->parent->item['user']['link']; $data['vendor_title'] = $this->parent->item['name']; if ($this->parent->item['is_company']) { $data['vendor_url'] = $this->parent->item['company']['link']; } $data['item'] = &$this->parent->item; return $data; } public function isFormVisible() { if (! $this->enabled) { return false; } if (! $this->parent->itemId || ! $this->parent->item) { return false; } if ($this->parent->item['owner']) { return false; } if ($this->parent->item['status'] == Listings::STATUS_PUBLICATED_OUT) { return false; } return true; } public function validate($data = []) { $data['item_id'] = $this->parent->itemId; if (empty($this->parent->item) || $this->parent->item['status'] != Listings::STATUS_PUBLICATED) { $this->errors->reloadPage(); } $data['receiver'] = $this->parent->item['user_id'] ?? 0; $data['company_id'] = $this->parent->item['company_id'] ?? 0; return parent::validate($data); } public function submit() { if (! $this->isFormVisible()) { $this->errors->reloadPage(); } return parent::submit(); } public function settingsForm($form) { $form->checkbox('enabled', _t('@', 'Enabled'), true); parent::settingsForm($form); $form->text('tip_title', _t('@listings', 'Contact Form Tip Title'), _t('listings', 'For your safety!', true)) ->boundaryInit(['title' => _t('@listings', 'Recommendations in the form of contacting the author of the listing')]); $form->wysiwyg('tip_description', _t('@listings', 'Contact Form Tip Description'), _t('listings', '

Avoid forwarding money!

Meet with the seller, personal deals are the safest.

Check the product before buying.

Do not reply to listings written with gross errors in grammar.

', true)) ->boundaryIn('tip_title'); } }