public TranslationStatusForm::buildForm(array $form, FormStateInterface $form_state)
Form builder for displaying the current translation status.
Overrides FormInterface::buildForm
File
- core/modules/locale/src/Form/TranslationStatusForm.php, line 65
Class
- TranslationStatusForm
- Provides a translation status form.
Namespace
Drupal\locale\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 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 | public function buildForm( array $form , FormStateInterface $form_state ) { $languages = locale_translatable_language_list(); $status = locale_translation_get_status(); $options = array (); $languages_update = array (); $languages_not_found = array (); $projects_update = array (); // Prepare information about projects which have available translation // updates. if ( $languages && $status ) { $updates = $this ->prepareUpdateData( $status ); // Build data options for the select table. foreach ( $updates as $langcode => $update ) { $title = $languages [ $langcode ]->getName(); $locale_translation_update_info = array ( '#theme' => 'locale_translation_update_info' ); foreach ( array ( 'updates' , 'not_found' ) as $update_status ) { if (isset( $update [ $update_status ])) { $locale_translation_update_info [ '#' . $update_status ] = $update [ $update_status ]; } } $options [ $langcode ] = array ( 'title' => array ( 'data' => array ( '#title' => $title , '#plain_text' => $title , ), ), 'status' => array ( 'class' => array ( 'description' , 'priority-low' ), 'data' => $locale_translation_update_info , ), ); if (! empty ( $update [ 'not_found' ])) { $languages_not_found [ $langcode ] = $langcode ; } if (! empty ( $update [ 'updates' ])) { $languages_update [ $langcode ] = $langcode ; } } // Sort the table data on language name. uasort( $options , function ( $a , $b ) { return strcasecmp ( $a [ 'title' ][ 'data' ][ '#title' ], $b [ 'title' ][ 'data' ][ '#title' ]); }); $languages_not_found = array_diff ( $languages_not_found , $languages_update ); } $last_checked = $this ->state->get( 'locale.translation_last_checked' ); $form [ 'last_checked' ] = array ( '#theme' => 'locale_translation_last_check' , '#last' => $last_checked , ); $header = array ( 'title' => array ( 'data' => $this ->t( 'Language' ), 'class' => array ( 'title' ), ), 'status' => array ( 'data' => $this ->t( 'Status' ), 'class' => array ( 'status' , 'priority-low' ), ), ); if (! $languages ) { $empty = $this ->t( 'No translatable languages available. <a href=":add_language">Add a language</a> first.' , array ( ':add_language' => $this ->url( 'entity.configurable_language.collection' ), )); } elseif ( $status ) { $empty = $this ->t( 'All translations up to date.' ); } else { $empty = $this ->t( 'No translation status available. <a href=":check">Check manually</a>.' , array ( ':check' => $this ->url( 'locale.check_translation' ), )); } // The projects which require an update. Used by the _submit callback. $form [ 'projects_update' ] = array ( '#type' => 'value' , '#value' => $projects_update , ); $form [ 'langcodes' ] = array ( '#type' => 'tableselect' , '#header' => $header , '#options' => $options , '#default_value' => $languages_update , '#empty' => $empty , '#js_select' => TRUE, '#multiple' => TRUE, '#required' => TRUE, '#not_found' => $languages_not_found , '#after_build' => array ( 'locale_translation_language_table' ), ); $form [ '#attached' ][ 'library' ][] = 'locale/drupal.locale.admin' ; $form [ 'actions' ] = array ( '#type' => 'actions' ); if ( $languages_update ) { $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => $this ->t( 'Update translations' ), ); } return $form ; } |
Please login to continue.