By linwiz on
How can I add a field to a content type that processes pattern replacement? (e.g. pattern replacement in module pathauto: admin/config/search/path/patterns) I'm looking to use this in my module, but I don't know where a field like this would come from.
Comments
Not enough info.
Not enough info.
Contact me to contract me for D7 -> D10/11 migrations.
I would like to take a field
I would like to take a field from admin/config/search/path/patterns and put it in node edit. I'm not sure I can explain it differently
"put it in" isn't exactly
"put it in" isn't exactly descriptive. Do you want to run some text through the pattern? Change the URL of the node path? Display the pattern as text to the user? Something else?
Contact me to contract me for D7 -> D10/11 migrations.
I want to run the text
I want to run the text through the pattern, so i can access the results in my module
I don't think you can do
I don't think you can do this. The reason is that path aliases are generated using tokens, they are not generated by using the unaliased path. By this I mean it doesn't work that the unaliased path is passed through a function with the aliased path being returned from that function. It works that modules can generate tokens, and when a path alias is generated, the tokens for that content type are used to generate the alias.
If you give a concrete example of the kind of text you want to start with, and how you would like it to look after it has been processed, maybe I or someone else can come up with some alternate solutions. What exactly are you trying to do? What is the end goal?
Contact me to contract me for D7 -> D10/11 migrations.
I need the user to be able to
I would like to thank you for the time you've spent assisting me, it is very much appreciated.
I need the user to be able to choose a filename. I would like the user to have access to strings like [current-date:long] which could be like Tuesday, April 30, 2013 - 17:14, etc. This is not related to node paths, but pathauto demonstrates the best functionality of what I would like to accomplish. You can see right now in my module that the file name is hard coded at $sTMPFileName, which only will suffice my needs, and not the needs of other websites.
I am starting to think that if I want to pursue this, I may have to hardcode every string replacement I would like to be available. I just do not have the experience to write the code myself to modify the node form UI itself. I am limited to adding and removing fields from the content type editor.
If i have to settle, the very least I would need the user to be able to type an exact filename, even if they have to type example-09-12-09 rather than example-[current-date:etc]
Ok, this is making more
Ok, this is making more sense. You need to create some custom tokens. You should look at the token hooks: http://api.drupal.org/api/drupal/7/search/hook_token
Google around for some Drupal Token tutorials as well, and you should be able to find some more information on this. Good luck!
Contact me to contract me for D7 -> D10/11 migrations.
tokens. I did not know the
tokens. I did not know the name for them! thanks. So in reality if the token module already has the tokens I want to use, I just make a simple call like token_replace($node->field_........)in my module. I shouldn't need any hooks, right?
Maybe? I haven't used them
Maybe? I haven't used them much except for creating new tokens for path aliases for my custom entity types, so I'm not the best person to answer that question. Hopefully someone else can give you a better answer.
Contact me to contract me for D7 -> D10/11 migrations.
as it turns out, I do not
as it turns out, I do not need the hooks. token_replace($node->field_...) does exactly what I need it to do. thank you.