Chris@0: bundle() == 'personal'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getContactForm() { Chris@0: return $this->get('contact_form')->entity; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getSenderName() { Chris@0: return $this->get('name')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setSenderName($sender_name) { Chris@0: $this->set('name', $sender_name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getSenderMail() { Chris@0: return $this->get('mail')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setSenderMail($sender_mail) { Chris@0: $this->set('mail', $sender_mail); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getSubject() { Chris@0: return $this->get('subject')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setSubject($subject) { Chris@0: $this->set('subject', $subject); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getMessage() { Chris@0: return $this->get('message')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setMessage($message) { Chris@0: $this->set('message', $message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function copySender() { Chris@0: return (bool) $this->get('copy')->value; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setCopySender($inform) { Chris@0: $this->set('copy', (bool) $inform); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getPersonalRecipient() { Chris@0: if ($this->isPersonal()) { Chris@0: return $this->get('recipient')->entity; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { Chris@0: /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ Chris@0: $fields = parent::baseFieldDefinitions($entity_type); Chris@0: Chris@0: $fields['contact_form']->setLabel(t('Form ID')) Chris@0: ->setDescription(t('The ID of the associated form.')); Chris@0: Chris@0: $fields['uuid']->setDescription(t('The message UUID.')); Chris@0: Chris@0: $fields['langcode']->setDescription(t('The message language code.')); Chris@0: Chris@0: $fields['name'] = BaseFieldDefinition::create('string') Chris@0: ->setLabel(t("The sender's name")) Chris@0: ->setDescription(t('The name of the person that is sending the contact message.')); Chris@0: Chris@0: $fields['mail'] = BaseFieldDefinition::create('email') Chris@0: ->setLabel(t("The sender's email")) Chris@0: ->setDescription(t('The email of the person that is sending the contact message.')); Chris@0: Chris@0: // The subject of the contact message. Chris@0: $fields['subject'] = BaseFieldDefinition::create('string') Chris@0: ->setLabel(t('Subject')) Chris@0: ->setRequired(TRUE) Chris@0: ->setSetting('max_length', 100) Chris@0: ->setDisplayOptions('form', [ Chris@0: 'type' => 'string_textfield', Chris@0: 'weight' => -10, Chris@0: ]) Chris@0: ->setDisplayConfigurable('form', TRUE); Chris@0: Chris@0: // The text of the contact message. Chris@0: $fields['message'] = BaseFieldDefinition::create('string_long') Chris@0: ->setLabel(t('Message')) Chris@0: ->setRequired(TRUE) Chris@0: ->setDisplayOptions('form', [ Chris@0: 'type' => 'string_textarea', Chris@0: 'weight' => 0, Chris@0: 'settings' => [ Chris@0: 'rows' => 12, Chris@0: ], Chris@0: ]) Chris@0: ->setDisplayConfigurable('form', TRUE) Chris@0: ->setDisplayOptions('view', [ Chris@0: 'type' => 'string', Chris@0: 'weight' => 0, Chris@0: 'label' => 'above', Chris@0: ]) Chris@0: ->setDisplayConfigurable('view', TRUE); Chris@0: Chris@0: $fields['copy'] = BaseFieldDefinition::create('boolean') Chris@0: ->setLabel(t('Copy')) Chris@0: ->setDescription(t('Whether to send a copy of the message to the sender.')); Chris@0: Chris@0: $fields['recipient'] = BaseFieldDefinition::create('entity_reference') Chris@0: ->setLabel(t('Recipient ID')) Chris@0: ->setDescription(t('The ID of the recipient user for personal contact messages.')) Chris@0: ->setSetting('target_type', 'user'); Chris@0: Chris@0: return $fields; Chris@0: } Chris@0: Chris@0: }