Add asset inventory views field #679

This commit is contained in:
wotnak 2023-05-15 17:08:09 +02:00 committed by Michael Stenta
parent 0ad1d6a698
commit 6bb1e1789e
4 changed files with 44 additions and 0 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Refresh map edit layer when WKT is pasted into data input field #670](https://github.com/farmOS/farmOS/pull/670)
- [Add QuickStringTrait::entityLabelsSummary() method for summarizing entity labels #675](https://github.com/farmOS/farmOS/pull/675)
- [Add asset inventory views field #679](https://github.com/farmOS/farmOS/pull/679)
### Changed

View File

@ -0,0 +1,4 @@
# Schema for the asset inventory views field handler.
views.field.asset_inventory:
type: views.field.field
label: 'Asset inventory field handler'

View File

@ -0,0 +1,23 @@
<?php
/**
* @file
* Provides Views data for farm_inventory.module.
*/
/**
* Implements hook_views_data_alter().
*/
function farm_inventory_views_data_alter(array &$data) {
// Add computed inventory field to assets.
if (isset($data['asset'])) {
$data['asset']['inventory'] = [
'title' => t('Current inventory'),
'field' => [
'id' => 'asset_inventory',
'field_name' => 'inventory',
],
];
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Drupal\farm_inventory\Plugin\views\field;
use Drupal\views\Plugin\views\field\EntityField;
/**
* A field that displays asset inventory.
*
* @ingroup views_field_handlers
*
* @ViewsField("asset_inventory")
*/
class AssetInventory extends EntityField {
}