diff --git a/docs/development/module/services.md b/docs/development/module/services.md index 08943cf3c..d8ee243e7 100644 --- a/docs/development/module/services.md +++ b/docs/development/module/services.md @@ -13,6 +13,8 @@ determining an asset's location and geometry. **Methods**: +`isLocation($asset)` - Check if an asset is a location. Returns a boolean. + `isFixed($asset)` - Check if an asset is fixed. Returns a boolean. `hasLocation($asset)` - Check if an asset is located within other location diff --git a/modules/core/location/src/AssetLocation.php b/modules/core/location/src/AssetLocation.php index 83bd5d1f4..8053473e8 100644 --- a/modules/core/location/src/AssetLocation.php +++ b/modules/core/location/src/AssetLocation.php @@ -22,6 +22,13 @@ class AssetLocation implements AssetLocationInterface { */ const ASSET_FIELD_GEOMETRY = 'intrinsic_geometry'; + /** + * The name of the asset boolean location field. + * + * @var string + */ + const ASSET_FIELD_LOCATION = 'is_location'; + /** * The name of the asset boolean fixed field. * @@ -99,6 +106,13 @@ class AssetLocation implements AssetLocationInterface { ); } + /** + * {@inheritdoc} + */ + public function isLocation(AssetInterface $asset): bool { + return !empty($asset->{static::ASSET_FIELD_LOCATION}->value); + } + /** * {@inheritdoc} */ diff --git a/modules/core/location/src/AssetLocationInterface.php b/modules/core/location/src/AssetLocationInterface.php index 8e3982f99..a2c53edad 100644 --- a/modules/core/location/src/AssetLocationInterface.php +++ b/modules/core/location/src/AssetLocationInterface.php @@ -10,6 +10,17 @@ use Drupal\log\Entity\LogInterface; */ interface AssetLocationInterface { + /** + * Check if an asset is a location. + * + * @param \Drupal\asset\Entity\AssetInterface $asset + * The Asset entity. + * + * @return bool + * Returns TRUE if it is a location, FALSE otherwise. + */ + public function isLocation(AssetInterface $asset): bool; + /** * Check if an asset is fixed. *