public NodeForm::form(array $form, FormStateInterface $form_state)
Gets the actual form array to be built.
Overrides ContentEntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/modules/node/src/NodeForm.php, line 67
Class
- NodeForm
- Form handler for the node edit forms.
Namespace
Drupal\node
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | public function form( array $form , FormStateInterface $form_state ) { // Try to restore from temp store, this must be done before calling // parent::form(). $uuid = $this ->entity->uuid(); $store = $this ->tempStoreFactory->get( 'node_preview' ); // If the user is creating a new node, the UUID is passed in the request. if ( $request_uuid = \Drupal::request()->query->get( 'uuid' )) { $uuid = $request_uuid ; } if ( $preview = $store ->get( $uuid )) { /** @var $preview \Drupal\Core\Form\FormStateInterface */ foreach ( $preview ->getValues() as $name => $value ) { $form_state ->setValue( $name , $value ); } // Rebuild the form. $form_state ->setRebuild(); $this ->entity = $preview ->getFormObject()->getEntity(); $this ->entity->in_preview = NULL; // Remove the stale temp store entry for existing nodes. if (! $this ->entity->isNew()) { $store -> delete ( $uuid ); } $this ->hasBeenPreviewed = TRUE; } /** @var \Drupal\node\NodeInterface $node */ $node = $this ->entity; if ( $this ->operation == 'edit' ) { $form [ '#title' ] = $this ->t( '<em>Edit @type</em> @title' , array ( '@type' => node_get_type_label( $node ), '@title' => $node ->label())); } $current_user = $this ->currentUser(); // Changed must be sent to the client, for later overwrite error checking. $form [ 'changed' ] = array ( '#type' => 'hidden' , '#default_value' => $node ->getChangedTime(), ); $form [ 'advanced' ] = array ( '#type' => 'vertical_tabs' , '#attributes' => array ( 'class' => array ( 'entity-meta' )), '#weight' => 99, ); $form = parent::form( $form , $form_state ); // Add a revision_log field if the "Create new revision" option is checked, // or if the current user has the ability to check that option. $form [ 'revision_information' ] = array ( '#type' => 'details' , '#group' => 'advanced' , '#title' => t( 'Revision information' ), // Open by default when "Create new revision" is checked. '#open' => $node ->isNewRevision(), '#attributes' => array ( 'class' => array ( 'node-form-revision-information' ), ), '#attached' => array ( 'library' => array ( 'node/drupal.node' ), ), '#weight' => 20, '#optional' => TRUE, ); $form [ 'revision' ] = array ( '#type' => 'checkbox' , '#title' => t( 'Create new revision' ), '#default_value' => $node ->type->entity->isNewRevision(), '#access' => $current_user ->hasPermission( 'administer nodes' ), '#group' => 'revision_information' , ); $form [ 'revision_log' ] += array ( '#states' => array ( 'visible' => array ( ':input[name="revision"]' => array ( 'checked' => TRUE), ), ), '#group' => 'revision_information' , ); // Node author information for administrators. $form [ 'author' ] = array ( '#type' => 'details' , '#title' => t( 'Authoring information' ), '#group' => 'advanced' , '#attributes' => array ( 'class' => array ( 'node-form-author' ), ), '#attached' => array ( 'library' => array ( 'node/drupal.node' ), ), '#weight' => 90, '#optional' => TRUE, ); if (isset( $form [ 'uid' ])) { $form [ 'uid' ][ '#group' ] = 'author' ; } if (isset( $form [ 'created' ])) { $form [ 'created' ][ '#group' ] = 'author' ; } // Node options for administrators. $form [ 'options' ] = array ( '#type' => 'details' , '#title' => t( 'Promotion options' ), '#group' => 'advanced' , '#attributes' => array ( 'class' => array ( 'node-form-options' ), ), '#attached' => array ( 'library' => array ( 'node/drupal.node' ), ), '#weight' => 95, '#optional' => TRUE, ); if (isset( $form [ 'promote' ])) { $form [ 'promote' ][ '#group' ] = 'options' ; } if (isset( $form [ 'sticky' ])) { $form [ 'sticky' ][ '#group' ] = 'options' ; } $form [ '#attached' ][ 'library' ][] = 'node/form' ; $form [ '#entity_builders' ][ 'update_status' ] = [ $this , 'updateStatus' ]; return $form ; } |
Please login to continue.