ContactForm.php

Same filename in other branches
  1. 3.x modules/content_entity_example/src/Form/ContactForm.php

Namespace

Drupal\content_entity_example\Form

File

modules/content_entity_example/src/Form/ContactForm.php

View source
<?php

namespace Drupal\content_entity_example\Form;

use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Language\Language;
use Drupal\Core\Form\FormStateInterface;

/**
 * Form controller for the content_entity_example entity edit forms.
 *
 * @ingroup content_entity_example
 */
class ContactForm extends ContentEntityForm {
    
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        
        /** @var \Drupal\content_entity_example\Entity\Contact $entity */
        $form = parent::buildForm($form, $form_state);
        $entity = $this->entity;
        $form['langcode'] = [
            '#title' => $this->t('Language'),
            '#type' => 'language_select',
            '#default_value' => $entity->getUntranslated()
                ->language()
                ->getId(),
            '#languages' => Language::STATE_ALL,
        ];
        return $form;
    }
    
    /**
     * {@inheritdoc}
     */
    public function save(array $form, FormStateInterface $form_state) {
        $form_state->setRedirect('entity.content_entity_example_contact.collection');
        $entity = $this->getEntity();
        $entity->save();
    }

}

Classes

Title Deprecated Summary
ContactForm Form controller for the content_entity_example entity edit forms.