feature: #3638392: Add an action that assigns the entity whose geometry contains a Geofield value to an entity reference field

Adds the "Geofield: assign containing entity reference" action (eca_geofield_assign_containing_reference).

It finds the entity whose PostGIS Geofield geometry relates to the geometry in a Geofield of the current entity, for example the district whose boundary contains a record's location, and writes it into an entity reference field of the same entity. Typical use: on presave, chain "Geofield: calculate centroid" and then this action, so saving a record fills in its district.

What is included:

  • The action, configured with a source Geofield, the entity reference field, the Geofield on the referenced entity type that holds the boundary, a spatial operator (ST_Intersects by default, same allow-list as the other actions) and an option to clear the reference when nothing matches.
  • The search scope comes from the reference field: its target entity type and target bundles, so no separate entity type or bundle settings.
  • PostgisService::findEntityIdByRelation(), a new public method. If several entities match, the one with the smallest area wins (the district, not the province), then the lowest entity ID.
  • Config schema and a README row.
  • A kernel test with 13 cases: smallest area wins, point only in the larger area, area geometry as source, no match (reference kept or cleared), replacing an existing reference, operators, empty source, invalid operator, non-Geofield source, non-reference field, default configuration.

Notes for review:

  • The action does not save the entity, like "Geofield: calculate centroid". The triggering event does.
  • The boundary field must use the PostGIS backend, like the other actions. The SRID of both sides is ignored, so both must be in the same coordinate system. Both points are in the README.
  • Related to "PostGIS: Find entities by geometry": that action can already find containing entities with ST_Intersects, but it orders by entity ID and needs a second action to write the reference. This one picks the smallest area and writes the reference in one step. If you would rather extend the existing action with an ordering option, I can rework this.
  • The query also skips deleted rows (deleted = 0), consistent with queryContainedEntities().

Closes #3638392

Merge request reports

Loading
Loading