Problem/Motivation

LeafletMap::getPopupContent() expects the passed in entity ID to always be a string, but this causes a fatal type error for entity types that use integer IDs:

TypeError: Drupal\leaflet_views\Plugin\views\style\LeafletMap::getPopupContent(): Argument #2 ($entity_id) must be of type string, int given, called in /leaflet/modules/leaflet_views/src/Plugin/views/style/LeafletMap.php on line 1123 in Drupal\leaflet_views\Plugin\views\style\LeafletMap->getPopupContent() (line 1235 of /leaflet/modules/leaflet_views/src/Plugin/views/style/LeafletMap.php).

EntityInterface::id() allows returning both string and integer IDs:

  /**
   * Gets the identifier.
   *
   * @return string|int|null
   *   The entity identifier, or NULL if the object does not yet have an
   *   identifier.
   */
  public function id();

Code path is as follows:

  • LeafletMap::processGeofield() calls ::extractEntityDetails()
  • ExtractEntityDetails() retrieves the entity ID by calling $entity->id() (which is an integer) and returns it in the $details array.
  • LeafletMap::processGeofield() then calls ::processEntityFeatures(), passing $details.
  • ::processEntityFeatures() unpacks the $details and passes the integer $entity_id to ::getPopupContent() which accepts only strings.

Steps to reproduce

  1. Add a geofield to an entity type that uses integer IDs.
  2. Create a view that lists the entities and set it to display as a Leaflet Map.
  3. Render the view.

Proposed resolution

Change the signature of ::getPopupContent() to accept also integer values for the entity ID.

Issue fork leaflet-3592904

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Status: Active » Needs review
itamair’s picture

Status: Needs review » Fixed

thx @pfrenssen ... merged. Will be part of next Leaflet module release.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.