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

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.
// @see https://www.drupal.org/node/2645614
  ];

  return $form;
}
doc_Drupal
2016-10-29 09:28:46
Comments
Leave a Comment

Please login to continue.