We have an option to append "all languages" to fields which are shared between translations.

If a field has more than one value, then the suffix is currently added as shown in this screenshot:

It would be better if the "all languages" suffix was added to the field label instead; ("Multiple Integers" in this case).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Component: Base system » User interface
bforchhammer’s picture

Status: Active » Needs review
FileSize
1.71 KB

Attached patch fixes the issue with multiple field values.

This seems to work well for core number, text, lists, and file/image fields (anything else I should test with?). It doesn't work with the "Media File Selector" widget (provided by media module), and that's probably easier to fix directly in the media module...

If this is the way to go, we probably have to do the same change in core (8.x).

stefanos.petrakis@gmail.com’s picture

Still applies cleanly to 7.x-1.x-dev. Tested with all core field types and widgets on a clean D7.50

Pros:

  • + 1: For coming even closer to the intented functionality as stated in the function's comment => "If the given element does not have a #title attribute, the function is recursively applied to child elements." The new code reads exactly in this order.
  • + 1: For providing simpler code

Cons:

It is probably not wise to skip checking which FAPI elements should get the 'all languages' suffix. Letting this run without constraints could present problems with nested containers that get a '#title' property, as per the inline comment already state:

// ... "The reason for this check
// is because some elements have a #title attribute even though it is not
// rendered, e.g. field containers."

Alternative:

The current logic dictates that we should respect the FAPI definitions for elements with a #title property.
This presents the problem discussed here, that the suffix will apply to all children of a multivalue field. And this problem is actually specific to the cardinality property of a FAPI element (call me multivalue).
Maybe it would be wiser instead of doing away with the sanity checks provided by the current code, to try this instead:

elseif (isset($element['#title']) && isset($element['#cardinality']) && $element['#cardinality'] != 1) {
  // This is the case of a multi-value field
}

Supplied patch attempts to solve the reported problem with a bit less "disruptive" means.

plach’s picture

Status: Needs review » Reviewed & tested by the community

@stefanos.petrakis:

I fully agree on your analysis and the fix looks good and works well. I'm fixing the minor nitpick below on commit, thanks!

+++ b/sites/all/modules/entity_translation/entity_translation.module
@@ -1464,6 +1464,10 @@ function _entity_translation_element_title_append(&$element, $suffix) {
+  // If this is a multi-valued field, apply the suffix to the container

Missing trailing dot :)

plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed, thanks.

Status: Fixed » Closed (fixed)

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