2015-10-04 22:24:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Farm asset views hooks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_views_data_alter().
|
|
|
|
*/
|
|
|
|
function farm_asset_views_data_alter(&$data) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What we want to do here is override the reverse entity reference
|
|
|
|
* relationship handler that's used to join in farm assets that reference
|
|
|
|
* terms. This is used in various farmOS Views that display a list of
|
|
|
|
* terms, with a count of the number of assets that are in them.
|
|
|
|
*
|
|
|
|
* For example: the list of Animal Groups in Farm Livestock, or the list of
|
|
|
|
* Crops in Farm Plantings.
|
|
|
|
*
|
|
|
|
* The reason we override is so that we can add a little extra logic to the
|
2018-01-31 16:27:25 +01:00
|
|
|
* join so that only non-archived assets are included. This is provided as an
|
2015-10-04 22:24:31 +02:00
|
|
|
* option in the relationship handler, so it can be added only when necessary.
|
|
|
|
*/
|
|
|
|
if (!empty($data['taxonomy_term_data'])) {
|
|
|
|
foreach ($data['taxonomy_term_data'] as $name => &$definition) {
|
|
|
|
|
|
|
|
// If the name starts with "reverse_" and ends with "_farm_asset",
|
|
|
|
// replace the relationship handler with our own.
|
|
|
|
$start = 'reverse_';
|
|
|
|
$end = '_farm_asset';
|
|
|
|
$start_len = strlen($start);
|
|
|
|
$end_len = strlen($end);
|
|
|
|
if (substr($name, 0, $start_len) == $start && substr($name, ($end_len * -1), $end_len) == $end) {
|
|
|
|
|
|
|
|
// Replace the relationship handler.
|
|
|
|
if (!empty($definition['relationship']['handler'])) {
|
|
|
|
$definition['relationship']['handler'] = 'farm_asset_handler_relationship_entity_reverse';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-31 00:05:45 +01:00
|
|
|
|
|
|
|
// Add a special filter for asset 'archived' property that treats it as a
|
|
|
|
// boolean value.
|
|
|
|
if (!empty($data['farm_asset']['archived'])) {
|
|
|
|
$data['farm_asset']['archived_boolean'] = array(
|
|
|
|
'title' => t('Archived (boolean)'),
|
|
|
|
'help' => t('Whether or not the asset is archived.'),
|
|
|
|
'filter' => array(
|
|
|
|
'real field' => 'archived',
|
|
|
|
'handler' => 'views_handler_filter_boolean_operator',
|
|
|
|
'type' => 'yes-no',
|
|
|
|
'accept null' => TRUE,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2015-10-04 22:24:31 +02:00
|
|
|
}
|
2017-04-27 15:55:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_views_plugins().
|
|
|
|
*/
|
|
|
|
function farm_asset_views_plugins() {
|
|
|
|
return array(
|
|
|
|
'argument validator' => array(
|
|
|
|
'farm_asset' => array(
|
|
|
|
'title' => t('Farm asset'),
|
|
|
|
'handler' => 'farm_asset_plugin_argument_validate_farm_asset',
|
2017-12-28 17:18:06 +01:00
|
|
|
'path' => drupal_get_path('module', 'farm_asset') . '/includes/views/plugins',
|
2017-04-27 15:55:22 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|