Skip to content

Commit

Permalink
Add asset inventory views field farmOS#679
Browse files Browse the repository at this point in the history
  • Loading branch information
wotnak authored and mstenta committed May 16, 2023
1 parent 0ad1d6a commit 6bb1e17
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
23 changes: 23 additions & 0 deletions modules/core/inventory/farm_inventory.views.inc
Original file line number Diff line number Diff line change
@@ -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',
],
];
}
}
16 changes: 16 additions & 0 deletions modules/core/inventory/src/Plugin/views/field/AssetInventory.php
Original file line number Diff line number Diff line change
@@ -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 {

}

0 comments on commit 6bb1e17

Please sign in to comment.