Issue #2449457 by Anushka-mp, sasanikolic, Berdir, plach: inconsistent checks in content_translation
parent
2bb91de3f3
commit
4bc5aa8380
|
@ -87,13 +87,15 @@ function _content_translation_form_language_content_settings_form_alter(array &$
|
||||||
$entity_type = $entity_manager->getDefinition($entity_type_id);
|
$entity_type = $entity_manager->getDefinition($entity_type_id);
|
||||||
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array();
|
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array();
|
||||||
|
|
||||||
$entity_type_translatable = $entity_type->isTranslatable();
|
$entity_type_translatable = $content_translation_manager->isSupported($entity_type_id);
|
||||||
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
|
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
|
||||||
// Here we do not want the widget to be altered and hold also the "Enable
|
// 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
|
// translation" checkbox, which would be redundant. Hence we add this key
|
||||||
// to be able to skip alterations.
|
// to be able to skip alterations. Alter the title and display the message
|
||||||
|
// about UI integration.
|
||||||
$form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE;
|
$form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE;
|
||||||
if (!$entity_type_translatable) {
|
if (!$entity_type_translatable) {
|
||||||
|
$form['settings'][$entity_type_id]['#title'] = t('@label (Translation is not supported).', array('@label' => $entity_type->getLabel()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,14 @@ function content_translation_language_types_info_alter(array &$language_types) {
|
||||||
* assumed. Every translation handler must implement
|
* assumed. Every translation handler must implement
|
||||||
* \Drupal\content_translation\ContentTranslationHandlerInterface.
|
* \Drupal\content_translation\ContentTranslationHandlerInterface.
|
||||||
*
|
*
|
||||||
|
* By default, entity types that do not have a canonical link template cannot be
|
||||||
|
* enabled for translation. This can be overridden by setting the
|
||||||
|
* 'content_translation_ui_skip' key to true. When that key is set, the Content
|
||||||
|
* Translation module will not provide any UI for translating the entity type,
|
||||||
|
* and the entity type should implement its own UI. This is useful for (e.g.)
|
||||||
|
* entity types that are embedded into others for editing (which would not need
|
||||||
|
* a canonical link, but could still support translation).
|
||||||
|
*
|
||||||
* To implement its business logic the content translation UI relies on various
|
* To implement its business logic the content translation UI relies on various
|
||||||
* metadata items describing the translation state. The default implementation
|
* metadata items describing the translation state. The default implementation
|
||||||
* is provided by \Drupal\content_translation\ContentTranslationMetadataWrapper,
|
* is provided by \Drupal\content_translation\ContentTranslationMetadataWrapper,
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ContentTranslationManager implements ContentTranslationManagerInterface {
|
||||||
*/
|
*/
|
||||||
public function isSupported($entity_type_id) {
|
public function isSupported($entity_type_id) {
|
||||||
$entity_type = $this->entityManager->getDefinition($entity_type_id);
|
$entity_type = $this->entityManager->getDefinition($entity_type_id);
|
||||||
return $entity_type->isTranslatable() && $entity_type->hasLinkTemplate('drupal:content-translation-overview');
|
return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains Drupal\content_translation\Tests\ContentTranslationUISkipTest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\content_translation\Tests;
|
||||||
|
|
||||||
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the content translation UI check skip.
|
||||||
|
*
|
||||||
|
* @group content_translation
|
||||||
|
*/
|
||||||
|
class ContentTranslationUISkipTest extends WebTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = array('content_translation_test', 'user', 'node');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the content_translation_ui_skip key functionality.
|
||||||
|
*/
|
||||||
|
function testUICheckSkip() {
|
||||||
|
$admin_user = $this->drupalCreateUser(array(
|
||||||
|
'translate any entity',
|
||||||
|
'administer content translation',
|
||||||
|
'administer languages'
|
||||||
|
));
|
||||||
|
$this->drupalLogin($admin_user);
|
||||||
|
// Visit the content translation.
|
||||||
|
$this->drupalGet('admin/config/regional/content-language');
|
||||||
|
|
||||||
|
// Check the message regarding UI integration.
|
||||||
|
$this->assertText('Test entity - Translatable skip UI check');
|
||||||
|
$this->assertText('Test entity - Translatable check UI (Translation is not supported)');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
name: 'Content translation tests'
|
||||||
|
type: module
|
||||||
|
description: 'Provides content translation tests.'
|
||||||
|
package: Testing
|
||||||
|
version: VERSION
|
||||||
|
core: 8.x
|
||||||
|
dependencies:
|
||||||
|
- content_translation
|
||||||
|
- language
|
||||||
|
- entity_test
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains Drupal\content_translation_test\Entity\EntityTestTranslatableNoUISkip.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\content_translation_test\Entity;
|
||||||
|
|
||||||
|
use Drupal\entity_test\Entity\EntityTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the test entity class.
|
||||||
|
*
|
||||||
|
* @ContentEntityType(
|
||||||
|
* id = "entity_test_translatable_no_skip",
|
||||||
|
* label = @Translation("Test entity - Translatable check UI"),
|
||||||
|
* base_table = "entity_test_mul",
|
||||||
|
* data_table = "entity_test_mul_property_data",
|
||||||
|
* entity_keys = {
|
||||||
|
* "id" = "id",
|
||||||
|
* "uuid" = "uuid",
|
||||||
|
* "bundle" = "type",
|
||||||
|
* "label" = "name",
|
||||||
|
* "langcode" = "langcode",
|
||||||
|
* },
|
||||||
|
* translatable = TRUE,
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class EntityTestTranslatableNoUISkip extends EntityTest {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains Drupal\content_translation_test\Entity\EntityTestTranslatableUISkip.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\content_translation_test\Entity;
|
||||||
|
|
||||||
|
use Drupal\entity_test\Entity\EntityTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the test entity class.
|
||||||
|
*
|
||||||
|
* @ContentEntityType(
|
||||||
|
* id = "entity_test_translatable_UI_skip",
|
||||||
|
* label = @Translation("Test entity - Translatable skip UI check"),
|
||||||
|
* base_table = "entity_test_mul",
|
||||||
|
* data_table = "entity_test_mul_property_data",
|
||||||
|
* entity_keys = {
|
||||||
|
* "id" = "id",
|
||||||
|
* "uuid" = "uuid",
|
||||||
|
* "bundle" = "type",
|
||||||
|
* "label" = "name",
|
||||||
|
* "langcode" = "langcode",
|
||||||
|
* },
|
||||||
|
* translatable = TRUE,
|
||||||
|
* content_translation_ui_skip = TRUE,
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class EntityTestTranslatableUISkip extends EntityTest {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue