Commit debc9506 authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #2980963 by jrockowitz: [webform_submission:node:title] don't take the translated title

parent adbf4089
......@@ -78,6 +78,7 @@ echo 'true' > modules/webform_image_select/tests/modules/webform_image_select_te
echo 'true' > modules/webform_node/webform_node.features.yml
echo 'true' > modules/webform_node/tests/modules/webform_node_test_multiple/webform_node_test_multiple.features.yml
echo 'true' > modules/webform_node/tests/modules/webform_node_test_translation/webform_node_test_translation.features.yml
echo 'true' > modules/webform_scheduled_email/tests/modules/webform_scheduled_email_test/webform_scheduled_email_test.features.yml
......@@ -126,6 +127,7 @@ drush en -y webform\
webform_test_translation\
webform_image_select_test\
webform_node_test_multiple\
webform_node_test_translation\
webform_scheduled_email_test;
# Show the difference between the active config and the default config.
......@@ -156,6 +158,7 @@ drush features-export -y webform_test_translation
drush features-export -y webform_test_paragraphs
drush features-export -y webform_image_select_test
drush features-export -y webform_node_test_multiple
drush features-export -y webform_node_test_translation
drush features-export -y webform_scheduled_email_test
# Revert all feature update to *.info.yml files.
......@@ -185,6 +188,7 @@ drush webform:tidy -y --dependencies webform_test_translation
drush webform:tidy -y --dependencies webform_test_paragraphs
drush webform:tidy -y --dependencies webform_image_select_test
drush webform:tidy -y --dependencies webform_node_test_multiple
drush webform:tidy -y --dependencies webform_node_test_translation
drush webform:tidy -y --dependencies webform_scheduled_email_test
# Re-import all webform configuration into your site.
......@@ -211,5 +215,6 @@ drush features-import -y webform_test_translation
drush features-import -y webform_test_paragraphs
drush features-import -y webform_image_select_test
drush features-import -y webform_node_test_multiple
drush features-import -y webform_node_test_translation
drush features-import -y webform_scheduled_email_test
```
......@@ -48,12 +48,16 @@ abstract class WebformNodeTestBase extends WebformTestBase {
*
* @param string $webform_id
* A webform id.
* @param array $settings
* (optional) An associative array of settings for the node, as used in
* entity_create().
*
* @return \Drupal\node\NodeInterface
* A webform node.
*/
protected function createWebformNode($webform_id) {
$node = $this->drupalCreateNode(['type' => 'webform']);
protected function createWebformNode($webform_id, $settings = []) {
$settings += ['type' => 'webform'];
$node = $this->drupalCreateNode($settings);
$node->webform->target_id = $webform_id;
$node->webform->status = WebformInterface::STATUS_OPEN;
$node->webform->open = '';
......
......@@ -43,7 +43,7 @@ function webform_node_tokens($type, $tokens, array $data, array $options, Bubble
if ($type == 'webform_submission' && !empty($data['webform_submission'])) {
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $data['webform_submission'];
$source_entity = $webform_submission->getSourceEntity();
$source_entity = $webform_submission->getSourceEntity(TRUE);
if (!$source_entity || (!$source_entity instanceof NodeInterface)) {
return $replacements;
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\webform\Entity;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Serialization\Yaml;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -420,11 +421,20 @@ class WebformSubmission extends ContentEntityBase implements WebformSubmissionIn
/**
* {@inheritdoc}
*/
public function getSourceEntity() {
public function getSourceEntity($translate = FALSE) {
if ($this->entity_type->value && $this->entity_id->value) {
$entity_type = $this->entity_type->value;
$entity_id = $this->entity_id->value;
return $this->entityTypeManager()->getStorage($entity_type)->load($entity_id);
$source_entity = $this->entityTypeManager()->getStorage($entity_type)->load($entity_id);
// If translated is set, get the translated source entity.
if ($translate && $source_entity instanceof ContentEntityInterface ) {
$langcode = $this->language()->getId();
if ($source_entity->hasTranslation($langcode)) {
$source_entity = $source_entity->getTranslation($langcode);
}
}
return $source_entity;
}
else {
return NULL;
......
......@@ -334,10 +334,12 @@ interface WebformSubmissionInterface extends ContentEntityInterface, EntityOwner
/**
* Gets the webform submission's source entity.
*
* @param boolean
* (optional) If TRUE the source entity will be translated.
* @return \Drupal\Core\Entity\EntityInterface|null
* The entity that this webform submission was created from.
*/
public function getSourceEntity();
public function getSourceEntity($translate = FALSE);
/**
* Gets the webform submission's source URL.
......
......@@ -378,7 +378,7 @@ function webform_tokens($type, $tokens, array $data, array $options, BubbleableM
$webform = $webform_submission->getWebform();
$bubbleable_metadata->addCacheableDependency($webform);
$source_entity = $webform_submission->getSourceEntity();
$source_entity = $webform_submission->getSourceEntity(TRUE);
if ($source_entity) {
$bubbleable_metadata->addCacheableDependency($source_entity);
}
......@@ -564,10 +564,10 @@ function webform_tokens($type, $tokens, array $data, array $options, BubbleableM
if (($webform_tokens = $token_service->findWithPrefix($tokens, 'webform')) && ($webform = $webform_submission->getWebform())) {
$replacements += $token_service->generate('webform', $webform_tokens, ['webform' => $webform], $options, $bubbleable_metadata);
}
if (($source_entity_tokens = $token_service->findWithPrefix($tokens, 'source-entity')) && ($source_entity = $webform_submission->getSourceEntity())) {
if (($source_entity_tokens = $token_service->findWithPrefix($tokens, 'source-entity')) && ($source_entity = $webform_submission->getSourceEntity(TRUE))) {
$replacements += $token_service->generate($source_entity->getEntityTypeId(), $source_entity_tokens, [$source_entity->getEntityTypeId() => $source_entity], $options, $bubbleable_metadata);
}
if (($submitted_to_tokens = $token_service->findWithPrefix($tokens, 'submitted-to')) && ($submitted_to = $webform_submission->getSourceEntity() ?: $webform_submission->getWebform())) {
if (($submitted_to_tokens = $token_service->findWithPrefix($tokens, 'submitted-to')) && ($submitted_to = $webform_submission->getSourceEntity(TRUE) ?: $webform_submission->getWebform())) {
$replacements += $token_service->generate($submitted_to->getEntityTypeId(), $submitted_to_tokens, [$submitted_to->getEntityTypeId() => $submitted_to], $options, $bubbleable_metadata);
}
......
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