CityListForm.php in Country, State and City Fields 8
File
src/Form/CityListForm.php
View source
<?php
namespace Drupal\country_state_city\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Language\Language;
use Drupal\Core\Form\FormStateInterface;
class CityListForm extends ContentEntityForm {
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$form['langcode'] = [
'#title' => $this
->t('Language'),
'#type' => 'language_select',
'#default_value' => $entity
->language()
->getId(),
'#languages' => Language::STATE_ALL,
'#access' => TRUE,
];
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$form_state
->setRedirect('entity.citylist.collection');
$entity = $this
->getEntity();
$entity
->save();
}
}
Classes
Name |
Description |
CityListForm |
Form controller for the citylist entity edit forms. |