By default on node edit form when you click "Provide a menu link", menu link title is automatically filled up with node title.

After installing "title" module and enabling title on content type you lose this feature. Menu link title stays empty and you have to fill it up manually.

Comments

gaëlg’s picture

Status: Active » Needs review

The following last three lines should be added for /modules/menu/menu.js to detect the title.

function title_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  $fr_info = title_field_replacement_info($entity_type);
  if (!empty($fr_info)) {
    foreach ($fr_info as $legacy_field => $info)  {
      if (isset($form[$legacy_field]) && title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
        $form[$legacy_field]['#access'] = FALSE;
        $form[$legacy_field]['#field_replacement'] = TRUE;
        // Add a class for automatic filling of menu link title.
        $replacing_field = &$form[$info['instance']['field_name']];
        $replacing_field['#attributes']['class'][] = 'form-item-title';
      }
    }
  }
}
plach’s picture

Version: 7.x-1.0-alpha4 » 7.x-1.x-dev
Status: Needs review » Active

Please, create a patch with the proposed change.

gaëlg’s picture

Status: Active » Needs review
StatusFileSize
new965 bytes

Alright. It works as is but it may be a bad way of doing it, so I did not take the time to make a patch. Should it have an isset() check for example? Anyway, the easy fix is to add the class that menu.js is looking for.

plach’s picture

Well, isset checks never hurt :)

Anyway if this actually fixes the issue it does not look so bad. Did you try it with field groups?

gaëlg’s picture

No. All I can say is it works for my needs, with the "default" Title field. I just needed it for use with Entity Translation (the dev version includes an interface to set the menu link title per language in the node form).
But I don't see why it wouldn't work with field groups, as the jquery selector to find the title is simply var $title = $(this).closest('form').find('.form-item-title input');

plach’s picture

I think Field Groups manipulates the form array hence the line selecting the replacing field wiget might not always work. Not sure about this. We need manual testing.

plach’s picture

Status: Needs review » Needs work
+++ b/title.module
@@ -473,6 +473,9 @@ function title_field_attach_form($entity_type, $entity, &$form, &$form_state, $l
+        // Add a class for automatic filling of menu link title.
+        $replacing_field = &$form[$info['instance']['field_name']];
+        $replacing_field['#attributes']['class'][] = 'form-item-title';

This won't always be a title or even a label (think of a taxonomy term description). We need to fix this by inheriting the attributes of the legacy field widget (see also #1748008: Replaced fields should inherit the legacy field access).

duellj’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new733 bytes

How about this patch? Uses the legacy field name instead of hardcoded "title".

nicolas bouteille’s picture

Status: Needs review » Reviewed & tested by the community

It works and no errors. Thanks!

  • Commit b0a5aeb on 7.x-1.x authored by duellj:
    Issue #1772116 by duellj, GaëlG | f4o: Fixed Menu link title is not...
plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed, thanks.

  • Commit b0a5aeb on 7.x-1.x, workbench authored by duellj:
    Issue #1772116 by duellj, GaëlG | f4o: Fixed Menu link title is not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.