5

I need to add a Machine Name type of field to Nodes of a certain Content Type. It's the same Machine Name field that Drupal is using when creating Content Types.

Example: If I enter "My Title" in the title field, the Machine Name field will be populated with "my_title" via javascript.

Why do I need it? I am referencing nodes to other nodes and want to generate an URI, based on a node referenced, i.e. example.com/node-referenced/node-content

1

There is a machine_name element type for the Form API, but it appears there is no machine name field type in core or in a contrib module. From there, I see three code-driven solutions:

  • It should be possible to crudely alter your node form to replace a text-field widget with a machine name element,
  • but the proper way would be to define a new Field API widget type based on the machine name Form API element type.
  • You can also not use the Field API for, directly add a machine name element in your node edit form through a form alter hook and handle storing it's value yourself.
  • Awesome, that will get me going in the right direction! – timofey.com Oct 17 '11 at 17:37
  • Do you know how to implement that in a module? I.e. how to make machine_name as a new field type via module. I can't seem to make it work. – timofey.com Oct 17 '11 at 22:54
  • Never mind. I found a module! – timofey.com Oct 18 '11 at 0:23
1

And here is the machine name field:

http://drupal.org/project/machine_name

Courtesy beejeebus, hunmonk, and C_Logemann working on Drupal.org's own project module.

1

Just found a module that does that: Safeword

Safeword adds a new Field type to Drupal 7: the "Name/Machine Name" combination. This field type can be useful for storing public-facint text and an internal "short" name, similar to the way that Content Type labels and machine names are used in the Drupal administration UI.

Safeword also uses the new 'Machine Name' FormAPI element in Drupal 7 to automatically suggest a machine name based on the text entered into the human-readable field.

Why bother using it? Using Token, Pathauto, and Auto NodeTitles, Safeword can be used as a replacement for Drupal's standard "Title" field, allowing content editors to create a visitor-friendly title with a customizable URL-safe "short" version that's used to build path aliases. The short URL-friendly machine name can also be used as a Views argument. Finally, it makes your Content Type administration page just a tiny bit cooler.

0

It sounds like you just need a new field on a certain content type, and want the field to be called machine name.

If that is the case do this:

  1. Goto: [yoursite.com]/admin/structure/types
  2. Click Manage fields for the content type you want to add this field
  3. Fill in the details in the add new field row, and hit save

That should add your field, but you may also want to edit the order it is displayed, and you can do that by dragging it up or down, and hitting save.

If you want to change how it is displayed then you need to look at the Manage Display tab, and you can re-order it and change the way it is displayed as well.

  • No, I need to have a Machine Name field. The field that is automatically populated via javascript from the title. For example, if I enter "Node Title", the Machine Name field will automatically be populated with "node_title". Just like you get when you create a new Content Type. – timofey.com Oct 15 '11 at 6:44
  • Can you not use pathauto to generate the path, and use that? – Shane Grant Oct 15 '11 at 7:58
  • Pathauto will use the machine-named field, instead of the Title, because Title may get altered. – timofey.com Oct 17 '11 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.