This causes an empty label and container to be rendered even if there is no map.

This is because it still returns a full elements array even if there are no items in it. Small patch attached that fixes this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Paul Lomax’s picture

Title: Geofield Openlayers field formatter returns an field even if it has no data » Geofield Openlayers field formatter returns a field even if it has no data
maijs’s picture

Version: 7.x-2.0-alpha2 » 7.x-2.x-dev
Status: Active » Needs review
FileSize
754 bytes

This issue is still unresolved. The field label is displayed even if there is no data input by user.

The patch provided by @Paul Lomax didn't work for me. This patch uses the same concept and is against 7.x-2.x-dev.

ducktape’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Patch in #2 works as expected.

Shouldn't this be expanded over all formatter types?

Jelle_S’s picture

Re-uploading. Somehow our build server is getting a 403 unauthorized on the patch above.

  • poker10 committed e17be1be on 7.x-2.x authored by Paul Lomax
    Issue #1915050 by Paul Lomax, maijs: Geofield Openlayers field formatter...
poker10’s picture

Status: Reviewed & tested by the community » Fixed

Shouldn't this be expanded over all formatter types?

No, because all other formatters fills the $element array in foreach cycles, therefore it is populated only if $items is not an empty array. This one formatter does populate the $element array directly without the check.

See:

    case 'geofield_openlayers':
      $map_name = $display['settings']['map_preset'] ? $display['settings']['map_preset'] : 'geofield_formatter_map';
      $element[0] = array('#markup' => _geofield_openlayers_formatter($map_name, $items));
      return $element;

vs:

    case 'geofield_def_list':
      foreach ($items as $delta => $item) {
        $element[$delta] = array('#markup' => _geofield_def_list_formatter($item, $display['settings']));
      }
      return $element;

I think the patch is correct. Committed this, thanks all!

Status: Fixed » Closed (fixed)

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