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
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 | 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.