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

Automatically add asset Views to other taxonomy terms provided by modules.

This commit is contained in:
Michael Stenta 2017-06-27 14:39:22 -04:00
parent 913e499e72
commit 411dd57e53
4 changed files with 43 additions and 42 deletions

View file

@ -183,6 +183,7 @@ function farm_crop_farm_ui_entities() {
'label_plural' => t('Crops/varieties'),
'view' => 'farm_crops',
'farm_asset' => 'planting',
'asset_view_arg' => 2,
),
'farm_crop_families' => array(
'label' => t('Crop Family'),
@ -203,15 +204,6 @@ function farm_crop_farm_ui_entity_views($entity_type, $bundle, $entity) {
if ($entity_type == 'taxonomy_term') {
switch ($entity->vocabulary_machine_name) {
// Farm crops.
case 'farm_crops':
$views[] = array(
'name' => 'farm_plantings',
'arg' => 2,
'always' => TRUE,
);
break;
// Farm crop family.
case 'farm_crop_families':
$views[] = 'farm_crops';

View file

@ -33,12 +33,14 @@ function farm_livestock_farm_ui_entities() {
'label_plural' => t('Groups'),
'view' => 'farm_animal_groups',
'farm_asset' => 'animal',
'asset_view_arg' => 2,
),
'farm_animal_types' => array(
'label' => t('Type'),
'label_plural' => t('Types'),
'view' => 'farm_animal_types',
'farm_asset' => 'animal',
'asset_view_arg' => 3,
),
),
);
@ -57,39 +59,6 @@ function farm_livestock_farm_area_type_info() {
);
}
/**
* Implements hook_farm_ui_entity_views().
*/
function farm_livestock_farm_ui_entity_views($entity_type, $bundle, $entity) {
$views = array();
// If the entity is a taxonomy_term...
if ($entity_type == 'taxonomy_term') {
switch ($entity->vocabulary_machine_name) {
// Farm animal groups:
case 'farm_animal_groups':
$views[] = array(
'name' => 'farm_animals',
'arg' => 2,
'always' => TRUE,
);
break;
// Farm animal types:
case 'farm_animal_types':
$views[] = array(
'name' => 'farm_animals',
'arg' => 3,
'always' => TRUE,
);
break;
}
}
return $views;
}
/**
* Implements hook_farm_log_categories().
*/

View file

@ -108,6 +108,14 @@ function hook_farm_ui_entities() {
// The specific asset type that these terms apply to (optional).
'farm_asset' => 'planting',
// The position of a contextual filter argument corresponding to this
// taxonomy term in the View of assets that these terms apply to
// (optional). This will enable the View of assets to be displayed
// on the term pages, filtered to only show assets tagged with the
// term being viewed. In most cases, this will be 2 or 3, because asset
// Views should always have asset location as their first argument.
'asset_view_arg' => 2,
),
),
);

View file

@ -263,6 +263,38 @@ function farm_ui_farm_ui_entity_views($entity_type, $entity_bundle, $entity) {
}
}
// Otherwise, if this is a taxonomy term...
elseif ($entity_type == 'taxonomy_term') {
// And if the term is associated with a specific asset type...
if (!empty($ui_info[$entity_type][$entity_bundle]['farm_asset'])) {
// Get the asset type.
$asset_type = $ui_info[$entity_type][$entity_bundle]['farm_asset'];
// And if that asset type has a View.
if (!empty($ui_info['farm_asset'][$asset_type]['view'])) {
// Get the View.
$asset_view = $ui_info['farm_asset'][$asset_type]['view'];
// And if the 'asset_view_arg' key is set...
if (!empty($ui_info[$entity_type][$entity_bundle]['asset_view_arg'])) {
// Get the argument position.
$arg = $ui_info[$entity_type][$entity_bundle]['asset_view_arg'];
// Add the asset View to this term (and always show it).
$views[] = array(
'name' => $asset_view,
'arg' => $arg,
'always' => TRUE,
);
}
}
}
}
return $views;
}