API page: https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.api.php/...

It appears this is only invoked if a corresponding hook_field_formatter_settings_summary() returns a summary.

This comment should be folded into the documentation.

Comments

jhodgdon’s picture

OK, this needs to be verified in the code and then added to the docs.

joachim’s picture

It was something tripped me up the other day when I was writing a field formatter.

jhodgdon’s picture

Issue tags: +Novice

OK, I'm looking at the code. The place where the Display settings page is built is:
https://api.drupal.org/api/drupal/modules!field_ui!field_ui.admin.inc/fu...

What you're saying is definitely true. The display form does this, near the bottom:

    // Display a summary of the current formatter settings.
      $summary = module_invoke($formatter['module'], 'field_formatter_settings_summary', $field, $instance, $view_mode);
      $table[$name]['settings_summary'] = array();
      $table[$name]['settings_edit'] = array();
      if ($summary) {
        // (put up the edit button and a summary of the settings)
      }

So, it does look like we should edit hook_field_formatter_settings_form() to say that if you have a settings form, you also need to implement hook_field_formatter_settings_summary() and make sure it returns a value that does not evaluate to FALSE (a non-empty string). The docs for https://api.drupal.org/api/drupal/modules!field_ui!field_ui.api.php/func... already say this, but I definitely agree it should be mentioned on the settings form hook too.

These two hooks should also be in the group/topic field_formatter, not field_types as they are now. (While we're at it, is it too out of scope to fix hook_field_widget_settings_form to be in group/topic field_widget instead of field_types too, in the same file?)

sachin_s’s picture

Assigned: Unassigned » sachin_s

I am updating the documentation hook_field_formatter_settings_form().

sachin_s’s picture

Assigned: sachin_s » Unassigned
Status: Active » Needs review
StatusFileSize
new594 bytes

Please review the patch. The documentation for hook_field_formatter_settings_form() has been updated to mention that it needs hook_field_formatter_settings_summary() implementation to get invoked.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks!

Could we make the wording a little better though? It seems awkward to me.

Maybe:

This hook is not invoked unless hook_field_formatter_settings_summary() returns a non-empty value.

What do you think?

joachim’s picture

I think that's better, but that's at least a double if not a triple negative! This would be easier to read:

This hook is only invoked if hook_field_formatter_settings_summary() returns a non-empty value.

And also we could perhaps say:

This hook is only invoked if the corresponding implementation of hook_field_formatter_settings_summary() returns a non-empty value for the formatter type.

jhodgdon’s picture

I like the last option in #7. Can we get a new patch? Thanks!

sachin_s’s picture

Assigned: Unassigned » sachin_s

Sure, I will update the wordings.

sachin_s’s picture

Assigned: sachin_s » Unassigned
Status: Needs work » Needs review
StatusFileSize
new533 bytes

Please review the new patch. Thanks!

sachin_s’s picture

I am new to d.o contribution, so just wondering if I need to provide an advanced patch using "git format-patch", or just the "git diff" is enough for drupal core.

joachim’s picture

git diff is fine.

(For very big patches that change lots of things for different reasons, I sometimes use git format-patch with whichever option it is to make it make a patch instead of a ton of mbox files, as then you get a sequence of changes, each with a comment.)

sachin_s’s picture

Thanks @joachim.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

Status: Reviewed & tested by the community » Needs work
sachin_s’s picture

jhodgdon’s picture

Status: Needs review » Fixed

Thanks again! Committed to 7.x.

sachin_s’s picture

Thank you, was my first commit so far :)

jhodgdon’s picture

Congratulations sachin_s!

  • Commit e07145e on 7.x by jhodgdon:
    Issue #2268947 by sachin_s, joachim: Add note to...

Status: Fixed » Closed (fixed)

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