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

designcontext’s picture

Ok, I get it for the edit-page with:

if ((arg(0) == 'field-collection') && (arg(1) == 'field-prm-faehigkeit' )) {
    if (arg(3) == 'edit') {
      $tid = $variables['page']['content']['system_main']['field_mf_art']['und']['#value']['0'];
      $term = taxonomy_term_load($tid);
      if(is_object($term)) {
        $titel = $term->name;
        $titel = 'Musikalische Fähigkeit "' . $titel . '" bearbeiten';
        drupal_set_title($titel,PASS_THROUGH);
      }
    }

in the preprocess-page-function. But no success with the delete-page...

drupa11y’s picture

Hi 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.

designcontext’s picture

I think installing a module for changing only one page title is a little bit too much.

tim.plunkett’s picture

In a custom module (or even theme), you can add this function. Replace YOURMODULE with the name of your module or theme.

function YOURMODULE_form_field_collection_item_form_alter(&$form, &$form_state, $form_id) {
  drupal_set_title(t('Your title'));
}
khanz’s picture

It 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?

khanz’s picture

Version: 7.x-1.0-beta1 » 7.x-1.0-beta3

updating version

xjm’s picture

Title: Changing the title when editing or deleting field collection items » Page title when adding/editing individual field collection items
Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Category: support » feature

The 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

xjm’s picture

For reference:

function mymodule_form_field_collection_item_form_alter(&$form, &$form_state, $form_id) {
  $item = $form_state['field_collection_item'];
  if (!isset($item->is_new)) {
    drupal_set_title(
      t(
        'Edit @label for @bundle %title',
        array(
          '@label' => $item->label(),
          '@bundle' => $item->hostEntityBundle(),
          '%title' => $item->hostEntity()->title,
        )
      ),
      PASS_THROUGH
    );
  }
  else {
    drupal_set_title(
      t(
        'Add new @fc_type to @bundle %title',
        array(
          '@fc_type' => $item->translatedInstanceLabel(),
          '@bundle' => $item->hostEntityBundle(),
          '%title' => $item->hostEntity()->title,
        )
      ),
      PASS_THROUGH
    );
  }
}
apmsooner’s picture

Issue summary: View changes

Just 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()),

shabana.navas’s picture

If 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:

/**
 * Implements hook_form_field_collection_item_form_alter().
 */
function mymodule_form_field_collection_item_form_alter(&$form, &$form_state, $form_id) {
  // Change the title of the blah field collection modal form.
  if (isset($form['#bundle']) && $form['#bundle'] == 'field_blah') {
    $item = $form_state['field_collection_item'];
    if (!isset($item->is_new)) {
      $form_state['title'] = t('Edit Blah Field');
    }
    else {
      $form_state['title'] = t('Add a New Blah Field');
    }
  }
}
tory-w’s picture

I just wanted to chime in and say that the combination of #8 and #9 worked for my needs. Thank you so much!

capysara’s picture

#8 and #9 worked for me! Thanks!