3 namespace Drupal\block_content;
5 use Drupal\Core\Entity\BundleEntityFormBase;
6 use Drupal\Core\Entity\EntityTypeInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\language\Entity\ContentLanguageSettings;
11 * Base form for category edit forms.
13 class BlockContentTypeForm extends BundleEntityFormBase {
18 public function form(array $form, FormStateInterface $form_state) {
19 $form = parent::form($form, $form_state);
21 /* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
22 $block_type = $this->entity;
24 if ($this->operation == 'add') {
25 $form['#title'] = $this->t('Add custom block type');
28 $form['#title'] = $this->t('Edit %label custom block type', ['%label' => $block_type->label()]);
32 '#type' => 'textfield',
33 '#title' => t('Label'),
35 '#default_value' => $block_type->label(),
36 '#description' => t("Provide a label for this block type to help identify it in the administration pages."),
40 '#type' => 'machine_name',
41 '#default_value' => $block_type->id(),
43 'exists' => '\Drupal\block_content\Entity\BlockContentType::load',
45 '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
48 $form['description'] = [
49 '#type' => 'textarea',
50 '#default_value' => $block_type->getDescription(),
51 '#description' => t('Enter a description for this block type.'),
52 '#title' => t('Description'),
56 '#type' => 'checkbox',
57 '#title' => t('Create new revision'),
58 '#default_value' => $block_type->shouldCreateNewRevision(),
59 '#description' => t('Create a new revision by default for this block type.'),
62 if ($this->moduleHandler->moduleExists('language')) {
65 '#title' => t('Language settings'),
66 '#group' => 'additional_settings',
69 $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
70 $form['language']['language_configuration'] = [
71 '#type' => 'language_configuration',
72 '#entity_information' => [
73 'entity_type' => 'block_content',
74 'bundle' => $block_type->id(),
76 '#default_value' => $language_configuration,
79 $form['#submit'][] = 'language_configuration_element_submit';
82 $form['actions'] = ['#type' => 'actions'];
83 $form['actions']['submit'] = [
85 '#value' => t('Save'),
88 return $this->protectBundleIdElement($form);
94 public function save(array $form, FormStateInterface $form_state) {
95 $block_type = $this->entity;
96 $status = $block_type->save();
98 $edit_link = $this->entity->link($this->t('Edit'));
99 $logger = $this->logger('block_content');
100 if ($status == SAVED_UPDATED) {
101 drupal_set_message(t('Custom block type %label has been updated.', ['%label' => $block_type->label()]));
102 $logger->notice('Custom block type %label has been updated.', ['%label' => $block_type->label(), 'link' => $edit_link]);
105 block_content_add_body_field($block_type->id());
106 drupal_set_message(t('Custom block type %label has been added.', ['%label' => $block_type->label()]));
107 $logger->notice('Custom block type %label has been added.', ['%label' => $block_type->label(), 'link' => $edit_link]);
110 $form_state->setRedirectUrl($this->entity->urlInfo('collection'));