mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* The farmOS Flags module.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_views_data_alter().
|
|
*/
|
|
function farm_flag_views_data_alter(array &$data) {
|
|
|
|
// Because Drupal core does not provide full Views integration for base fields
|
|
// we must manually specify the list_field views filter for the flag field.
|
|
// Define the views filter settings.
|
|
$flag_filter = [
|
|
'id' => 'list_field',
|
|
'field_name' => 'flag',
|
|
'allow_empty' => TRUE,
|
|
];
|
|
$tables = [
|
|
'asset__flag',
|
|
'asset_revision__flag',
|
|
'log__flag',
|
|
'log_revision__flag',
|
|
'plan__flag',
|
|
'plan_revision__flag',
|
|
];
|
|
foreach ($tables as $table) {
|
|
if (!empty($data[$table]['flag_value'])) {
|
|
$data[$table]['flag_value']['filter'] = $flag_filter;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Allowed values callback function for the flags field.
|
|
*
|
|
* @return array
|
|
* Returns an array of allowed values for use in form select options.
|
|
*/
|
|
function farm_flag_field_allowed_values() {
|
|
/** @var \Drupal\farm_flag\Entity\FarmFlagInterface[] $flags */
|
|
$flags = \Drupal::entityTypeManager()->getStorage('flag')->loadMultiple();
|
|
$allowed_values = [];
|
|
foreach ($flags as $id => $flag) {
|
|
$allowed_values[$id] = $flag->getLabel();
|
|
}
|
|
return $allowed_values;
|
|
}
|