Hello!
I have a field collection called "Fähigkeiten" on a profile. Its a collection for musicians where they can store their instruments and skills (beginner, intermediate,...).
When editing a field collection item the title of the page is e.g. Fähigkeiten 1. That's not very descriptive so I tried to substitued the title with the instrument. The same for the delete-page.
My results are not optimal. I only get the title of the edit-page changed, not the browser title. Maybe someone could please give me a tip how to do this?!
Thanks a lot!
Katharina
Here is my code:
It only works in mytheme_process_page. In the preprocess I get an WSOD.
if ($variables['page']['content']['system_main']['#bundle']=='field_prm_faehigkeit') {
$tid = $variables['page']['content']['system_main']['field_mf_art']['und']['#value']['0'];
$term = taxonomy_term_load($tid);
if(is_object($term)) {
$variables['title'] = $term->name;
}
}
Comments
Comment #1
designcontext commentedOk, I get it for the edit-page with:
in the preprocess-page-function. But no success with the delete-page...
Comment #2
drupa11y commentedHi Katharina,
why not use this module with tokens: http://drupal.org/project/page_title
The Page Title module lets you change these defaults in two ways. First, you can adjust the patterns below using the placeholders given. This will change the way the default page titles are created. Second, on enabled forms (curently node, term & user editing forms) you have the option of specifying a title that is different to the title of the item. This field only appears if the Show Field box is checked for the item. If a value is provided it will be used to generate the [current-page:page-title] placeholder however if it is left blank the [current-page:page-title] token will inherit the item's own title.
The [current:page-title] token will default to the value returned from drupal_get_title if there is no value specified or no available page title field.
Certain types of page title pattern have access to special tokens which others do not, depending on their scope. All patterns have access to the Global scope. Content type patterns have access to the Node tokens, vocabulary patterns have access to the Taxonomy tokens and finally the user patterns have access to the User tokens.
Comment #3
designcontext commentedI think installing a module for changing only one page title is a little bit too much.
Comment #4
tim.plunkettIn a custom module (or even theme), you can add this function. Replace
YOURMODULEwith the name of your module or theme.Comment #5
khanz commentedIt would be great to have the ability to set automatic titles on field collection view as well as edit pages. Is there a plan to integrate Token and Automatic Nodetitles (or Automatic Entity Label) or is it really an overkill?
Comment #6
khanz commentedupdating version
Comment #7
xjmThe page title for the item add form is similarly vague: "Add new My thingy". It would at least be good to provide contextual information about which entity the new or updated item belongs to.
See also:
#1339294: drupal_set_title() should never be called inside a form builder
#1482108: Page title for new single field collection not translated
Comment #8
xjmFor reference:
Comment #9
apmsooner commentedJust adding here that solution in #8 works great however '@bundle' => $item->hostEntityBundle(), returns the machine name of the bundle rather than friendly name. A revision to this works (for nodes) though as such:
'@bundle' => node_type_get_name($item->hostEntityBundle()),Comment #10
shabana.navas commentedIf you're editing through a ctools modal form (see the field_collection_modals module), drupal_set_title won't work. You'll have to use the form_state. So this will work:
Comment #11
tory-w commentedI just wanted to chime in and say that the combination of #8 and #9 worked for my needs. Thank you so much!
Comment #12
capysara commented#8 and #9 worked for me! Thanks!