This post is a continuation of the overly long and messy discussion at http://drupal.org/node/32069.

In this thread are posted two different patches for flexinode that allow aministrators to take advantage of new functionality in Drupal 4.7 which allows custom title labels for content types.

The first patch, attached to this post, is much cleaner code-wise. The second patch, posted immediately below, is messier but perhaps slightly more user-friendly (or maybe not?) . I'm looking for feedback and comments on which method is preferred.

Note: Database update required!
The first patch requires you modify the database: you need to add a new varchar(255) field to the flexinode_type table in the database. The name of the field is "title_label". The second patch requires a a new int(1) field to be added to the flexinode_field table. The field's name is 'is_title'.

Comments

Steve Dondley’s picture

StatusFileSize
new6.87 KB

See post immediately above for an explanation of the patch attached here. Don't forget to make the change to the database (see above also).

bryan kennedy’s picture

+1 for flexinode_titles_1.patch

Works great on my site now. I tried the other and it didn't seem to be any more "user-friendly" IMO.

bryan kennedy’s picture

Okay, I do notice one problem. My Path alias form feild is now showing up above the title for the flexinode. Ideally this should fit underneath the title.

scroogie’s picture

Why dont you just make the node title a new field type? Then the user wont need no database update (and by the way it seems to be more in the flexinode style).

Steve Dondley’s picture

scroogie,

because the title field is so tightly integrated with the rest of Drupal, what you suggest won't work.

Steve Dondley’s picture

bryan,

This problem will have to wait until after the flexinode module gets converted to the new forms API.

scroogie’s picture

Can you tell me why it would not work? You could just copy the textfield type and change the save function to update the right entry in the nodes table.

Bèr Kessels’s picture

Having no title is not an option in Drupal. Blocks, lists, and nearly al of the node administration will break. So if we need a title anyway, its best to just provide it, not? :)

scroogie’s picture

Okay, got that. Then Patch 1 gets my vote.

drumm’s picture

Status: Needs review » Needs work

This patch no longer applies to HEAD.

gnat’s picture

Status: Needs work » Needs review
StatusFileSize
new6.38 KB

this patch, which is written against the current cvs version, adds a checkbox to the flexinode field create/edit screen of text fields for flexinode content types called "Use as Title" which will set the input of that field as the the title in the node table. the option is checked in form validation to ensure that only one field per ctype is allowed to be a title. this requires an update to the database, which is provided with this patch.

in the create/edit content screens for those ctypes there is no 'Title' field in the form. instead the flexinode field appears as it would were it any other text field. i thought it advantageous to do it this way, since it gives a more complete control to the presentation of the form in terms of weight. though i realize others may disagree about this.

there are a few things that either need to be fixed, or would be cool features if they were added, but i wanted to submit what i had, to see if people liked the direction this patch is headed before spending more time on it.

those are:

  • currently a "Use as Title" flag does not make the field required, but bypasses the title check. i will have to fix this, and make sure that "Use as Title" sets required to 1 as well.
  • the field that is used as a title does not show up in previews. this is a mix of not being sure why, and not knowing the best way to handle this.
  • i would like to allow more than one field be used as a title, whose values get concoctenated into a title, but truncated at 128 characters.
  • currently this feature is only available to textfield types, perhaps limited other types can be added?
gnat’s picture

StatusFileSize
new1.32 KB

here's the mysql patch.

gnat’s picture

StatusFileSize
new1.26 KB

and the pgsql patch.

bomarmonk’s picture

A definite + on the concantenated fields option. This would be very useful for flexinodes where you wanted the node title to reflect a first and last name--- something I would definitely like to accomplish!

gnat’s picture

Category: task » feature
StatusFileSize
new9.47 KB

This patch is an addition to my previous patch, which does a few of the things that I was hoping it would do, namely:

  • The "Use as Title" flag now makes the field required. This will ensure that a title is always generated.
  • Date/time fields may now also be part of the title
  • Two fields may be used in the custom title.

Adding in a second field requires another database change (new db structures below). It has also remade my to-do list on this change. As it stands it is:

  • Currently multiple titles a delimeted by a ' - '. This is what I wanted for the site I'm building this for, but I realize that this is less than ideal, and being able to set the delimeter would be helpful.
  • The custom titles still do no appear in the previews
  • whatever bugs come up as i use this further
gnat’s picture

StatusFileSize
new1.37 KB

mysql structure.

gnat’s picture

StatusFileSize
new1.31 KB

pgsql structure.

Bèr Kessels’s picture

Status: Needs review » Needs work

Great work so far, but IMO a tiny bit crufty still:

I think it is best when you not prompt an error "more then two are chosen" but rather insert the active title field and set the current one.

We should IMO not hardcode what can be titles and what not. Why not add a very simple hook call to he incs that allows any .inc to be candidate for a title:
fieldname_can_be_title() if returns TRUE, that field will be candidate for a title

Watch your coding style, quite often you forget indentations.

Please choose your functionnames carefully, not flexinode_uat_check_fields but rather flexinode_check_title_usage

Bèr

gnat’s picture

Status: Needs work » Needs review
StatusFileSize
new8.67 KB

this is another update to my patch, here's what's done in this iteration.

  • removed the error 'Two fields have already been selected for the title' since it was not being used as of my last patch.
  • renamed the function 'flexinode_uat_check_fields' to 'flexinode_check_title_usage'
  • cleaned up the code so that it conforms with coding standards
  • added a hook call to the .inc files so that each field type can return 'flexinode_field_$fieldname_can_be_title' as true, and allow it to be used as a title.
  • edited field_timestamp.inc and field_textfield.inc so that they may still be used as titles.
gnat’s picture

StatusFileSize
new273 bytes

patch for field_textfield.inc

gnat’s picture

StatusFileSize
new421 bytes

patch for field_timestamp.inc

Bèr Kessels’s picture

Looks a lot better. Thanks.

Can someone else have a look at this too? I am not confident to call my quick patching and checking actually is reviewing. Flexinode is rather comlpex :)

Some very very minor things: gnat, please check your editor for it adds a lot of spaces like }_____ And also, in some future, rather just commit your changes as one patch, instead of a patch per file. That is a lot easier for all of us to review.

rlbravo’s picture

Title: Custom titles for flexinode » Version Support
Version: master » 4.6.x-1.x-dev
Component: Code » Documentation
Category: feature » support
Priority: Normal » Minor

Does this patch works in version 4.6.3. Thanks Steve.

Steve Dondley’s picture

Steve Dondley’s picture

Title: Version Support » Custom titles for flexinode

rlbravo: do not change the title

gnat’s picture

Version: 4.6.x-1.x-dev » master
Component: Documentation » Code
Category: support » feature

also, don't change version, compnent, and category.

Bèr Kessels’s picture

Status: Needs review » Needs work

gnat: I want to get this feature in the 4.7 branch soon.
Can you

* Provide a SINGLE patch. Tracking amd reviewing four patches (for each file one) is very hard.
* Provide an updated patch?

Bèr

gnat’s picture

Status: Needs work » Needs review
StatusFileSize
new13.58 KB

This is a single unified patch that encompasses the five edited files for this feature (field_textfield.inc, field_timestamp.inc, flexinode.module, flexinode.mysql, flexinode.pgsql). There are no significant changes to what I have done in the code, though I did clean up the stray spaces. The flexinode module in the diff is done against the latest cvs file: flexinode.module?rev=1.66.

I would still like to add functionality for the 'delimeter', but was not sure exactly where to put that. Is this something that should be part of the ctype information? I would like some feedback on where such a thing should go. Bottom line having a hard coded ' - ' to deliminate the two elements of a title should not be the way it is done. So somewhere a select box needs to be added so that it can be more tailored to the user's needs, some of the other things I can think of are ' ' (one space), ' ' (two spaces), ',' (comma/comma space), etc. I'm just not sure where it should be added and what table in the DB it should be a part of. So if anyone has thoughts on that, and helps come up with a good strategy, I would be more than happy to write the code. :)

Patrick Nelson’s picture

Firstly, works superbly - thanks for the patches and the efforts of all involved.

Secondly, in light of the removal of node_validate, are there any changes to be made to these patches? There are changes that need to be made to code in the CVS version of flexinode but some of the code that needs to be changed has already been modified by these patches?

gnat’s picture

StatusFileSize
new9 KB

This patch removes the use of node_validate_title() from my patch.

Patrick Nelson’s picture

Thanks gnat,

That works for me.

Patrick Nelson’s picture

OK, I lied.

I'm getting an error now when viewing any flexinode content that seems to be related to this latest patch.

The error reads:

Warning: Illegal offset type in /var/www/modules/flexinode/flexinode.module on line 451

Where line 451 is as below:

449     function flexinode_node_name($type) {
450       $types = flexinode_node_info();
<b>451       return $types[$type]['name'];</b>
452     }

The reason I say "seems to" is because I have also updated to flexinode 1.68.

If this error is not related to this patch, I'll open a new issue, but I could do with some help figuring out why it's occuring in the first place.

Many thanks

Patrick Nelson’s picture

The "...." tags are not in my module - that's just me trying to emphasise that line in this post.

Steve Dondley’s picture

I can't view the mysql patches. Acess is forbidden.

Steve Dondley’s picture

Status: Needs review » Needs work

OK, was able to figure out what db fields to add by looking at the patch.

If I understand the patch correctly, it seems like it should concatenate two fields together if there is more than one field marked as "use as title". This feature does not seem to work.

Steve Dondley’s picture

OK, not sure what just happened but I disabled one of the title fields and then re-enabled it. And now that field says "second part of title".

So the module works, but it seems you have to enable the two title fields a certain way. I consider that a bug.

bomarmonk’s picture

Does this new custom title work for the 4.7 version of flexinode? Is it working well enough to run on a live site? Thanks for any information. Tempted to try...

bomarmonk’s picture

Can anyone tell me how to apply the database changes for this patch? I think I have all the files properly patched, but I'm not sure how to run the sql updates included here. I would really like to have this feature. Thank you for any help!

Steve Dondley’s picture

Add the following fields to the flexinode_data table

name             type        allow nulls   key   default value
use_as_title 	tinyint(4) 	Yes 	None 	0  	 
use_as_title_2 	tinyint(4) 	Yes 	None 	  	 
Steve Dondley’s picture

Damn, sorry! That last post should say change the flexinode_field table (not flexinode_data).

bomarmonk’s picture

This patch works! Very nice! I can confirm the odd behavior with the second field being combined with the title. Disable the second field, reenable it, and magically the text appears: "make second part of title." A minor bug.

Also, since I converted existing flexinodes (with preexisting titles), the old title stayed around. After getting those fields to set properly to title, I had to edit each flexinode and resubmite (changing nothing), in order for the new fields to display properly as title. Could the module change for the preexisting titles and disable them somehow, without having to resubmit all the flexinodes with the new title setting?

One more minor quirk: I had a flexinode with a first name field (one of the title fields) and one of these names included a nickname in quotes. It seemed as though this new patch didn't know how to deal with the quotes-- they broke and became something like &quote;

Finally, would it be easy to have an option to change the delimineter between the fields in the title? I have a first and last name, so a comma seems most logical. Right now, I get a dash.

This is awesome, though. Thanks for your work on this patch. I hope it gets into the 4.7 version of flexinode. For now, its been worth the patching.

bomarmonk’s picture

One more thing: the earlier functionality of having a different label for the title goes hand-in-hand with this latest patch. I hope someone can carry that over and combine it into a unified patch... or a seperate one, since I have already applied the use_as_title patch.

bomarmonk’s picture

Sorry, I noticed that the author of this patch already discussed the delimineter, so my earlier comment is redundant. I was thinking about how to include a dilemeter: you would want it on a per-content type basis, so that all content types can concatenate the fields with a different seperator. So maybe this should be a seperate textfield for flexinode, where the user can put in anything he or she wants? Or a drop-down of deliminiters that becomes available after two fields have been enabled as the title? The values for the dropdown could be stored in a list within the general flexinode settings page (that sounds a bit tricky, but that might be nice). By default, if the delimiter is not chosen, we get the dash.... just my two cents.

bomarmonk’s picture

StatusFileSize
new26.54 KB

Well, I have this working with two textfields, but when I try to use the timestamp/date as the title (only this, no other field), the title just doesn't show itself. The option is there: make this a title. I enable this and the edit-form excludes the traditional title field-- so far so good. Then, when looking at the node in the content area, or in a list, the title does not appear (you can see the date if you look at the full node).

Please have a look at this and see if it can be replicated. Thanks. I am attaching a image of the problem (see how the blotter entry looks)

adamrice’s picture

Does anyone have this working on the latest release of Flexinode? This patch would be useful to me, but naturally I'd rather mess with the final release of the module for 4.7 than some unreliable pre-release version <g>