Comments

hswong3i created an issue. See original summary.

hswong3i’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB
darrenwh’s picture

Status: Needs review » Needs work
  1. +++ b/token.tokens.inc
    @@ -558,6 +569,9 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
    +      $replacements += \Drupal::token()->generate('term', $parent_tokens, array('term' => $source_term), $options, $bubbleable_metadata);
    

    This line is long and could benefit from having the array's values on separate lines.

  2. +++ b/token.tokens.inc
    @@ -590,6 +604,11 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
    +      $replacements += \Drupal::token()->generate('vocabulary', $parent_tokens, array('vocabulary' => $source_vocabulary), $options, $bubbleable_metadata);
    

    Similar comment as above.

chipway’s picture

Status: Needs work » Needs review
StatusFileSize
new2.75 KB
new1.47 KB

Thanks hswong3i and darrenwh. Here is a new patch.

darrenwh’s picture

+++ b/token.tokens.inc
@@ -169,6 +170,11 @@ function token_token_info() {
+      'description' => t("The source term for this current term's translation set."),

Very trivial but the speech marks in the translation blocks are not consistent (" or ')?

chipway’s picture

Thanks darrenwh,
Because we have term's with a ' inside the string.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/token.tokens.inc
    @@ -169,6 +170,11 @@ function token_token_info() {
       if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
    +    $info['tokens']['term']['source'] = array(
    +      'name' => t('Translation source term'),
    +      'description' => t("The source term for this current term's translation set."),
    +      'type' => 'term',
    +    );
         $info['tokens']['term']['edit-url'] = array(
           'name' => t('Edit URL'),
    

    Drupal 8 doesn't have translation sets, it has entity translation.

  2. +++ b/token.tokens.inc
    @@ -590,6 +606,13 @@ function token_tokens($type, array $tokens, array $data = array(), array $option
    +
    +    // Chained token relationships.
    +    if (($parent_tokens = \Drupal::token()->findWithPrefix($tokens, 'source')) && $source_vocabulary = \Drupal::service('entity.repository')->getTranslationFromContext($vocabulary, LanguageInterface::LANGCODE_DEFAULT)) {
    +      $replacements += \Drupal::token()->generate('vocabulary', $parent_tokens, array(
    +        'vocabulary' => $source_vocabulary),
    +        $options, $bubbleable_metadata);
    

    And config entities don't have entity translations, not like that. Shouldn't be exposed for vocabularies.

    This feels like a duplicate of another issue.

gaurav.kapoor’s picture

Status: Needs work » Needs review
StatusFileSize
new1017 bytes
new3.1 KB

Minor fixes.

j-lee’s picture

/**
  * Implements hook_token_info_alter().
@@ -127,7 +128,7 @@ function token_token_info() {
   // Node tokens.
   $info['tokens']['node']['source'] = array(
     'name' => t('Translation source node'),
-    'description' => t("The source node for this current node's translation set."),
+    'description' => t("The source node for this current node's entity translation."),
     'type' => 'node',
   );

This is out of scope.

+1 for removing the vocabulary part.

j-lee’s picture

Status: Needs review » Needs work

and the new status ...

hswong3i’s picture

Status: Needs work » Needs review
StatusFileSize
new2.69 KB
new2.31 KB

Retouch patch from #8, remove out of scope patch for node-source description, lint with Drupal Coder, via latest 8.x-1.x-dev.

hswong3i’s picture

StatusFileSize
new2.67 KB

Update #11 via latest 8.x-1.x-dev

nironan’s picture

Adds support for term:source tokens to 7.x.

berdir’s picture

Component: Token Actions » Code
Status: Needs review » Needs work

As pointed out before, this doesn't work and doesn't make sense for vocabulary, that API only does something for content entities. Lets just add this for terms here and if someone needs vocabulary then a separate issue can be opened that loads them as override-free or so.

berdir’s picture

Also tests would help to get this committed.

timcosgrove’s picture

I don't have time to write tests right now, but we want to use this patch, so I rewrote it to remove the vocabulary code and leave terms.

gg4’s picture

Status: Needs work » Needs review

Noting it still needs tests, but flipping to needs review to make sure existing tests are still green.

gg4’s picture

Issue tags: +Needs tests
ngkoutsaik’s picture

Status: Needs review » Needs work
herved’s picture

Status: Needs work » Needs review
StatusFileSize
new2.34 KB
new638 bytes

Thank you for this, we have a need for this in one of our projects.
Adding minimal test.

heddn’s picture

Title: Add [term:source] and [term:vocabulary:source] for translation » Add [term:source] for source translation
Issue tags: -Needs tests

Re-titleing.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

This has tests, although limited, I'm not sure what more is needed there. And it has manual testing. LGTM.

hswong3i’s picture

Patch re-roll via 8.x-1.x-dev

markdc’s picture

I applied #23 to an existing site, cleared cache, added :source to my pathauto term pattern and got the following error on saving a term:

The website encountered an unexpected error. Please try again later.
Error: Class 'LanguageInterface' not found in token_tokens() (line 576 of modules/contrib/token/token.tokens.inc).
token_tokens('term', Array, Array, Array, Object)
call_user_func_array('token_tokens', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 304)
Drupal\Core\Utility\Token->generate('term', Array, Array, Array, Object) (Line: 196)
Drupal\Core\Utility\Token->replace('shop/[term:source:parents:join-path]/[term:source:name]', Array, Array, Object) (Line: 228)
Drupal\pathauto\PathautoGenerator->createEntityAlias(Object, 'update') (Line: 380)
Drupal\pathauto\PathautoGenerator->updateEntityAlias(Object, 'update') (Line: 93)
pathauto_entity_update(Object)
call_user_func_array('pathauto_entity_update', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 206)
Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 843)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 535)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 728)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 460)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 837)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 395)
Drupal\Core\Entity\EntityBase->save() (Line: 156)
Drupal\taxonomy\TermForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('taxonomy_term_product_categories_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 115)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
gaurav.kapoor’s picture

Assigned: Unassigned » gaurav.kapoor
Status: Reviewed & tested by the community » Needs work

The patch will require some changes such as adding the use statement for Language Interface.

gaurav.kapoor’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB

I noticed, that 8.x-1.x branch of Token module already has the required use statement, but it is missing in 8.x-1.9, so by pushing the patch provided in #23, we can mark this issue as resolved. Adding a patch compatible with 8.x-1.9 in case if someone needs this feature urgently.

james.williams’s picture

This might be scope creep, but could it be implemented dynamically for any content entity type? The \Drupal\Core\Entity\ContentEntityInterface implements \Drupal\Core\TypedData\TranslatableInterface, which contains the getUntranslated() method, which is used for nodes, so I would have thought any content entity could have been done the same way?

gaurav.kapoor’s picture

Assigned: gaurav.kapoor » Unassigned
abu-zakham’s picture

StatusFileSize
new2.16 KB

re-roll patch #26

Status: Needs review » Needs work

The last submitted patch, 29: 2816693-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

qusai taha’s picture

Status: Needs work » Needs review
StatusFileSize
new2.05 KB

Re-Roll patch #29

dabblela’s picture

StatusFileSize
new2.1 KB

I had some issues with URL generation using term:source:url:path. I think this is because the patches here still pass the original langcode when generating the token. Attached an updated version of #31 that changes this behavior.

rinku jacob 13’s picture

StatusFileSize
new183.27 KB

I have successfully applied patch #32 drupal version 9.5.x. After applying the patch i can see [term:source] token for Taxonomy terms. Adding Screenshots for the reference

bboty’s picture

I confirm I have also successfully applied patch #32 Drupal version 9.5.x. After applying the patch i can see [term:source], directly used with [term:source:name] token for Taxonomy terms when generating URL aliases.

bboty’s picture

Status: Needs review » Reviewed & tested by the community

  • Berdir committed 37b3fee2 on 8.x-1.x authored by dabblela
    Issue #2816693 by hswong3i, gaurav.kapoor, chipway, timcosgrove, herved...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Re #27: generic entity tokens are tricky, token types have no inheritance, so it needs to altered dynamically, we need to figure out if it's our token or not and then also have generic test coverage.

I'm fine with the test coverage here, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.