Same name and namespace in other branches
  1. 8.9.x core/modules/block_content/src/BlockContentTypeForm.php \Drupal\block_content\BlockContentTypeForm::form()
  2. 9 core/modules/block_content/src/BlockContentTypeForm.php \Drupal\block_content\BlockContentTypeForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

core/modules/block_content/src/BlockContentTypeForm.php, line 21

Class

BlockContentTypeForm
The block content type entity form.

Namespace

Drupal\block_content

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /** @var \Drupal\block_content\BlockContentTypeInterface $block_type */
  $block_type = $this->entity;
  if ($this->operation == 'add') {
    $form['#title'] = $this
      ->t('Add block type');
  }
  else {
    $form['#title'] = $this
      ->t('Edit %label block type', [
      '%label' => $block_type
        ->label(),
    ]);
  }
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $block_type
      ->label(),
    '#description' => $this
      ->t("The human-readable name for this block type, displayed on the <em>Block types</em> page."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $block_type
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\block_content\\Entity\\BlockContentType::load',
    ],
    '#description' => $this
      ->t("Unique machine-readable name: lowercase letters, numbers, and underscores only."),
    '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
  ];
  $form['description'] = [
    '#type' => 'textarea',
    '#default_value' => $block_type
      ->getDescription(),
    '#description' => $this
      ->t('Displays on the <em>Block types</em> page.'),
    '#title' => $this
      ->t('Description'),
  ];
  $form['revision'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Create new revision'),
    '#default_value' => $block_type
      ->shouldCreateNewRevision(),
    '#description' => $this
      ->t('Create a new revision by default for this block type.'),
  ];
  if ($this->moduleHandler
    ->moduleExists('language')) {
    $form['language'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Language settings'),
      '#group' => 'additional_settings',
    ];
    $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type
      ->id());
    $form['language']['language_configuration'] = [
      '#type' => 'language_configuration',
      '#entity_information' => [
        'entity_type' => 'block_content',
        'bundle' => $block_type
          ->id(),
      ],
      '#default_value' => $language_configuration,
    ];
    $form['#submit'][] = 'language_configuration_element_submit';
  }
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  return $this
    ->protectBundleIdElement($form);
}