class CustomBlockTypeFormController

Base form controller for category edit forms.

Hierarchy

Expanded class hierarchy of CustomBlockTypeFormController

File

drupal/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php, line 15
Contains \Drupal\custom_block\CustomBlockTypeFormController.

Namespace

Drupal\custom_block
View source
class CustomBlockTypeFormController extends EntityFormController {

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::form().
   */
  public function form(array $form, array &$form_state) {
    $form = parent::form($form, $form_state);
    $block_type = $this->entity;
    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label'),
      '#maxlength' => 255,
      '#default_value' => $block_type
        ->label(),
      '#description' => t("Provide a label for this block type to help identify it in the administration pages."),
      '#required' => TRUE,
    );
    $form['id'] = array(
      '#type' => 'machine_name',
      '#default_value' => $block_type
        ->id(),
      '#machine_name' => array(
        'exists' => 'custom_block_type_load',
      ),
      '#disabled' => !$block_type
        ->isNew(),
    );
    $form['description'] = array(
      '#type' => 'textarea',
      '#default_value' => $block_type->description,
      '#description' => t('Enter a description for this block type.'),
      '#title' => t('Description'),
    );
    $form['revision'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create new revision'),
      '#default_value' => $block_type->revision,
      '#description' => t('Create a new revision by default for this block type.'),
    );
    if (module_exists('translation_entity')) {
      $form['language'] = array(
        '#type' => 'details',
        '#title' => t('Language settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#group' => 'additional_settings',
      );
      $language_configuration = language_get_default_configuration('custom_block', $block_type
        ->id());
      $form['language']['language_configuration'] = array(
        '#type' => 'language_configuration',
        '#entity_information' => array(
          'entity_type' => 'custom_block',
          'bundle' => $block_type
            ->id(),
        ),
        '#default_value' => $language_configuration,
      );
      $form['#submit'][] = 'language_configuration_element_submit';
    }
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
    return $form;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::save().
   */
  public function save(array $form, array &$form_state) {
    $block_type = $this->entity;
    $status = $block_type
      ->save();
    $uri = $block_type
      ->uri();
    if ($status == SAVED_UPDATED) {
      drupal_set_message(t('Custom block type %label has been updated.', array(
        '%label' => $block_type
          ->label(),
      )));
      watchdog('custom_block', 'Custom block type %label has been updated.', array(
        '%label' => $block_type
          ->label(),
      ), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
    }
    else {
      drupal_set_message(t('Custom block type %label has been added.', array(
        '%label' => $block_type
          ->label(),
      )));
      watchdog('custom_block', 'Custom block type %label has been added.', array(
        '%label' => $block_type
          ->label(),
      ), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
    }
    $form_state['redirect'] = 'admin/structure/custom-blocks';
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::delete().
   */
  public function delete(array $form, array &$form_state) {
    $block_type = $this->entity;
    $form_state['redirect'] = 'admin/structure/custom-blocks/manage/' . $block_type
      ->id() . '/delete';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomBlockTypeFormController::delete public function Overrides \Drupal\Core\Entity\EntityFormController::delete(). Overrides EntityFormController::delete
CustomBlockTypeFormController::form public function Overrides \Drupal\Core\Entity\EntityFormController::form(). Overrides EntityFormController::form
CustomBlockTypeFormController::save public function Overrides \Drupal\Core\Entity\EntityFormController::save(). Overrides EntityFormController::save
EntityFormController::$entity protected property The entity being used by this form.
EntityFormController::$operation protected property The name of the current operation.
EntityFormController::actions protected function Returns an array of supported actions for the current entity form. 17
EntityFormController::actionsElement protected function Returns the action form element for the current entity form.
EntityFormController::buildEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::buildEntity(). Overrides EntityFormControllerInterface::buildEntity 2
EntityFormController::buildForm public function Form constructor. Overrides FormInterface::buildForm 1
EntityFormController::getBaseFormID public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormID
EntityFormController::getEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). Overrides EntityFormControllerInterface::getEntity
EntityFormController::getFormDisplay public function Returns the form display. Overrides EntityFormControllerInterface::getFormDisplay
EntityFormController::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
EntityFormController::getFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getFormLangcode(). Overrides EntityFormControllerInterface::getFormLangcode
EntityFormController::getOperation public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getOperation(). Overrides EntityFormControllerInterface::getOperation
EntityFormController::init protected function Initialize the form state and the entity before the first form build. 1
EntityFormController::isDefaultFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::prepareEntity protected function Prepares the entity object before the form is built first. 3
EntityFormController::setEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::setEntity(). Overrides EntityFormControllerInterface::setEntity
EntityFormController::setFormDisplay public function Sets the form display. Overrides EntityFormControllerInterface::setFormDisplay
EntityFormController::setOperation public function Sets the operation for this form.
EntityFormController::submit public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::submit(). Overrides EntityFormControllerInterface::submit 13
EntityFormController::submitEntityLanguage protected function Handle possible entity language changes. 1
EntityFormController::submitForm public function Form submission handler. Overrides FormInterface::submitForm
EntityFormController::updateFormLangcode protected function Updates the form language to reflect any change to the entity language.
EntityFormController::validate public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::validate(). Overrides EntityFormControllerInterface::validate 11
EntityFormController::validateForm public function Form validation handler. Overrides FormInterface::validateForm
EntityFormController::__construct public function Constructs an EntityFormController object. 5