Now that entities can have fields, Automatic Nodetitles should become Automatic Entity Titles.

For example you can use a field called "title" on every entity. Then use Automatic Entity Titles to generate the entity titles for nodes (node titles), taxonomy terms (term titles/name display on taxonomy page), users (Username/ Real Name), entities, etc.

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TimelessDomain’s picture

If you could provide a patch for Taxonomy Terms -> I would very much appreciate it.

Jerome F’s picture

subscribe

artatac’s picture

sub

AdamGerthel’s picture

It's not just taxonomies and users. A lot of modules (like Commerce) use entities. Would be very useful.

iko’s picture

Indeed.

Subscribing

adpo’s picture

subscribe

vasi1186’s picture

FileSize
17.92 KB

Here is a first version of a patch that tries to make this module work with any type of entities. The patch works with the 7.x-1.x dev version.

Please be aware that there are many changes, and it would probably make sense to have a new 7.x-2.x version of the module, or event better a new module with a different title, something like "Automatic Entity Titles" as it has been suggested. The patch still needs a lot of testing, I tried it on taxonomy terms and it worked. Also, some more code review and probably some changes are still needed.

A few issues that should be taken into consideration:
- I couldn't find a proper way yet to alter all the bundle edit forms, so at the moment there is a new menu tab on the bundle edit page that contains the auto title settings. As a side effect, right now you have actually 2 more tabs when you go to the node type edit page, because the nodes and the comments share the entity admin path...
- although there is a hook_update_N() that will migrate the existing settings to the new structure, I highly recommend to make a database backup first.

I will probably review more the code in the next days, and probably make some changes, but I think that the main skeleton will not be changed. Any feedback and help with testing will be highly appreciated.

vasi1186’s picture

FileSize
18.01 KB

A better integration with the title module. The previous patch had a bug when checking if the title module replaces the entity legacy field.

shaisamuel’s picture

Is this patch is going to be integrated in the module? Can you release a new update which include it?

mausolos’s picture

FWIW, I needed an autotitle solution for Commerce, and ended up making tweaks to commerce_autosku to make a commerce_autotitle module that seems to work pretty well. Maybe this could be looked at as a starting point for an auto entity title project? Here's where I'm keeping track of my notes: http://drupal.org/node/1416458#comment-5534548

bforchhammer’s picture

Hm, I'm wondering whether this could actually help me with #1420296: Automatic node title integration... seeing that patch #8 contains code for "better integration with the title module".

I'm definitely going to need the autonodetitle + title module integration soon, so if there are any efforts towards creating a new module for this I'd be happy to help out... mausolos, vasi1186?

mausolos’s picture

@bforchhammer: I'll happily pass you the converted module I made, later. Though really most of what I did was to take the commerce_autosku module and make a bunch of find/replace of sku -> title. If you can't wait til later, you could just take a quick look at the insides of autosku to get an idea of whether it's too commerce-y or whether it might stand a decent chance of making a good abstract module. Message me your email and I'll zip it up and send it out tonight.

bforchhammer’s picture

Thanks for the offer, mausolos. I have decided to try the patch #8 instead, as I'm already using this module, and autosku seems to be "something different".

That patch seems to be working fairly well. Thanks, vasi1186!

I've made a bunch of adjustments to allow multilingual titles and improve integration with entity_translation module in general. Attached is the updated patch and interdiff.

I've also put the code into a sandbox to ease further development efforts... Let me know if you'd like to co-maintain the sandbox!

itamair’s picture

Thanks to both bforchhammer & vasi1186 for this patch. It seems great work ... but ...
I was unable to correctly apply the patch with git, on the last dev release (September 9, 2011): anyway I did it by myself, line by line ...

There are some errors thrown when the $bundle_info['admin']['bundle argument'] is not set and the $bundle_arg value is defined as $bundle_name (#49 of auto_nodetitle.module file): in this case the $bundle_arg is not a number, and works bad as a parameter to the auto_nodetitle_settings_form function in auto_nodetitle.admin.inc file (it seems).

It seems to happen with comment entity and for the most of Drupal Commerce entities (commerce_product, commerce_order, commerce_file, commerce_license).
I tried but couldn't find the best workaround.

Besides that, for a commerce_product content type, its tokens aren't defined and exposed in the autonode title form ... (->useless for this entity).

It's a great step beyond for this module to make it compliant with entities, but unluckely so far didn't feel so confident with it with mine entities

Great work so far, anyway. Really hope all this will become Automatic Entity Titles mature & stable soon ...

bforchhammer’s picture

I was unable to correctly apply the patch with git, on the last dev release (September 9, 2011)

It applies fine for me, with both the git apply and patch -p1 command. If it's any easier you could also git clone the sandbox instead...

There are some errors thrown [...]

Can you elaborate on that? What's the actual problem, and what's the simplest way to reproduce it? (I have done most of my tests just with "node" entities so far, and that seems to be working well...)

Thanks for testing this, itamair!

Albert Volkman’s picture

@itamair you stated that you attempted to apply it against the dev release. You should apply it against the latest git pull (HEAD)

itamair’s picture

FileSize
10.7 KB

Ok, I made some code change and now for me it works (great!) also with commerce entities, and what ever ...
I made some change in the 'auto_nodetitle_settings_form' function (#325 line of auto_nodetitle.admin.inc file) to handle the case the $bundle_arg is not the arg key but the bundle name itself ...
and also a minor one in the '_auto_nodetitle_get_settings' (#325 line of auto_nodetitle.module file) as I had some error with the $entity_info['entity keys']['label'] (notset ...)

Sorry, I am still unable to pack patches ...
I attach my working version of the module in .zip format.

There was also a syntax error for Autotile instead of "Autotitle" (#60 of auto_nodetitle.module file).

Would be great if instead of Tab Menu ('MENU_LOCAL_TASK') the module settings might be shown in the classic Autonode title (for each pane), as in case of field and comment appears two menu tabs with the same title (Auto Title).

Thanks for your great work. Hope all this will help ...

itamair’s picture

... still I just cannot use tokens related to the product type, for a commerce product type ... (as they are not exposed, probably due to Drupal Commerce itself, don't know) but I can easily workaround that using the php pattern and the $entity variable here available (that works nice) ;-)

itamair’s picture

FileSize
11.75 KB

ah ... little update to the previous attachment in which there was a check dpm() code line left.
all previously said remains ...

bforchhammer’s picture

Here are itamair's changes in form of a patch...

bforchhammer’s picture

Status: Active » Needs work
+++ b/auto_nodetitle.admin.inc
@@ -10,7 +10,8 @@
+  $bundle_name = isset($bundle_arg->{$entity['bundle keys']['bundle']}) ? $bundle_arg->{$entity['bundle keys']['bundle']} : $bundle_arg;

Not sure about this line; is $bundle_arg sometimes an object and sometimes a string? Sounds like there might be something off somewhere else...

itamair’s picture

Status: Needs work » Active

yes that's the matter ...
sorry bforchhammer, but in my last attachment still there were two dpm() calls that helped me to check exactly that output from the $bundle_arg

          if (isset($bundle_info['admin']['bundle argument'])) {
            $bundle_arg = $bundle_info['admin']['bundle argument'];
            dpm($bundle_arg);
          }
          else {
            $bundle_arg = $bundle_name;
            dpm($bundle_arg);
          }

I see you properly deleted all of them .. great!

itamair’s picture

$bundle_arg happens sometimes to be a number (not an object) and sometimes a string.
It outputs as a string in case of user and commerce entities ... as in this cases it seems (isset($bundle_info['admin']['bundle argument']) is FALSE

fago’s picture

Status: Active » Needs work

Now that entities can have fields, Automatic Nodetitles should become Automatic Entity Titles.

Agreed, and a I very much appreciate the effort. However, I think this should become a new, separate project. "Automatic Nodetitles" should stay for nodes only, everything else would be just confusing.

@ Automatic Entity Titles

I guess it should be call "Automatic Entity Labels" instead, as entities generally don't have titles. Also, it would be nice if it could cover profile2 too, which is already prepared for something like that (and offers this functionality currently via Rules only).

Generally, I'm not sure how the module can properly work as there is no general way for altering the form, nor a determined location for the label in the form (e.g. profile2 doesn't have it at all). Thus, imo the module has to provide ways for entity types to provide the necessary information.

Here a short review:

+++ b/auto_nodetitle.module
@@ -23,72 +23,200 @@ function auto_nodetitle_permission() {
+ * Because now we work with more entities, there is a problem with using tokens.
+ * We have to know for each entity which are the tokens that he can use. And
+ * there is currently no automatic match between the entities and tokens...

This is already handled by the entity API: It supports a special key in hook_entity_info() to specify the 'token type'. See its docs and/or the entity-token module. Afaik also token.module makes use of that key, thus best this module should too.

+++ b/auto_nodetitle.module
@@ -23,72 +23,200 @@ function auto_nodetitle_permission() {
+      } else {

Coding style.

+++ b/auto_nodetitle.module
@@ -23,72 +23,200 @@ function auto_nodetitle_permission() {
+function auto_nodetitle_entity_presave($entity, $type) {
+  if (auto_nodetitle_is_needed($entity, $type)) {

Given this runs on every entity-hook, this should be as fast as possible. Thus best check first whether "ant" is enabled for the given entity type.

bforchhammer’s picture

Status: Needs work » Closed (won't fix)

Thank you for you review, fago!

I have gone ahead and created issues for the open tasks/problems in my sandbox. Let's continue work + discussion over there.

Also, please let me know if you'd like to co-maintain the new module or help in any way!

bforchhammer’s picture

The sandbox has now become a full project: auto_entitylabel

I have also added an "upgrade path" for people who are currently using a patch from this issue. This should make transitioning to the new module fairly painless.

itamair’s picture

great! .., and really well done!