Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
< ? php
/**
* @ file
2013-06-25 19:16:20 +00:00
* The content translation administration forms .
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
*/
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
use Drupal\content_translation\BundleTranslationSettingsInterface ;
2018-03-06 03:54:48 +00:00
use Drupal\content_translation\ContentTranslationManager ;
2014-08-29 16:48:20 +00:00
use Drupal\Core\Config\Entity\ThirdPartySettingsInterface ;
2014-06-20 17:40:27 +00:00
use Drupal\Core\Entity\ContentEntityTypeInterface ;
2015-06-29 14:22:57 +00:00
use Drupal\Core\Entity\EntityTypeInterface ;
2013-10-19 08:12:13 +00:00
use Drupal\Core\Field\FieldDefinitionInterface ;
2015-06-29 14:22:57 +00:00
use Drupal\Core\Field\FieldStorageDefinitionInterface ;
2014-07-31 00:50:42 +00:00
use Drupal\Core\Form\FormStateInterface ;
2014-06-10 16:52:58 +00:00
use Drupal\Core\Language\LanguageInterface ;
2014-03-31 17:37:55 +00:00
use Drupal\Core\Render\Element ;
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
2012-12-29 08:13:54 +00:00
/**
2013-02-19 06:57:04 +00:00
* Returns a form element to configure field synchronization .
2012-12-29 08:13:54 +00:00
*
2013-10-19 08:12:13 +00:00
* @ param \Drupal\Core\Field\FieldDefinitionInterface $field
2013-10-04 07:55:32 +00:00
* A field definition object .
2016-02-25 15:54:27 +00:00
* @ param string $element_name
* ( optional ) The element name , which is added to drupalSettings so that
* javascript can manipulate the form element .
2013-02-19 06:57:04 +00:00
*
* @ return array
* A form element to configure field synchronization .
*/
2016-02-25 15:54:27 +00:00
function content_translation_field_sync_widget ( FieldDefinitionInterface $field , $element_name = 'third_party_settings[content_translation][translation_sync]' ) {
2014-08-29 16:48:20 +00:00
// No way to store field sync information on this field.
if ( ! ( $field instanceof ThirdPartySettingsInterface )) {
2017-03-04 01:20:24 +00:00
return [];
2014-08-29 16:48:20 +00:00
}
2013-02-19 06:57:04 +00:00
2017-03-04 01:20:24 +00:00
$element = [];
2014-03-27 16:21:47 +00:00
$definition = \Drupal :: service ( 'plugin.manager.field.field_type' ) -> getDefinition ( $field -> getType ());
$column_groups = $definition [ 'column_groups' ];
2013-10-04 07:55:32 +00:00
if ( ! empty ( $column_groups ) && count ( $column_groups ) > 1 ) {
2016-02-25 15:54:27 +00:00
$options = [];
$default = [];
$require_all_groups_for_translation = [];
2013-02-19 06:57:04 +00:00
2013-10-04 07:55:32 +00:00
foreach ( $column_groups as $group => $info ) {
2013-02-19 06:57:04 +00:00
$options [ $group ] = $info [ 'label' ];
$default [ $group ] = ! empty ( $info [ 'translatable' ]) ? $group : FALSE ;
2016-02-25 15:54:27 +00:00
if ( ! empty ( $info [ 'require_all_groups_for_translation' ])) {
$require_all_groups_for_translation [] = $group ;
}
2013-02-19 06:57:04 +00:00
}
2014-08-29 16:48:20 +00:00
$default = $field -> getThirdPartySetting ( 'content_translation' , 'translation_sync' , $default );
2013-03-10 06:18:48 +00:00
2017-03-04 01:20:24 +00:00
$element = [
2013-02-19 06:57:04 +00:00
'#type' => 'checkboxes' ,
'#title' => t ( 'Translatable elements' ),
'#options' => $options ,
2014-08-29 16:48:20 +00:00
'#default_value' => $default ,
2017-03-04 01:20:24 +00:00
];
2016-02-25 15:54:27 +00:00
if ( $require_all_groups_for_translation ) {
// The actual checkboxes are sometimes rendered separately and the parent
// element is ignored. Attach to the first option to ensure that this
// does not get lost.
$element [ key ( $options )][ '#attached' ][ 'drupalSettings' ][ 'contentTranslationDependentOptions' ] = [
'dependent_selectors' => [
2018-05-11 09:40:33 +00:00
$element_name => $require_all_groups_for_translation ,
2016-02-25 15:54:27 +00:00
],
];
$element [ key ( $options )][ '#attached' ][ 'library' ][] = 'content_translation/drupal.content_translation.admin' ;
}
2013-02-19 06:57:04 +00:00
}
return $element ;
}
/**
* ( proxied ) Implements hook_form_FORM_ID_alter () .
2012-12-29 08:13:54 +00:00
*/
2014-07-31 00:50:42 +00:00
function _content_translation_form_language_content_settings_form_alter ( array & $form , FormStateInterface $form_state ) {
2012-12-29 08:13:54 +00:00
// Inject into the content language settings the translation settings if the
// user has the required permission.
Issue #2061977 by InternetDevels, kim.pepper, ianthomas_uk, herom, rhm50, naveenvalecha, andypost, mandar.harkare, sergeypavlenko, sidharthap, SIz, tkuldeep17: Replace user_access() calls with ->hasPermission() in all core modules except user.
2014-07-12 06:55:56 +00:00
if ( ! \Drupal :: currentUser () -> hasPermission ( 'administer content translation' )) {
2012-12-29 08:13:54 +00:00
return ;
}
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
2014-12-11 09:09:33 +00:00
$content_translation_manager = \Drupal :: service ( 'content_translation.manager' );
2012-12-29 08:13:54 +00:00
$default = $form [ 'entity_types' ][ '#default_value' ];
2014-02-10 09:24:05 +00:00
foreach ( $default as $entity_type_id => $enabled ) {
2014-12-11 09:09:33 +00:00
$default [ $entity_type_id ] = $enabled || $content_translation_manager -> isEnabled ( $entity_type_id ) ? $entity_type_id : FALSE ;
2012-12-29 08:13:54 +00:00
}
$form [ 'entity_types' ][ '#default_value' ] = $default ;
2014-03-09 19:59:45 +00:00
$form [ '#attached' ][ 'library' ][] = 'content_translation/drupal.content_translation.admin' ;
2012-12-29 08:13:54 +00:00
2019-04-26 07:09:28 +00:00
$entity_type_manager = \Drupal :: entityTypeManager ();
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal :: service ( 'entity_field.manager' );
2016-07-31 20:20:40 +00:00
$bundle_info_service = \Drupal :: service ( 'entity_type.bundle.info' );
2014-02-10 09:24:05 +00:00
foreach ( $form [ '#labels' ] as $entity_type_id => $label ) {
2019-04-26 07:09:28 +00:00
$entity_type = $entity_type_manager -> getDefinition ( $entity_type_id );
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_field_manager -> getFieldStorageDefinitions ( $entity_type_id ) : [];
2014-06-20 17:40:27 +00:00
2015-04-28 08:53:05 +00:00
$entity_type_translatable = $content_translation_manager -> isSupported ( $entity_type_id );
2016-07-31 20:20:40 +00:00
foreach ( $bundle_info_service -> getBundleInfo ( $entity_type_id ) as $bundle => $bundle_info ) {
2012-12-29 08:13:54 +00:00
// Here we do not want the widget to be altered and hold also the "Enable
// translation" checkbox, which would be redundant. Hence we add this key
2015-04-28 08:53:05 +00:00
// to be able to skip alterations. Alter the title and display the message
// about UI integration.
2014-02-10 09:24:05 +00:00
$form [ 'settings' ][ $entity_type_id ][ $bundle ][ 'settings' ][ 'language' ][ '#content_translation_skip_alter' ] = TRUE ;
2015-02-06 12:28:32 +00:00
if ( ! $entity_type_translatable ) {
2017-03-04 01:20:24 +00:00
$form [ 'settings' ][ $entity_type_id ][ '#title' ] = t ( '@label (Translation is not supported).' , [ '@label' => $entity_type -> getLabel ()]);
2015-02-06 12:28:32 +00:00
continue ;
}
2012-12-29 08:13:54 +00:00
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
// Displayed the "shared fields widgets" toggle.
if ( $content_translation_manager instanceof BundleTranslationSettingsInterface ) {
$settings = $content_translation_manager -> getBundleTranslationSettings ( $entity_type_id , $bundle );
2018-03-06 03:54:48 +00:00
$force_hidden = ContentTranslationManager :: isPendingRevisionSupportEnabled ( $entity_type_id , $bundle );
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
$form [ 'settings' ][ $entity_type_id ][ $bundle ][ 'settings' ][ 'content_translation' ][ 'untranslatable_fields_hide' ] = [
'#type' => 'checkbox' ,
'#title' => t ( 'Hide non translatable fields on translation forms' ),
2018-03-06 03:54:48 +00:00
'#default_value' => $force_hidden || ! empty ( $settings [ 'untranslatable_fields_hide' ]),
'#disabled' => $force_hidden ,
'#description' => $force_hidden ? t ( 'Moderated content requires non-translatable fields to be edited in the original language form.' ) : '' ,
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
'#states' => [
'visible' => [
':input[name="settings[' . $entity_type_id . '][' . $bundle . '][translatable]"]' => [
'checked' => TRUE ,
],
],
],
];
}
2019-04-26 07:09:28 +00:00
$fields = $entity_field_manager -> getFieldDefinitions ( $entity_type_id , $bundle );
2014-09-03 15:34:18 +00:00
if ( $fields ) {
foreach ( $fields as $field_name => $definition ) {
2016-09-14 09:19:34 +00:00
if ( $definition -> isComputed () || ( ! empty ( $storage_definitions [ $field_name ]) && _content_translation_is_field_translatability_configurable ( $entity_type , $storage_definitions [ $field_name ]))) {
2017-03-04 01:20:24 +00:00
$form [ 'settings' ][ $entity_type_id ][ $bundle ][ 'fields' ][ $field_name ] = [
2014-09-03 15:34:18 +00:00
'#label' => $definition -> getLabel (),
'#type' => 'checkbox' ,
'#default_value' => $definition -> isTranslatable (),
2017-03-04 01:20:24 +00:00
];
2014-09-03 15:34:18 +00:00
// Display the column translatability configuration widget.
2016-02-25 15:54:27 +00:00
$column_element = content_translation_field_sync_widget ( $definition , " settings[ { $entity_type_id } ][ { $bundle } ][columns][ { $field_name } ] " );
2014-09-03 15:34:18 +00:00
if ( $column_element ) {
$form [ 'settings' ][ $entity_type_id ][ $bundle ][ 'columns' ][ $field_name ] = $column_element ;
}
}
}
if ( ! empty ( $form [ 'settings' ][ $entity_type_id ][ $bundle ][ 'fields' ])) {
// Only show the checkbox to enable translation if the bundles in the
// entity might have fields and if there are fields to translate.
2017-03-04 01:20:24 +00:00
$form [ 'settings' ][ $entity_type_id ][ $bundle ][ 'translatable' ] = [
2013-05-06 10:31:46 +00:00
'#type' => 'checkbox' ,
2014-12-11 09:09:33 +00:00
'#default_value' => $content_translation_manager -> isEnabled ( $entity_type_id , $bundle ),
2017-03-04 01:20:24 +00:00
];
2013-02-19 06:57:04 +00:00
}
2012-12-29 08:13:54 +00:00
}
}
}
2014-06-20 17:40:27 +00:00
2013-06-25 19:16:20 +00:00
$form [ '#validate' ][] = 'content_translation_form_language_content_settings_validate' ;
$form [ '#submit' ][] = 'content_translation_form_language_content_settings_submit' ;
2012-12-29 08:13:54 +00:00
}
2018-05-11 09:26:36 +00:00
2015-06-29 14:22:57 +00:00
/**
* Checks whether translatability should be configurable for a field .
*
* @ param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition .
* @ param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition
* The field storage definition .
*
* @ return bool
* TRUE if field translatability can be configured , FALSE otherwise .
*
* @ internal
*/
function _content_translation_is_field_translatability_configurable ( EntityTypeInterface $entity_type , FieldStorageDefinitionInterface $definition ) {
// Allow to configure only fields supporting multilingual storage. We skip our
// own fields as they are always translatable. Additionally we skip a set of
// well-known fields implementing entity system business logic.
2019-03-26 14:37:28 +00:00
return $definition -> isTranslatable () &&
2015-06-29 14:22:57 +00:00
$definition -> getProvider () != 'content_translation' &&
! in_array ( $definition -> getName (), [ $entity_type -> getKey ( 'langcode' ), $entity_type -> getKey ( 'default_langcode' ), 'revision_translation_affected' ]);
}
2012-12-29 08:13:54 +00:00
2013-02-19 06:57:04 +00:00
/**
2020-12-16 12:37:42 +00:00
* ( proxied ) Implements hook_preprocess_HOOK () .
2013-02-19 06:57:04 +00:00
*/
2013-06-25 19:16:20 +00:00
function _content_translation_preprocess_language_content_settings_table ( & $variables ) {
2013-02-19 06:57:04 +00:00
// Alter the 'build' variable injecting the translation settings if the user
// has the required permission.
Issue #2061977 by InternetDevels, kim.pepper, ianthomas_uk, herom, rhm50, naveenvalecha, andypost, mandar.harkare, sergeypavlenko, sidharthap, SIz, tkuldeep17: Replace user_access() calls with ->hasPermission() in all core modules except user.
2014-07-12 06:55:56 +00:00
if ( ! \Drupal :: currentUser () -> hasPermission ( 'administer content translation' )) {
2013-02-19 06:57:04 +00:00
return ;
}
$element = $variables [ 'element' ];
$build = & $variables [ 'build' ];
2017-03-04 01:20:24 +00:00
array_unshift ( $build [ '#header' ], [ 'data' => t ( 'Translatable' ), 'class' => [ 'translatable' ]]);
$rows = [];
2013-02-19 06:57:04 +00:00
2014-03-31 17:37:55 +00:00
foreach ( Element :: children ( $element ) as $bundle ) {
2017-03-04 01:20:24 +00:00
$field_names = ! empty ( $element [ $bundle ][ 'fields' ]) ? Element :: children ( $element [ $bundle ][ 'fields' ]) : [];
2013-05-06 10:31:46 +00:00
if ( ! empty ( $element [ $bundle ][ 'translatable' ])) {
$checkbox_id = $element [ $bundle ][ 'translatable' ][ '#id' ];
}
2013-02-19 06:57:04 +00:00
$rows [ $bundle ] = $build [ '#rows' ][ $bundle ];
2013-05-06 10:31:46 +00:00
if ( ! empty ( $element [ $bundle ][ 'translatable' ])) {
2017-03-04 01:20:24 +00:00
$translatable = [
2013-05-06 10:31:46 +00:00
'data' => $element [ $bundle ][ 'translatable' ],
2017-03-04 01:20:24 +00:00
'class' => [ 'translatable' ],
];
2013-05-06 10:31:46 +00:00
array_unshift ( $rows [ $bundle ][ 'data' ], $translatable );
2013-02-19 06:57:04 +00:00
2013-05-06 10:31:46 +00:00
$rows [ $bundle ][ 'data' ][ 1 ][ 'data' ][ '#prefix' ] = '<label for="' . $checkbox_id . '">' ;
}
else {
2017-03-04 01:20:24 +00:00
$translatable = [
2015-02-06 12:28:32 +00:00
'data' => t ( 'N/A' ),
2017-03-04 01:20:24 +00:00
'class' => [ 'untranslatable' ],
];
2013-05-06 10:31:46 +00:00
array_unshift ( $rows [ $bundle ][ 'data' ], $translatable );
}
2013-02-19 06:57:04 +00:00
foreach ( $field_names as $field_name ) {
$field_element = & $element [ $bundle ][ 'fields' ][ $field_name ];
2017-03-04 01:20:24 +00:00
$rows [] = [
'data' => [
[
Issue #2704871 by pepegarciag, Mile23, Manuel Garcia, ieguskiza, snehi, gaurav.pahuja, dimaro, rajeshwari10, gargsuchi, pashupathi nath gajawada, penyaskito, xjm, ZeiP, Wim Leers, alexpott: Replace usages of deprecated method drupal_render()
2017-07-03 15:35:13 +00:00
'data' => \Drupal :: service ( 'renderer' ) -> render ( $field_element ),
2017-03-04 01:20:24 +00:00
'class' => [ 'translatable' ],
],
[
'data' => [
2013-02-19 06:57:04 +00:00
'#prefix' => '<label for="' . $field_element [ '#id' ] . '">' ,
'#suffix' => '</label>' ,
2017-03-04 01:20:24 +00:00
'bundle' => [
2013-06-17 19:58:27 +00:00
'#prefix' => '<span class="visually-hidden">' ,
2013-02-19 06:57:04 +00:00
'#suffix' => '</span> ' ,
2015-08-31 07:43:39 +00:00
'#plain_text' => $element [ $bundle ][ 'settings' ][ '#label' ],
2017-03-04 01:20:24 +00:00
],
'field' => [
2015-08-31 07:43:39 +00:00
'#plain_text' => $field_element [ '#label' ],
2017-03-04 01:20:24 +00:00
],
],
'class' => [ 'field' ],
],
[
2013-02-19 06:57:04 +00:00
'data' => '' ,
2017-03-04 01:20:24 +00:00
'class' => [ 'operations' ],
],
],
2019-03-28 06:39:30 +00:00
'#field_name' => $field_name ,
2017-03-04 01:20:24 +00:00
'class' => [ 'field-settings' ],
];
2013-02-19 06:57:04 +00:00
if ( ! empty ( $element [ $bundle ][ 'columns' ][ $field_name ])) {
$column_element = & $element [ $bundle ][ 'columns' ][ $field_name ];
2014-03-31 17:37:55 +00:00
foreach ( Element :: children ( $column_element ) as $key ) {
2013-02-19 06:57:04 +00:00
$column_label = $column_element [ $key ][ '#title' ];
unset ( $column_element [ $key ][ '#title' ]);
2017-03-04 01:20:24 +00:00
$rows [] = [
'data' => [
[
Issue #2704871 by pepegarciag, Mile23, Manuel Garcia, ieguskiza, snehi, gaurav.pahuja, dimaro, rajeshwari10, gargsuchi, pashupathi nath gajawada, penyaskito, xjm, ZeiP, Wim Leers, alexpott: Replace usages of deprecated method drupal_render()
2017-07-03 15:35:13 +00:00
'data' => \Drupal :: service ( 'renderer' ) -> render ( $column_element [ $key ]),
2017-03-04 01:20:24 +00:00
'class' => [ 'translatable' ],
],
[
'data' => [
2013-02-19 06:57:04 +00:00
'#prefix' => '<label for="' . $column_element [ $key ][ '#id' ] . '">' ,
'#suffix' => '</label>' ,
2017-03-04 01:20:24 +00:00
'bundle' => [
2013-06-17 19:58:27 +00:00
'#prefix' => '<span class="visually-hidden">' ,
2013-02-19 06:57:04 +00:00
'#suffix' => '</span> ' ,
2015-08-31 07:43:39 +00:00
'#plain_text' => $element [ $bundle ][ 'settings' ][ '#label' ],
2017-03-04 01:20:24 +00:00
],
'field' => [
2013-06-17 19:58:27 +00:00
'#prefix' => '<span class="visually-hidden">' ,
2013-02-19 06:57:04 +00:00
'#suffix' => '</span> ' ,
2015-08-31 07:43:39 +00:00
'#plain_text' => $field_element [ '#label' ],
2017-03-04 01:20:24 +00:00
],
'columns' => [
2015-08-31 07:43:39 +00:00
'#plain_text' => $column_label ,
2017-03-04 01:20:24 +00:00
],
],
'class' => [ 'column' ],
],
[
2013-02-19 06:57:04 +00:00
'data' => '' ,
2017-03-04 01:20:24 +00:00
'class' => [ 'operations' ],
],
],
'class' => [ 'column-settings' ],
];
2013-02-19 06:57:04 +00:00
}
}
}
}
$build [ '#rows' ] = $rows ;
}
2012-12-29 08:13:54 +00:00
/**
2013-06-25 19:16:20 +00:00
* Form validation handler for content_translation_admin_settings_form () .
2012-12-29 08:13:54 +00:00
*
2013-06-25 19:16:20 +00:00
* @ see content_translation_admin_settings_form_submit ()
2012-12-29 08:13:54 +00:00
*/
2014-07-31 00:50:42 +00:00
function content_translation_form_language_content_settings_validate ( array $form , FormStateInterface $form_state ) {
2014-08-08 16:25:54 +00:00
$settings = & $form_state -> getValue ( 'settings' );
2012-12-29 08:13:54 +00:00
foreach ( $settings as $entity_type => $entity_settings ) {
foreach ( $entity_settings as $bundle => $bundle_settings ) {
if ( ! empty ( $bundle_settings [ 'translatable' ])) {
$name = " settings][ $entity_type ][ $bundle ][translatable " ;
$translatable_fields = isset ( $settings [ $entity_type ][ $bundle ][ 'fields' ]) ? array_filter ( $settings [ $entity_type ][ $bundle ][ 'fields' ]) : FALSE ;
if ( empty ( $translatable_fields )) {
2017-03-04 01:20:24 +00:00
$t_args = [ '%bundle' => $form [ 'settings' ][ $entity_type ][ $bundle ][ 'settings' ][ '#label' ]];
2014-08-22 01:04:33 +00:00
$form_state -> setErrorByName ( $name , t ( 'At least one field needs to be translatable to enable %bundle for translation.' , $t_args ));
2012-12-29 08:13:54 +00:00
}
$values = $bundle_settings [ 'settings' ][ 'language' ];
2014-12-08 16:25:00 +00:00
if ( empty ( $values [ 'language_alterable' ]) && \Drupal :: languageManager () -> isLanguageLocked ( $values [ 'langcode' ])) {
2014-06-10 16:52:58 +00:00
foreach ( \Drupal :: languageManager () -> getLanguages ( LanguageInterface :: STATE_LOCKED ) as $language ) {
2014-10-16 13:45:53 +00:00
$locked_languages [] = $language -> getName ();
2012-12-29 08:13:54 +00:00
}
2017-03-04 01:20:24 +00:00
$form_state -> setErrorByName ( $name , t ( 'Translation is not supported if language is always one of: @locked_languages' , [ '@locked_languages' => implode ( ', ' , $locked_languages )]));
2012-12-29 08:13:54 +00:00
}
}
}
}
}
/**
2013-06-25 19:16:20 +00:00
* Form submission handler for content_translation_admin_settings_form () .
2012-12-29 08:13:54 +00:00
*
2013-06-25 19:16:20 +00:00
* @ see content_translation_admin_settings_form_validate ()
2012-12-29 08:13:54 +00:00
*/
2014-07-31 00:50:42 +00:00
function content_translation_form_language_content_settings_submit ( array $form , FormStateInterface $form_state ) {
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
$content_translation_manager = \Drupal :: service ( 'content_translation.manager' );
2014-08-08 16:25:54 +00:00
$entity_types = $form_state -> getValue ( 'entity_types' );
$settings = & $form_state -> getValue ( 'settings' );
2012-12-29 08:13:54 +00:00
// If an entity type is not translatable all its bundles and fields must be
// marked as non-translatable. Similarly, if a bundle is made non-translatable
// all of its fields will be not translatable.
2014-06-20 17:40:27 +00:00
foreach ( $settings as $entity_type_id => & $entity_settings ) {
foreach ( $entity_settings as $bundle => & $bundle_settings ) {
2019-04-26 07:09:28 +00:00
$fields = \Drupal :: service ( 'entity_field.manager' ) -> getFieldDefinitions ( $entity_type_id , $bundle );
2013-05-06 10:31:46 +00:00
if ( ! empty ( $bundle_settings [ 'translatable' ])) {
2014-06-20 17:40:27 +00:00
$bundle_settings [ 'translatable' ] = $bundle_settings [ 'translatable' ] && $entity_types [ $entity_type_id ];
2013-05-06 10:31:46 +00:00
}
2012-12-29 08:13:54 +00:00
if ( ! empty ( $bundle_settings [ 'fields' ])) {
foreach ( $bundle_settings [ 'fields' ] as $field_name => $translatable ) {
2014-06-20 17:40:27 +00:00
$translatable = $translatable && $bundle_settings [ 'translatable' ];
2013-02-19 06:57:04 +00:00
// If we have column settings and no column is translatable, no point
// in making the field translatable.
if ( isset ( $bundle_settings [ 'columns' ][ $field_name ]) && ! array_filter ( $bundle_settings [ 'columns' ][ $field_name ])) {
2014-06-20 17:40:27 +00:00
$translatable = FALSE ;
2013-02-19 06:57:04 +00:00
}
2014-08-19 10:25:28 +00:00
$field_config = $fields [ $field_name ] -> getConfig ( $bundle );
if ( $field_config -> isTranslatable () != $translatable ) {
$field_config
-> setTranslatable ( $translatable )
-> save ();
2013-10-14 15:40:28 +00:00
}
2012-12-29 08:13:54 +00:00
}
}
2014-08-29 16:48:20 +00:00
if ( isset ( $bundle_settings [ 'translatable' ])) {
// Store whether a bundle has translation enabled or not.
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
$content_translation_manager -> setEnabled ( $entity_type_id , $bundle , $bundle_settings [ 'translatable' ]);
// Store any other bundle settings.
if ( $content_translation_manager instanceof BundleTranslationSettingsInterface ) {
$content_translation_manager -> setBundleTranslationSettings ( $entity_type_id , $bundle , $bundle_settings [ 'settings' ][ 'content_translation' ]);
}
2014-08-29 16:48:20 +00:00
// Save translation_sync settings.
if ( ! empty ( $bundle_settings [ 'columns' ])) {
foreach ( $bundle_settings [ 'columns' ] as $field_name => $column_settings ) {
$field_config = $fields [ $field_name ] -> getConfig ( $bundle );
if ( $field_config -> isTranslatable ()) {
$field_config -> setThirdPartySetting ( 'content_translation' , 'translation_sync' , $column_settings );
}
// If the field does not have translatable enabled we need to reset
// the sync settings to their defaults.
else {
$field_config -> unsetThirdPartySetting ( 'content_translation' , 'translation_sync' );
}
$field_config -> save ();
}
}
}
2012-12-29 08:13:54 +00:00
}
}
Issue #2878556 by plach, matsbla, vijaycs85, Gábor Hojtsy, catch, gabesullice, effulgentsia, hchonov, hass, amateescu, xjm: Ensure that changes to untranslatable fields affect only one translation in pending revisions
2018-01-20 15:56:17 +00:00
2015-04-27 22:27:40 +00:00
// Ensure entity and menu router information are correctly rebuilt.
2019-01-26 14:52:11 +00:00
\Drupal :: entityTypeManager () -> clearCachedDefinitions ();
2015-04-27 22:27:40 +00:00
\Drupal :: service ( 'router.builder' ) -> setRebuildNeeded ();
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
}