TextFieldForm.php in Apache Solr Config Generator 8
File
src/Form/TextFieldForm.php
View source
<?php
namespace Drupal\apachesolr_confgen\Form;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
class TextFieldForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$solr_text_field = $this->entity;
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $solr_text_field
->label(),
'#description' => $this
->t("Label for the TextField."),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $solr_text_field
->id(),
'#machine_name' => array(
'exists' => '\\Drupal\\apachesolr_confgen\\Entity\\TextField::load',
),
'#disabled' => !$solr_text_field
->isNew(),
);
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$solr_text_field = $this->entity;
$status = $solr_text_field
->save();
if ($status) {
drupal_set_message($this
->t('Saved the %label TextField.', array(
'%label' => $solr_text_field
->label(),
)));
}
else {
drupal_set_message($this
->t('The %label TextField was not saved.', array(
'%label' => $solr_text_field
->label(),
)));
}
$form_state
->setRedirectUrl($solr_text_field
->urlInfo('collection'));
}
}