public CommentTypeForm::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/comment/src/CommentTypeForm.php, line 69
Class
- CommentTypeForm
- Base form handler for comment type edit forms.
Namespace
Drupal\comment
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 | public function form( array $form , FormStateInterface $form_state ) { $form = parent::form( $form , $form_state ); $comment_type = $this ->entity; $form [ 'label' ] = array ( '#type' => 'textfield' , '#title' => t( 'Label' ), '#maxlength' => 255, '#default_value' => $comment_type ->label(), '#required' => TRUE, ); $form [ 'id' ] = array ( '#type' => 'machine_name' , '#default_value' => $comment_type ->id(), '#machine_name' => array ( 'exists' => '\Drupal\comment\Entity\CommentType::load' , ), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => ! $comment_type ->isNew(), ); $form [ 'description' ] = array ( '#type' => 'textarea' , '#default_value' => $comment_type ->getDescription(), '#description' => t( 'Describe this comment type. The text will be displayed on the <em>Comment types</em> administration overview page.' ), '#title' => t( 'Description' ), ); if ( $comment_type ->isNew()) { $options = array (); foreach ( $this ->entityManager->getDefinitions() as $entity_type ) { // Only expose entities that have field UI enabled, only those can // get comment fields added in the UI. if ( $entity_type ->get( 'field_ui_base_route' )) { $options [ $entity_type ->id()] = $entity_type ->getLabel(); } } $form [ 'target_entity_type_id' ] = array ( '#type' => 'select' , '#default_value' => $comment_type ->getTargetEntityTypeId(), '#title' => t( 'Target entity type' ), '#options' => $options , '#description' => t( 'The target entity type can not be changed after the comment type has been created.' ) ); } else { $form [ 'target_entity_type_id_display' ] = array ( '#type' => 'item' , '#markup' => $this ->entityManager->getDefinition( $comment_type ->getTargetEntityTypeId())->getLabel(), '#title' => t( 'Target entity type' ), ); } if ( $this ->moduleHandler->moduleExists( 'content_translation' )) { $form [ 'language' ] = array ( '#type' => 'details' , '#title' => t( 'Language settings' ), '#group' => 'additional_settings' , ); $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle( 'comment' , $comment_type ->id()); $form [ 'language' ][ 'language_configuration' ] = array ( '#type' => 'language_configuration' , '#entity_information' => array ( 'entity_type' => 'comment' , 'bundle' => $comment_type ->id(), ), '#default_value' => $language_configuration , ); $form [ '#submit' ][] = 'language_configuration_element_submit' ; } $form [ 'actions' ] = array ( '#type' => 'actions' ); $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t( 'Save' ), ); return $form ; } |
Please login to continue.