ModerationStateForm::form

public ModerationStateForm::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/content_moderation/src/Form/ModerationStateForm.php, line 17

Class

ModerationStateForm
Class ModerationStateForm.

Namespace

Drupal\content_moderation\Form

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
public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
 
  /* @var \Drupal\content_moderation\ModerationStateInterface $moderation_state */
  $moderation_state = $this->entity;
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $moderation_state->label(),
    '#description' => $this->t('Label for the Moderation state.'),
    '#required' => TRUE,
  );
 
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $moderation_state->id(),
    '#machine_name' => array(
      'exists' => [ModerationState::class, 'load'],
    ),
    '#disabled' => !$moderation_state->isNew(),
  );
 
  $form['published'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Published'),
    '#description' => $this->t('When content reaches this state it should be published.'),
    '#default_value' => $moderation_state->isPublishedState(),
  ];
 
  $form['default_revision'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Default revision'),
    '#description' => $this->t('When content reaches this state it should be made the default revision; this is implied for published states.'),
    '#default_value' => $moderation_state->isDefaultRevisionState(),
    // @todo Add form #state to force "make default" on when "published" is
// on for a state.
  ];
 
  return $form;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.