function ContactHooks::entityExtraFieldInfo

Same name and namespace in other branches
  1. 11.x core/modules/contact/src/Hook/ContactHooks.php \Drupal\contact\Hook\ContactHooks::entityExtraFieldInfo()

Implements hook_entity_extra_field_info().

Attributes

#[Hook('entity_extra_field_info')]

File

core/modules/contact/src/Hook/ContactHooks.php, line 63

Class

ContactHooks
Hook implementations for contact.

Namespace

Drupal\contact\Hook

Code

public function entityExtraFieldInfo() : array {
  $fields = [];
  foreach (array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo('contact_message')) as $bundle) {
    $fields['contact_message'][$bundle]['form']['name'] = [
      'label' => $this->t('Sender name'),
      'description' => $this->t('Text'),
      'weight' => -50,
    ];
    $fields['contact_message'][$bundle]['form']['mail'] = [
      'label' => $this->t('Sender email'),
      'description' => $this->t('Email'),
      'weight' => -40,
    ];
    if ($bundle == 'personal') {
      $fields['contact_message'][$bundle]['form']['recipient'] = [
        'label' => $this->t('Recipient username'),
        'description' => $this->t('User'),
        'weight' => -30,
      ];
    }
    $fields['contact_message'][$bundle]['form']['preview'] = [
      'label' => $this->t('Preview sender message'),
      'description' => $this->t('Preview'),
      'weight' => 40,
    ];
    $fields['contact_message'][$bundle]['form']['copy'] = [
      'label' => $this->t('Send copy to sender'),
      'description' => $this->t('Option'),
      'weight' => 50,
    ];
  }
  $fields['user']['user']['form']['contact'] = [
    'label' => $this->t('Contact settings'),
    'description' => $this->t('Contact module form element.'),
    'weight' => 5,
  ];
  return $fields;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.