class ContactStorageTestHooks

Hook implementations for contact_storage_test.

Hierarchy

Expanded class hierarchy of ContactStorageTestHooks

File

core/modules/contact/tests/modules/contact_storage_test/src/Hook/ContactStorageTestHooks.php, line 15

Namespace

Drupal\contact_storage_test\Hook
View source
class ContactStorageTestHooks {
    
    /**
     * Implements hook_entity_base_field_info().
     */
    public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
        if ($entity_type->id() == 'contact_message') {
            $fields = [];
            $fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('Message ID'))
                ->setDescription(t('The message ID.'))
                ->setReadOnly(TRUE)
                ->setSetting('unsigned', TRUE);
            return $fields;
        }
    }
    
    /**
     * Implements hook_entity_type_alter().
     */
    public function entityTypeAlter(array &$entity_types) : void {
        
        /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
        // Set the controller class for nodes to an alternate implementation of the
        // Drupal\Core\Entity\EntityStorageInterface interface.
        $entity_types['contact_message']->setStorageClass('\\Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage');
        $keys = $entity_types['contact_message']->getKeys();
        $keys['id'] = 'id';
        $entity_types['contact_message']->set('entity_keys', $keys);
        $entity_types['contact_message']->set('base_table', 'contact_message');
    }
    
    /**
     * Implements hook_form_FORM_ID_alter() for contact_form_form().
     */
    public function formContactFormFormAlter(&$form, FormStateInterface $form_state) : void {
        
        /** @var \Drupal\contact\ContactFormInterface $contact_form */
        $contact_form = $form_state->getFormObject()
            ->getEntity();
        $form['send_a_pony'] = [
            '#type' => 'checkbox',
            '#title' => t('Send submitters a voucher for a free pony.'),
            '#description' => t('Enable to send an additional email with a free pony voucher to anyone who submits the form.'),
            '#default_value' => $contact_form->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE),
        ];
        $form['#entity_builders'][] = 'contact_storage_test_contact_form_form_builder';
    }

}

Members

Title Sort descending Modifiers Object type Summary
ContactStorageTestHooks::entityBaseFieldInfo public function Implements hook_entity_base_field_info().
ContactStorageTestHooks::entityTypeAlter public function Implements hook_entity_type_alter().
ContactStorageTestHooks::formContactFormFormAlter public function Implements hook_form_FORM_ID_alter() for contact_form_form().

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