public NodeTranslationHandler::entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity)
Performs the needed alterations to the entity form.
Parameters
array $form: The entity form to be altered to provide the translation workflow.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\Core\Entity\EntityInterface $entity: The entity being created or edited.
Overrides ContentTranslationHandler::entityFormAlter
File
- core/modules/node/src/NodeTranslationHandler.php, line 17
Class
- NodeTranslationHandler
- Defines the translation handler for nodes.
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 | public function entityFormAlter( array & $form , FormStateInterface $form_state , EntityInterface $entity ) { parent::entityFormAlter( $form , $form_state , $entity ); // Move the translation fieldset to a vertical tab. if (isset( $form [ 'content_translation' ])) { $form [ 'content_translation' ] += array ( '#group' => 'advanced' , '#attributes' => array ( 'class' => array ( 'node-translation-options' ), ), ); $form [ 'content_translation' ][ '#weight' ] = 100; // We do not need to show these values on node forms: they inherit the // basic node property values. $form [ 'content_translation' ][ 'status' ][ '#access' ] = FALSE; $form [ 'content_translation' ][ 'name' ][ '#access' ] = FALSE; $form [ 'content_translation' ][ 'created' ][ '#access' ] = FALSE; } $form_object = $form_state ->getFormObject(); $form_langcode = $form_object ->getFormLangcode( $form_state ); $translations = $entity ->getTranslationLanguages(); $status_translatable = NULL; // Change the submit button labels if there was a status field they affect // in which case their publishing / unpublishing may or may not apply // to all translations. if (! $entity ->isNew() && (!isset( $translations [ $form_langcode ]) || count ( $translations ) > 1)) { foreach ( $entity ->getFieldDefinitions() as $property_name => $definition ) { if ( $property_name == 'status' ) { $status_translatable = $definition ->isTranslatable(); } } if (isset( $status_translatable )) { foreach ( array ( 'publish' , 'unpublish' , 'submit' ) as $button ) { if (isset( $form [ 'actions' ][ $button ])) { $form [ 'actions' ][ $button ][ '#value' ] .= ' ' . ( $status_translatable ? t( '(this translation)' ) : t( '(all translations)' )); } } } } } |
Please login to continue.