Contacts * @copyright Tamaranga */ class Contacts extends PhonesInput { public function init() { parent::init(); $this->setKey('contacts'); $this->setTitle(_t('item-form', 'Contacts')); $this->addWrapper(function ($content, $data) { $data['content'] = $content; $data['contacts'] = $this->contacts ?? ''; if (empty($data['content']) && empty($data['contacts'])) { return ''; } return $this->view->template( 'form/blocks/contacts', $data, 'listings' ); }); } public function data() { if (! $this->visible()) { return false; } $data = parent::data(); $data['edit'] = $this->form->edit(); $data['readonly'] = $this->readonly = Listings::getItemContactsFromProfile(); if (! $data['edit'] && ! User::id()) { $data['readonly'] = $this->readonly = false; } return $data; } public function phones() { return $this->form->item['phones'] ?? []; } public function blocks() { $this->addBlock('contacts', ContactsInput::class, function ($block) { /** @var ContactsInput $block */ $block->readonly = Listings::getItemContactsFromProfile(); if (! $this->form->edit() && ! User::id()) { $block->readonly = false; } $block->contacts = function () { return $this->form->item['contacts'] ?? []; }; $block->prerenderable(true); }); } public function visible() { return true; } public function reloadBlock($event) { if ($event != 'publisherChange') { return false; } if ($this->visible()) { return $this->render(); } return ''; } public function onLoad($data = []) { if (! $this->form->edit() || Listings::getItemContactsFromProfile()) { if (bff::moduleExists('business') && User::companyID() && ! empty($this->form->item['company_id'])) { $company = $this->form->loadCompanyData(); $this->form->item->fill(['phones' => $company['phones']]); $this->form->item->fill(['contacts' => $company['contacts']]); } else { if (! empty($this->form->user['phones'])) { $this->form->item->fill(['phones' => $this->form->user['phones']]); } if (! empty($this->form->user['contacts'])) { $this->form->item->fill(['contacts' => $this->form->user['contacts']]); } } } parent::onLoad($data); } }