NodeTypeForm::form

public NodeTypeForm::form(array $form, FormStateInterface $form_state)

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/node/src/NodeTypeForm.php, line 46

Class

NodeTypeForm
Form handler for node type forms.

Namespace

Drupal\node

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
 
  $type = $this->entity;
  if ($this->operation == 'add') {
    $form['#title'] = $this->t('Add content type');
    $fields = $this->entityManager->getBaseFieldDefinitions('node');
    // Create a node with a fake bundle using the type's UUID so that we can
    // get the default values for workflow settings.
    // @todo Make it possible to get default values without an entity.
    $node = $this->entityManager->getStorage('node')->create(array('type' => $type->uuid()));
  }
  else {
    $form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label()));
    $fields = $this->entityManager->getFieldDefinitions('node', $type->id());
    // Create a node to get the current values for workflow settings fields.
    $node = $this->entityManager->getStorage('node')->create(array('type' => $type->id()));
  }
 
  $form['name'] = array(
    '#title' => t('Name'),
    '#type' => 'textfield',
    '#default_value' => $type->label(),
    '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add content</em> page. This name must be unique.'),
    '#required' => TRUE,
    '#size' => 30,
  );
 
  $form['type'] = array(
    '#type' => 'machine_name',
    '#default_value' => $type->id(),
    '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    '#disabled' => $type->isLocked(),
    '#machine_name' => array(
      'exists' => ['Drupal\node\Entity\NodeType', 'load'],
      'source' => array('name'),
    ),
    '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array(
      '%node-add' => t('Add content'),
    )),
  );
 
  $form['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textarea',
    '#default_value' => $type->getDescription(),
    '#description' => t('This text will be displayed on the <em>Add new content</em> page.'),
  );
 
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    '#attached' => array(
      'library' => array('node/drupal.content_types'),
    ),
  );
 
  $form['submission'] = array(
    '#type' => 'details',
    '#title' => t('Submission form settings'),
    '#group' => 'additional_settings',
    '#open' => TRUE,
  );
  $form['submission']['title_label'] = array(
    '#title' => t('Title field label'),
    '#type' => 'textfield',
    '#default_value' => $fields['title']->getLabel(),
    '#required' => TRUE,
  );
  $form['submission']['preview_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Preview before submitting'),
    '#default_value' => $type->getPreviewMode(),
    '#options' => array(
      DRUPAL_DISABLED => t('Disabled'),
      DRUPAL_OPTIONAL => t('Optional'),
      DRUPAL_REQUIRED => t('Required'),
    ),
  );
  $form['submission']['help'] = array(
    '#type' => 'textarea',
    '#title' => t('Explanation or submission guidelines'),
    '#default_value' => $type->getHelp(),
    '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'),
  );
  $form['workflow'] = array(
    '#type' => 'details',
    '#title' => t('Publishing options'),
    '#group' => 'additional_settings',
  );
  $workflow_options = array(
    'status' => $node->status->value,
    'promote' => $node->promote->value,
    'sticky' => $node->sticky->value,
    'revision' => $type->isNewRevision(),
  );
  // Prepare workflow options to be used for 'checkboxes' form element.
  $keys = array_keys(array_filter($workflow_options));
  $workflow_options = array_combine($keys, $keys);
  $form['workflow']['options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Default options'),
    '#default_value' => $workflow_options,
    '#options' => array(
      'status' => t('Published'),
      'promote' => t('Promoted to front page'),
      'sticky' => t('Sticky at top of lists'),
      'revision' => t('Create new revision'),
    ),
    '#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'),
  );
  if ($this->moduleHandler->moduleExists('language')) {
    $form['language'] = array(
      '#type' => 'details',
      '#title' => t('Language settings'),
      '#group' => 'additional_settings',
    );
 
    $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $type->id());
    $form['language']['language_configuration'] = array(
      '#type' => 'language_configuration',
      '#entity_information' => array(
        'entity_type' => 'node',
        'bundle' => $type->id(),
      ),
      '#default_value' => $language_configuration,
    );
  }
  $form['display'] = array(
    '#type' => 'details',
    '#title' => t('Display settings'),
    '#group' => 'additional_settings',
  );
  $form['display']['display_submitted'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display author and date information'),
    '#default_value' => $type->displaySubmitted(),
    '#description' => t('Author username and publish date will be displayed.'),
  );
 
  return $this->protectBundleIdElement($form);
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.