public EntityModerationForm::buildForm(array $form, FormStateInterface $form_state, ContentEntityInterface $entity = NULL)
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- core/modules/content_moderation/src/Form/EntityModerationForm.php, line 77
Class
- EntityModerationForm
- The EntityModerationForm provides a simple UI for changing moderation state.
Namespace
Drupal\content_moderation\Form
Code
public function buildForm(array $form, FormStateInterface $form_state, ContentEntityInterface $entity = NULL) {
/** @var \Drupal\content_moderation\Entity\ModerationState $current_state */
$current_state = $entity->moderation_state->entity;
$transitions = $this->validation->getValidTransitions($entity, $this->currentUser());
// Exclude self-transitions.
$transitions = array_filter($transitions, function(ModerationStateTransition $transition) use ($current_state) {
return $transition->getToState() != $current_state->id();
});
$target_states = [];
/** @var ModerationStateTransition $transition */
foreach ($transitions as $transition) {
$target_states[$transition->getToState()] = $transition->label();
}
if (!count($target_states)) {
return $form;
}
if ($current_state) {
$form['current'] = [
'#type' => 'item',
'#title' => $this->t('Status'),
'#markup' => $current_state->label(),
];
}
// Persist the entity so we can access it in the submit handler.
$form_state->set('entity', $entity);
$form['new_state'] = [
'#type' => 'select',
'#title' => $this->t('Moderate'),
'#options' => $target_states,
];
$form['revision_log'] = [
'#type' => 'textfield',
'#title' => $this->t('Log message'),
'#size' => 30,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Apply'),
];
$form['#theme'] = ['entity_moderation_form'];
return $form;
}
Please login to continue.