Commit 1ad4630a authored by alexpott's avatar alexpott

Issue #2111887 by Gábor Hojtsy, kfritsche, vasi1186, dclavain, YesCT, segi:...

Issue #2111887 by Gábor Hojtsy, kfritsche, vasi1186, dclavain, YesCT, segi: Regression: Only title (of base fields) on nodes is marked as translatable.
parent c40d1173
......@@ -289,7 +289,7 @@ public function entityFormSharedElements($element, $form_state, $form) {
// @todo Find a more reliable way to determine if a form element concerns a
// multilingual value.
if (!isset($ignored_types)) {
$ignored_types = array_flip(array('actions', 'value', 'hidden', 'vertical_tabs', 'token'));
$ignored_types = array_flip(array('actions', 'value', 'hidden', 'vertical_tabs', 'token', 'details'));
}
foreach (element_children($element) as $key) {
......
......@@ -69,7 +69,7 @@ protected function doTestBasicTranslation() {
$content_translation_path = $entity->getSystemPath('drupal:content-translation-overview');
$path = $langcode . '/' . $content_translation_path . '/add/' . $default_langcode . '/' . $langcode;
$this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity));
$this->drupalPostForm($path, $this->getEditValues($values, $langcode), $this->getFormSubmitActionForNewTranslation($entity, $langcode));
if ($this->testLanguageSelector) {
$this->assertNoFieldByXPath('//select[@id="edit-langcode"]', NULL, 'Language selector correctly disabled on translations.');
}
......@@ -86,7 +86,7 @@ protected function doTestBasicTranslation() {
// Add another translation and mark the other ones as outdated.
$values[$langcode] = $this->getNewEntityValues($langcode);
$edit = $this->getEditValues($values, $langcode) + array('content_translation[retranslate]' => TRUE);
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity));
$this->drupalPostForm($path, $edit, $this->getFormSubmitActionForNewTranslation($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
// Check that the entered values have been correctly stored.
......@@ -126,7 +126,7 @@ protected function doTestOutdatedStatus() {
// Mark translations as outdated.
$edit = array('content_translation[retranslate]' => TRUE);
$edit_path = $entity->getSystemPath('edit-form');
$this->drupalPostForm($langcode . '/' . $edit_path, $edit, $this->getFormSubmitAction($entity));
$this->drupalPostForm($langcode . '/' . $edit_path, $edit, $this->getFormSubmitAction($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
// Check that every translation has the correct "outdated" status.
......@@ -140,7 +140,7 @@ protected function doTestOutdatedStatus() {
else {
$this->assertFieldByXPath('//input[@name="content_translation[outdated]"]', TRUE, 'The translate flag is checked by default.');
$edit = array('content_translation[outdated]' => FALSE);
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity));
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $enabled_langcode));
$this->drupalGet($path);
$this->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is now shown.');
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
......@@ -160,7 +160,7 @@ protected function doTestPublishedStatus() {
foreach ($this->langcodes as $index => $langcode) {
if ($index > 0) {
$edit = array('content_translation[status]' => FALSE);
$this->drupalPostForm($langcode . '/' . $path, $edit, $this->getFormSubmitAction($entity));
$this->drupalPostForm($langcode . '/' . $path, $edit, $this->getFormSubmitAction($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$this->assertFalse($entity->translation[$langcode]['status'], 'The translation has been correctly unpublished.');
}
......@@ -191,7 +191,7 @@ protected function doTestAuthoringInfo() {
'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'),
);
$prefix = $index > 0 ? $langcode . '/' : '';
$this->drupalPostForm($prefix . $path, $edit, $this->getFormSubmitAction($entity));
$this->drupalPostForm($prefix . $path, $edit, $this->getFormSubmitAction($entity, $langcode));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
......@@ -207,7 +207,7 @@ protected function doTestAuthoringInfo() {
'content_translation[name]' => $this->randomName(12),
'content_translation[created]' => '19/11/1978',
);
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity));
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode));
$this->assertTrue($this->xpath('//div[contains(@class, "error")]//ul'), 'Invalid values generate a list of form errors.');
$this->assertEqual($entity->translation[$langcode]['uid'], $values[$langcode]['uid'], 'Translation author correctly kept.');
$this->assertEqual($entity->translation[$langcode]['created'], $values[$langcode]['created'], 'Translation date correctly kept.');
......@@ -252,17 +252,50 @@ protected function getEditValues($values, $langcode, $new = FALSE) {
return $edit;
}
/**
* Returns the form action value when submitting a new translation.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being tested.
* @param string $langcode
* Language code for the form.
*
* @return string
* Name of the button to hit.
*/
protected function getFormSubmitActionForNewTranslation(EntityInterface $entity, $langcode) {
$entity->addTranslation($langcode, $entity->toArray());
return $this->getFormSubmitAction($entity, $langcode);
}
/**
* Returns the form action value to be used to submit the entity form.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being tested.
* @param string $langcode
* Language code for the form.
*
* @return string
* Name of the button to hit.
*/
protected function getFormSubmitAction(EntityInterface $entity) {
return t('Save');
protected function getFormSubmitAction(EntityInterface $entity, $langcode) {
return t('Save') . $this->getFormSubmitSuffix($entity, $langcode);
}
/**
* Returns appropriate submit button suffix based on translatability.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being tested.
* @param string $langcode
* Language code for the form.
*
* @return string
* Submit button suffix based on translatability.
*/
protected function getFormSubmitSuffix(EntityInterface $entity, $langcode) {
return '';
}
/**
......
......@@ -380,38 +380,44 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setDisplayConfigurable('form', TRUE);
$fields['uid'] = FieldDefinition::create('entity_reference')
->setLabel(t('User ID'))
->setDescription(t('The user ID of the node author.'))
->setLabel(t('Author'))
->setDescription(t('The user that is the node author.'))
->setRevisionable(TRUE)
->setSettings(array(
'target_type' => 'user',
'default_value' => 0,
));
))
->setTranslatable(TRUE);
$fields['status'] = FieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the node is published.'))
->setRevisionable(TRUE);
->setRevisionable(TRUE)
->setTranslatable(TRUE);
$fields['created'] = FieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the node was created.'))
->setRevisionable(TRUE);
->setRevisionable(TRUE)
->setTranslatable(TRUE);
$fields['changed'] = FieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the node was last edited.'))
->setRevisionable(TRUE);
->setRevisionable(TRUE)
->setTranslatable(TRUE);
$fields['promote'] = FieldDefinition::create('boolean')
->setLabel(t('Promote'))
->setDescription(t('A boolean indicating whether the node should be displayed on the front page.'))
->setRevisionable(TRUE);
->setRevisionable(TRUE)
->setTranslatable(TRUE);
$fields['sticky'] = FieldDefinition::create('boolean')
->setLabel(t('Sticky'))
->setDescription(t('A boolean indicating whether the node should be displayed at the top of lists in which it appears.'))
->setRevisionable(TRUE);
->setRevisionable(TRUE)
->setTranslatable(TRUE);
$fields['revision_timestamp'] = FieldDefinition::create('timestamp')
->setLabel(t('Revision timestamp'))
......@@ -429,7 +435,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['log'] = FieldDefinition::create('string')
->setLabel(t('Log'))
->setDescription(t('The log entry explaining the changes in this revision.'))
->setRevisionable(TRUE);
->setRevisionable(TRUE)
->setTranslatable(TRUE);
return $fields;
}
......
......@@ -38,6 +38,28 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac
$form['content_translation']['name']['#access'] = FALSE;
$form['content_translation']['created']['#access'] = FALSE;
}
$form_controller = content_translation_form_controller($form_state);
$form_langcode = $form_controller->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 ? $this->t('(this translation)') : $this->t('(all translations)'));
}
}
}
}
}
/**
......
......@@ -90,20 +90,22 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) {
"{$this->fieldName}[0][value]" => $values[$this->fieldName][0]['value'],
'langcode' => $langcode,
);
$this->drupalPostForm('node/add/article', $edit,t('Save and publish'));
$this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this->drupalLogin($this->translator);
$node = $this->drupalGetNodeByTitle($values['title']);
return $node->id();
}
/**
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::getFormSubmitAction().
* {@inheritdoc}
*/
protected function getFormSubmitAction(EntityInterface $entity) {
if ($entity->isPublished()) {
return t('Save and unpublish');
protected function getFormSubmitAction(EntityInterface $entity, $langcode) {
if ($entity->getTranslation($langcode)->isPublished()) {
return t('Save and keep published') . $this->getFormSubmitSuffix($entity, $langcode);
}
else {
return t('Save and keep unpublished') . $this->getFormSubmitSuffix($entity, $langcode);
}
return t('Save and keep unpublished');
}
/**
......@@ -115,25 +117,24 @@ protected function doTestPublishedStatus() {
$languages = language_list();
$actions = array(
array(t('Save and publish'), t('Save and keep published')),
array(t('Save and unpublish'), t('Save and keep unpublished')),
t('Save and keep published'),
t('Save and unpublish'),
);
foreach ($actions as $index => $status_actions) {
foreach ($actions as $index => $action) {
// (Un)publish the node translations and check that the translation
// statuses are (un)published accordingly.
foreach ($this->langcodes as $langcode) {
if (!empty($status_actions)) {
$action = array_shift($status_actions);
}
$this->drupalPostForm($path, array(), $action, array('language' => $languages[$langcode]));
$this->drupalPostForm($path, array(), $action . $this->getFormSubmitSuffix($entity, $langcode), array('language' => $languages[$langcode]));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
foreach ($this->langcodes as $langcode) {
// The node is created as unpulished thus we switch to the published
// The node is created as unpublished thus we switch to the published
// status first.
$status = !$index;
$this->assertEqual($status, $entity->translation[$langcode]['status'], 'The translation has been correctly unpublished.');
$translation = $entity->getTranslation($langcode);
$this->assertEqual($status, $translation->isPublished(), 'The status of the translation has been correctly saved.');
}
}
}
......@@ -147,25 +148,34 @@ protected function doTestAuthoringInfo() {
$languages = language_list();
$values = array();
// Post different authoring information for each translation.
// Post different base field information for each translation.
foreach ($this->langcodes as $langcode) {
$user = $this->drupalCreateUser();
$values[$langcode] = array(
'uid' => $user->id(),
'created' => REQUEST_TIME - mt_rand(0, 1000),
'sticky' => (bool) mt_rand(0, 1),
'promote' => (bool) mt_rand(0, 1),
);
$edit = array(
'uid' => $user->getUsername(),
'created[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
'created[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
'sticky' => $values[$langcode]['sticky'],
'promote' => $values[$langcode]['promote'],
);
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity), array('language' => $languages[$langcode]));
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode), array('language' => $languages[$langcode]));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
foreach ($this->langcodes as $langcode) {
$this->assertEqual($entity->translation[$langcode]['uid'], $values[$langcode]['uid'], 'Translation author correctly stored.');
$this->assertEqual($entity->translation[$langcode]['created'], $values[$langcode]['created'], 'Translation date correctly stored.');
$translation = $entity->getTranslation($langcode);
$this->assertEqual($translation->getOwnerId(), $values[$langcode]['uid'], 'Author of translation correctly stored.');
$this->assertEqual($translation->getCreatedTime(), $values[$langcode]['created'], 'Date of Translation correctly stored.');
$this->assertEqual($translation->isSticky(), $values[$langcode]['sticky'], 'Sticky of Translation correctly stored.');
$this->assertEqual($translation->isPromoted(), $values[$langcode]['promote'], 'Promoted of Translation correctly stored.');
}
}
......@@ -237,7 +247,9 @@ function testTranslationRendering() {
foreach (array_diff($this->langcodes, array($default_langcode)) as $langcode) {
$values[$langcode] = $this->getNewEntityValues($langcode);
$translation = $node->addTranslation($langcode, $values[$langcode]);
// Publish and promote the translation to frontpage.
$translation->setPromoted(TRUE);
$translation->setPublished(TRUE);
}
$node->save();
......@@ -264,7 +276,7 @@ function testTranslationRendering() {
}
/**
* Tests that the given path dsiplays the correct translation values.
* Tests that the given path displays the correct translation values.
*
* @param string $path
* The path to be tested.
......@@ -279,4 +291,16 @@ protected function doTestTranslations($path, array $values) {
}
}
/**
* {@inheritdoc}
*/
protected function getFormSubmitSuffix(EntityInterface $entity, $langcode) {
if (!$entity->isNew() && $entity->isTranslatable()) {
$translations = $entity->getTranslationLanguages();
if ((count($translations) > 1 || !isset($translations[$langcode])) && ($field = $entity->getFieldDefinition('status'))) {
return ' ' . ($field->isTranslatable() ? t('(this translation)') : t('(all translations)'));
}
}
return '';
}
}
......@@ -79,6 +79,7 @@ function setUp() {
function testAliasTranslation() {
$english_node = $this->drupalCreateNode(array('type' => 'page', 'langcode' => 'en'));
$english_alias = $this->randomName();
$translatable = !$english_node->isNew() && $english_node->isTranslatable() && count($english_node->getTranslationLanguages()) > 1 && ($field = $english_node->getFieldDefinition('status')) && $field->isTranslatable();
// Edit the node to set language and path.
$edit = array();
......@@ -98,7 +99,7 @@ function testAliasTranslation() {
$edit['body[0][value]'] = $this->randomName();
$french_alias = $this->randomName();
$edit['path[alias]'] = $french_alias;
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalPostForm(NULL, $edit, t('Save') . ' ' . ($translatable ? t('(this translation)') : t('(all translations)')));
// Clear the path lookup cache.
$this->container->get('path.alias_manager')->cacheClear();
......
......@@ -129,9 +129,12 @@ function testSearchingMultilingualFieldValues() {
// This should find two results for the second and third node.
$plugin->setSearch('English OR Hungarian', array(), array());
$search_result = $plugin->execute();
$this->assertEqual($search_result[0]['title'], 'Third node this is the Hungarian title', 'The search finds the correct Hungarian title.');
$this->assertEqual($search_result[1]['title'], 'Second node this is the English title', 'The search finds the correct English title.');
$this->assertEqual(count($search_result), 2, 'Found two results.');
// Nodes are saved directly after each other and have the same created time
// so testing for the order is not possible.
$results = array($search_result[0]['title'], $search_result[1]['title']);
$this->assertTrue(in_array('Third node this is the Hungarian title', $results), 'The search finds the correct Hungarian title.');
$this->assertTrue(in_array('Second node this is the English title', $results), 'The search finds the correct English title.');
// Now filter for Hungarian results only.
$plugin->setSearch('English OR Hungarian', array('f' => array('language:hu')), array());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment