You are here

TextFieldForm.php in Apache Solr Config Generator 8

File

src/Form/TextFieldForm.php
View source
<?php

/**
 * @file
 * Contains Drupal\apachesolr_confgen\Form\TextFieldForm.
 */
namespace Drupal\apachesolr_confgen\Form;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;

/**
 * Class TextFieldForm.
 *
 * @package Drupal\apachesolr_confgen\Form
 */
class TextFieldForm extends EntityForm {

  /**
   * {@inheritdoc}
   */
  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(),
    );

    /* You will need additional form elements for your custom properties. */
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

}

Classes

Namesort descending Description
TextFieldForm Class TextFieldForm.