Hallo,

I am currently in the process of converting a Drupal 8 site to Backdrop. I still have to solve a major problem. When a user successfully logs in, a menu item must be displayed with which he can edit a page assigned to him. The assignment takes place via the entity reference field field_zugehoeriger_chor in the account settings :

 

The entity reference refers to a corresponding entry with its own node type:

In the previous Drupal version I created the menu link in the following form:

Unfortunately, this no longer works under Backdrop. I get an error message that the path is invalid:

Apparently you cannot use tokens for path input in Backdrop. Since it is essential for the simple and intuitive use of the site that users can update their data immediately and directly, I would be grateful for any advice on how such a link can be realised in Backdrop. Thank you very much.

Accepted answer

Glad to hear you have a workaround, even if the effort is high!

In the meantime I have posted a Port request for Menu Token. Hard to say if anyone will work on it; I'll keep my fingers crossed.

Most helpful answers

Yes, that would have been my next workaround attempt. However, I did further tests with the appropriate formatting of the link and came up with a workable solution. If you don't use the token to edit the corresponding entry, but only the token with the corresponding NID and then assemble the link yourself with it, then it works:

 

Thanks again for the suggestion. I now only have to customise the whole thing using CSS so that no difference to the other menu items is recognisable, but that should be doable. It's just a pity that the total effort for this simple requirement is quite high.

Comments

Olafski's picture

Hi mue368, I'm not sure about the technical limitation (no tokens for path input). As a workaround you could put the link in a custom block and place the block via one of the layouts of your site. I guess, to make tokens work in a text block, you need the Token Filter module.

Many thanks for the idea. After various tests, I unfortunately have to realise that this does not work. The necessary tokens are converted correctly as normal text, but not when used in a link. Here is the screenshot of the copied token:

 The source code of the inserted link then looks like this:

The token is then not cancelled when the mouse is clicked but remains with exactly this text:

By the way, I use CKEditor 5 as my editor. It seems to me that either CKEditor 5 or the Token Filter module is faulty. Is there a way to adapt the source code so that the token is resolved correctly?

PS: The token notation with curly brackets does not work either. These are also converted incorrectly in the source text after saving. Here is a simple test with a standard token. Before saving:

After saving:

Olafski's picture

Sorry to hear that my idea doesn't work. Tried it by myself and had the same results (even without CKEditor 5 by the way): Tokens work but not in a link. I'm not sure if that's an issue with Backdrop core or with the module. I'd recommend to file a report in the module's issue queue and ask if tokens in links are supposed to work.

Apart of that, I'm pretty sure that your goal can be achieved somehow. Here is another quick idea which isn't exactly what you intended but nearly. There might be better solutions, but it's a start.

  • Create a view of user accounts, using a Block display.
  • Add the contextual filter "User account: Uid", providing the default value "User account ID from logged in person".
  • Switch the view to use fields.
  • Add your Entity Reference field, and enable the option "Link label to referenced entity".
  • Save the view, and add the block to your layout.

Good idea, I use this often.
With Views, you can display various data on a page as <div data-something=”something”> or plain text, in hidden blocks, and then manipulate this data using Javascript. You can make an additional menu item, or whatever your imagination allows.

Yes, that would have been my next workaround attempt. However, I did further tests with the appropriate formatting of the link and came up with a workable solution. If you don't use the token to edit the corresponding entry, but only the token with the corresponding NID and then assemble the link yourself with it, then it works:

 

Thanks again for the suggestion. I now only have to customise the whole thing using CSS so that no difference to the other menu items is recognisable, but that should be doable. It's just a pity that the total effort for this simple requirement is quite high.

Olafski's picture

Glad to hear you have a workaround, even if the effort is high!

In the meantime I have posted a Port request for Menu Token. Hard to say if anyone will work on it; I'll keep my fingers crossed.

My guess is that you were using the module menu_token in Drupal? Otherwise Drupal AFAIK doesn't take tokens in menu links. I see that module is not ported to Backdrop - but you can see if someone (or yourself) can port it.

Hallo argiepiano, 

Yes, that is correct. I use the menu_token module in Drupal. It would of course be great if someone could be found to port this module. I think there are many interested parties. Unfortunately my PHP knowledge is not sufficient to do the porting myself. However, it is a pity that the good suggestion for the workaround does not work either and that no tokens can be used in links in user-defined text blocks.
 

 

Hello mue368,

The following is a little thing I put together because I am also thinking of converting modules to Backdrop, and I needed a process to follow:

Before anyone can convert a module to Backdrop, its canonical version needs to be confirmed.  Please confirm the version you are using in your production site?

As a reference you can use the following resource as an aid:

https://www.drupal.org/project/menu_token/releases

You can also try the following command to expose the version number of your menu_token installation (if you are using linux):

# find / -type f -name 'menu_token.info.yml' 2>&1 -exec cat {} + | grep "version"

In my case, the output was:

version: '8.x-1.0-alpha3'

What version are you using?

BCMS is a fork of Drupal 7, so I am assuming that it will use the Drupal 7 version of things as its feedstock.

The most recent Drupal 7 version of menu_token is:

menu_token 7.x-1.0-beta7

Which has the following dependencies that would need to be checked:

  • dependencies[] = menu
  • dependencies[] = entity
  • dependencies[] = token
  • dependencies[] = ctools
  • dependencies[] = uuid
     

Checks:

Menu = Backdrop Core (/site/core/modules/menu)

Entity = Backdrop Core (/site/core/modules/entity)

Token = Backdrop Core (/site/core/modules/)

Ctools = Backdrop Core (https://backdropcms.org/project/ctools)

UUID = Backdrop Contrib? (https://github.com/backdrop-contrib/uuid)

The above UUID project is a bit of a standout.  I say this because there is no listing for it at https://backdropcms.org/project/uuid, while there was a listing for ctools, even though that module does not exist as a separate entity from BCMS.

So, it looks like the dependencies are (I think) covered, which is good news. 

The next thing to determine is the scale of the conversion process, so anyone undertaking it can understand the impact of the attempt up front:

Using:

menu_token 7.x-1.0-beta7

As a reference, we find 84K of information:

~/Drupal/Modules/7.x/menu_token# du -h
16K     ./plugins
84K     

Arranged like this:

menu_token
├── LICENSE.txt
├── menu_token.admin.inc
├── menu_token.css
├── menu_token.info
├── menu_token.install
├── menu_token.module
├── menu_token.test
└── plugins
   ├── menu_token_entity_context.inc
   ├── menu_token_entity_random.inc
   └── menu_token_entity_user_defined.inc

There are 14 artifacts involved, two of which are directories:

~/Drupal/Modules/7.x# tree menu_token | wc -l
14

Here are some statistics regarding these files:

LICENSE.txt

  • No need to convert

menu_token.admin.inc

  • 28 lines of code

menu_token.css

  • 3 lines of code

menu_token.info

  • 16 lines of code

menu_token.install

  • 221 lines of code

menu_token.module

  • 601 lines of code

menu_token.test

  • 54 lines of code

plugins/menu_token_entity_context.inc

  • 55 lines of code

plugins/menu_token_entity_random.inc

  • 38 lines of code

plugins/menu_token_entity_user_defined.inc

  • 47 lines of code

The above parameters should help (somewhat) in terms of appreciating the  scale and complexity of the conversion process, which should result in more accurate time estimates concerning the work involved.

 

Hello Graham,

Thank you for your enquiry. 

I use version 9.1.0-alpha1 in the production system. Token is the only dependency specified for this version.