Problem

When settings default Rabbit Hole behavior on a bundle (like the Vocabulary), and adding a Page Redirect, you only have access to global tokens. It would make sense that you would also have access to the tokens for the entity type here (in this case, the underlying term that will eventually be the context for this setting). That way you can take advantage of fields on the entity, like a Link field, so you can redirect to the value of that field.

Solution

It does seem that "taxonomy_term" is added to the $entity_type_for_tokens variable when creating the Browse Tokens link, but the Token tree builder is expecting just "term." This is how the core taxonomy module defines it's tokens.

We need another way to get the entity type in PageRedirect.php, one that takes into account this discrepancy. This is the current code:

$entity_type_for_tokens = $entity_is_bundle
        ? $entity->getEntityType()->getBundleOf()
        : $entity->getEntityTypeId();

Comments

jazzdrive3 created an issue. See original summary.

jazzdrive3’s picture

Issue summary: View changes
dylan donkersgoed’s picture

Status: Active » Needs review
StatusFileSize
new4.68 KB

I see the issue. I don't see any straightforward way of mapping entities to tokens, I guess because tokens don't necessarily map to an entity. It seems to work with nodes (and possibly other entities) but - while not quite a coincidence - that definitely doesn't seem guaranteed.

I'm not entirely happy with it, but I'm attaching a patch with a potential solution. It adds a getEntityTokenMap() method to the RabbitHoleEntityPluginInterface which provides an array of token IDs keyed by entity ID. Normally it will just provide the entity ID (and possibly bundle entity ID) mapped to itself but it can be overridden to provide different tokens if necessary. The patch does so with the Taxonomy entity plugin.

dylan donkersgoed’s picture

I've applied this patch to the dev branch. It'll be in the next beta release. jazzdrive3, I credited you as well since you found the cause of the issue and generally how to fix it.

dylan donkersgoed’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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