3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Expose the computed "group" asset field to Views.

This commit is contained in:
Michael Stenta 2021-05-27 13:23:31 -04:00
parent 0eff167220
commit 58ced4cdb3
2 changed files with 31 additions and 0 deletions

View file

@ -29,6 +29,21 @@ function farm_group_entity_base_field_info(EntityTypeInterface $entity_type) {
}
}
/**
* Implements hook_views_data_alter().
*/
function farm_group_views_data_alter(array &$data) {
// Add the computed group membership field to assets.
$data['asset']['group'] = [
'title' => t('Current group'),
'field' => [
'id' => 'asset_group',
'field_name' => 'group',
],
];
}
/**
* Implements hook_views_pre_view().
*/

View file

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