diff --git a/modules/farm/farm_crop/farm_crop.module b/modules/farm/farm_crop/farm_crop.module index 09d9d202d..51f725c34 100644 --- a/modules/farm/farm_crop/farm_crop.module +++ b/modules/farm/farm_crop/farm_crop.module @@ -194,63 +194,51 @@ function farm_crop_farm_ui_entities() { } /** - * Implements hook_farm_ui_asset_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_crop_farm_ui_asset_views($farm_asset) { - - // If the entity is not a planting, bail. - if ($farm_asset->type != 'planting') { - return array(); - } +function farm_crop_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Plantings. - return array( - array( + if ($entity_type == 'farm_asset' && $bundle == 'planting') { + $views[] = array( 'name' => 'farm_log_movement', 'weight' => 100, - ), - array( + ); + $views[] = array( 'name' => 'farm_asset_children', 'display' => 'page', 'title' => t('Children'), 'weight' => 110, - ), - ); -} + ); + } -/** - * Implements hook_farm_ui_taxonomy_views(). - */ -function farm_crop_farm_ui_taxonomy_views($term) { + // If the entity is a taxonomy_term... + elseif ($entity_type == 'taxonomy_term') { + switch ($entity->vocabulary_machine_name) { - // Start a list of View names. - $views = array(); + // Farm areas: + case 'farm_areas': + $views[] = array( + 'name' => 'farm_plantings', + 'weight' => -20, + ); + break; - // Switch logic depending on the vocabulary. - switch ($term->vocabulary_machine_name) { + // Farm crops. + case 'farm_crops': + $views[] = array( + 'name' => 'farm_plantings', + 'arg' => 2, + 'always' => TRUE, + ); + break; - // Farm areas: - case 'farm_areas': - $views[] = array( - 'name' => 'farm_plantings', - 'arg' => 1, - 'weight' => -20, - ); - break; - - // 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'; - break; + // Farm crop family. + case 'farm_crop_families': + $views[] = 'farm_crops'; + break; + } } return $views; diff --git a/modules/farm/farm_equipment/farm_equipment.module b/modules/farm/farm_equipment/farm_equipment.module index 65b4f2b49..49a593893 100644 --- a/modules/farm/farm_equipment/farm_equipment.module +++ b/modules/farm/farm_equipment/farm_equipment.module @@ -31,41 +31,28 @@ function farm_equipment_farm_ui_entities() { } /** - * Implements hook_farm_ui_asset_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_equipment_farm_ui_asset_views($farm_asset) { - - // If the entity is not equipment, bail. - if ($farm_asset->type != 'equipment') { - return array(); - } +function farm_equipment_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Equipment. - return array( - array( + if ($entity_type == 'farm_asset' && $bundle == 'equipment') { + $views[] = array( 'name' => 'farm_log_movement', 'weight' => 100, - ), - ); -} - -/** - * Implements hook_farm_ui_taxonomy_views(). - */ -function farm_equipment_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); + ); } - // Return a list of Views to include on Areas. - return array( - array( + // Show equipment in area pages. + elseif ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( 'name' => 'farm_equipment', 'weight' => -10, - ), - ); + ); + } + + return $views; } /** diff --git a/modules/farm/farm_livestock/farm_livestock.module b/modules/farm/farm_livestock/farm_livestock.module index e918a7022..2623ea3a6 100644 --- a/modules/farm/farm_livestock/farm_livestock.module +++ b/modules/farm/farm_livestock/farm_livestock.module @@ -58,66 +58,55 @@ function farm_livestock_farm_area_type_info() { } /** - * Implements hook_farm_ui_asset_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_livestock_farm_ui_asset_views($farm_asset) { - - // If the entity is not an animal, bail. - if ($farm_asset->type != 'animal') { - return array(); - } +function farm_livestock_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Animals. - return array( - array( + if ($entity_type == 'farm_asset' && $bundle == 'animal') { + $views[] = array( 'name' => 'farm_log_movement', 'weight' => 100, - ), - array( + ); + $views[] = array( 'name' => 'farm_asset_children', 'display' => 'page', 'title' => t('Children'), 'weight' => 110, - ), - ); -} + ); + } -/** - * Implements hook_farm_ui_taxonomy_views(). - */ -function farm_livestock_farm_ui_taxonomy_views($term) { + // If the entity is a taxonomy_term... + elseif ($entity_type == 'taxonomy_term') { + switch ($entity->vocabulary_machine_name) { - // Start a list of View names. - $views = array(); + // Farm areas: + case 'farm_areas': + $views[] = array( + 'name' => 'farm_animals', + 'weight' => -10, + ); + break; - // Switch logic depending on the vocabulary. - switch ($term->vocabulary_machine_name) { + // Farm animal groups: + case 'farm_animal_groups': + $views[] = array( + 'name' => 'farm_animals', + 'arg' => 2, + 'always' => TRUE, + ); + break; - // Farm areas: - case 'farm_areas': - $views[] = array( - 'name' => 'farm_animals', - 'weight' => -10, - ); - break; - - // 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; + // Farm animal types: + case 'farm_animal_types': + $views[] = array( + 'name' => 'farm_animals', + 'arg' => 3, + 'always' => TRUE, + ); + break; + } } return $views; diff --git a/modules/farm/farm_log/farm_log_activity/farm_log_activity.module b/modules/farm/farm_log/farm_log_activity/farm_log_activity.module index c11c77f23..12966abd0 100644 --- a/modules/farm/farm_log/farm_log_activity/farm_log_activity.module +++ b/modules/farm/farm_log/farm_log_activity/farm_log_activity.module @@ -25,20 +25,18 @@ function farm_log_activity_farm_ui_entities() { } /** - * Implements hook_farm_ui_taxonomy_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_log_activity_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); - } +function farm_log_activity_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Areas. - return array( - array( + if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( 'name' => 'farm_log_activity', 'arg' => 2, - ), - ); + ); + } + + return $views; } diff --git a/modules/farm/farm_log/farm_log_input/farm_log_input.module b/modules/farm/farm_log/farm_log_input/farm_log_input.module index b17368442..72a87607b 100644 --- a/modules/farm/farm_log/farm_log_input/farm_log_input.module +++ b/modules/farm/farm_log/farm_log_input/farm_log_input.module @@ -25,20 +25,18 @@ function farm_log_input_farm_ui_entities() { } /** - * Implements hook_farm_ui_taxonomy_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_log_input_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); - } +function farm_log_input_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Areas. - return array( - array( + if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( 'name' => 'farm_log_input', 'arg' => 2, - ), - ); + ); + } + + return $views; } diff --git a/modules/farm/farm_log/farm_log_movement/farm_log_movement.module b/modules/farm/farm_log/farm_log_movement/farm_log_movement.module index 3265a12bd..88117d5e0 100644 --- a/modules/farm/farm_log/farm_log_movement/farm_log_movement.module +++ b/modules/farm/farm_log/farm_log_movement/farm_log_movement.module @@ -11,25 +11,23 @@ include_once 'farm_log_movement.features.inc'; include_once 'farm_log_movement.location.inc'; /** - * Implements hook_farm_ui_taxonomy_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_log_movement_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); - } +function farm_log_movement_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Areas. - return array( + if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { // Area asset history (at the bottom). - array( + $views[] = array( 'name' => 'farm_area_assets', 'weight' => 100, 'always' => TRUE, - ), - ); + ); + } + + return $views; } /** diff --git a/modules/farm/farm_log/farm_log_observation/farm_log_observation.module b/modules/farm/farm_log/farm_log_observation/farm_log_observation.module index 154e4d221..8e6a7bb48 100644 --- a/modules/farm/farm_log/farm_log_observation/farm_log_observation.module +++ b/modules/farm/farm_log/farm_log_observation/farm_log_observation.module @@ -25,22 +25,18 @@ function farm_log_observation_farm_ui_entities() { } /** - * Implements hook_farm_ui_taxonomy_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_log_observation_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); - } +function farm_log_observation_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Areas. - return array( - - // Observations in this area. - array( + if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( 'name' => 'farm_log_observation', 'arg' => 2, - ), - ); + ); + } + + return $views; } diff --git a/modules/farm/farm_sensor/farm_sensor.module b/modules/farm/farm_sensor/farm_sensor.module index 23610dc26..c2ec79b36 100644 --- a/modules/farm/farm_sensor/farm_sensor.module +++ b/modules/farm/farm_sensor/farm_sensor.module @@ -22,40 +22,27 @@ function farm_sensor_farm_ui_entities() { } /** - * Implements hook_farm_ui_asset_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_sensor_farm_ui_asset_views($farm_asset) { - - // If the entity is not sensor, bail. - if ($farm_asset->type != 'sensor') { - return array(); - } +function farm_sensor_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Sensors. - return array( - array( + if ($entity_type == 'farm_asset' && $bundle == 'sensor') { + $views[] = array( 'name' => 'farm_log_movement', 'weight' => 100, - ), - ); -} - -/** - * Implements hook_farm_ui_taxonomy_views(). - */ -function farm_sensor_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); + ); } - // Return a list of Views to include on Areas. - return array( - array( + // Show sensors in area pages. + elseif ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( 'name' => 'farm_sensors', - ), - ); + ); + } + + return $views; } /** diff --git a/modules/farm/farm_sensor/farm_sensor_listener/farm_sensor_listener.module b/modules/farm/farm_sensor/farm_sensor_listener/farm_sensor_listener.module index 637f755a6..03318b31d 100644 --- a/modules/farm/farm_sensor/farm_sensor_listener/farm_sensor_listener.module +++ b/modules/farm/farm_sensor/farm_sensor_listener/farm_sensor_listener.module @@ -524,22 +524,16 @@ function farm_sensor_listener_load($key) { } /** - * Implements hook_farm_ui_asset_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_sensor_listener_farm_ui_asset_views($farm_asset) { +function farm_sensor_listener_farm_ui_entity_views($entity_type, $bundle, $entity) { - // If the entity is not a sensor, bail. - if ($farm_asset->type != 'sensor') { - return array(); + // Show sensor data View on listener sensors. + $views = array(); + if ($entity_type == 'farm_asset' && $bundle == 'sensor' && $entity->sensor_type == 'listener') { + $views[] = array( + 'farm_sensor_data', + ); } - - // If the sensor is not a listener, bail. - if ($farm_asset->sensor_type != 'listener') { - return array(); - } - - // Return a list of Views to include on listener sensors. - return array( - 'farm_sensor_data', - ); + return $views; } diff --git a/modules/farm/farm_soil/farm_soil_compost/farm_soil_compost.module b/modules/farm/farm_soil/farm_soil_compost/farm_soil_compost.module index 3a25f77b2..21ca5a782 100644 --- a/modules/farm/farm_soil/farm_soil_compost/farm_soil_compost.module +++ b/modules/farm/farm_soil/farm_soil_compost/farm_soil_compost.module @@ -22,46 +22,33 @@ function farm_soil_compost_farm_ui_entities() { } /** - * Implements hook_farm_ui_asset_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_soil_compost_farm_ui_asset_views($farm_asset) { - - // If the entity is not a compost bail. - if ($farm_asset->type != 'compost') { - return array(); - } +function farm_soil_compost_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Compost assets. - return array( - array( + if ($entity_type == 'farm_asset' && $bundle == 'compost') { + $views[] = array( 'name' => 'farm_log_movement', 'weight' => 100, - ), - array( + ); + $views[] = array( 'name' => 'farm_asset_children', 'display' => 'page', 'title' => t('Children'), 'weight' => 110, - ), - ); -} - -/** - * Implements hook_farm_ui_taxonomy_views(). - */ -function farm_soil_compost_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); + ); } - // Return a list of Views to include on Areas. - return array( - array( + // Show compost in area pages. + elseif ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( 'name' => 'farm_compost', - ), - ); + ); + } + + return $views; } /** diff --git a/modules/farm/farm_soil/farm_soil_test/farm_soil_test.module b/modules/farm/farm_soil/farm_soil_test/farm_soil_test.module index ad52a53eb..016b65c7b 100644 --- a/modules/farm/farm_soil/farm_soil_test/farm_soil_test.module +++ b/modules/farm/farm_soil/farm_soil_test/farm_soil_test.module @@ -24,17 +24,17 @@ function farm_soil_test_farm_ui_entities() { } /** - * Implements hook_farm_ui_taxonomy_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_soil_test_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); - } +function farm_soil_test_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Areas. - return array( - 'farm_log_soil_tests', - ); + if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( + 'name' => 'farm_log_soil_tests', + ); + } + + return $views; } diff --git a/modules/farm/farm_ui/farm_ui.api.php b/modules/farm/farm_ui/farm_ui.api.php index c28a829f4..b1d141095 100644 --- a/modules/farm/farm_ui/farm_ui.api.php +++ b/modules/farm/farm_ui/farm_ui.api.php @@ -85,7 +85,7 @@ function hook_farm_ui_entities() { // View absolutely needs to be at the very top or the very bottom of // the list. /** - * @see hook_farm_ui_asset_views() and hook_farm_ui_taxonomy_views() + * @see hook_farm_ui_entity_views() */ 'weight' => 10, ), @@ -115,18 +115,32 @@ function hook_farm_ui_entities() { } /** - * Attach Views to asset view pages. + * Attach Views to an entity page. * - * @param FarmAsset $farm_asset - * The farm asset entity. + * @param $entity_type + * The entity type. Currently supports: 'farm_asset' or 'taxonomy_term'. + * @param $bundle + * The entity bundle. + * @param $entity + * The loaded entity object. * * @return array - * Returns an array of View names to attach to farm asset pages. + * Returns an array of View to attach to taxonomy term pages. + * Each element in the array can either be the name of a View, + * or an array of options, including: + * 'name' - the machine name of the View + * 'display' - which display of the View should be used + * 'arg' - which argument the term id should be passed to in the View + * (this is useful if the View has more than one contextual filter) + * 'weight' - the weight of the View in the taxonomy page + * (this is useful for changing the order of Views) + * 'always' - always display, even if there are no View results + * (default is FALSE) */ -function hook_farm_ui_asset_views(FarmAsset $farm_asset) { +function hook_farm_ui_entity_views($entity_type, $bundle, $entity) { - // If the entity is not a planting, bail. - if ($farm_asset->type != 'planting') { + // If the entity is not a planting asset, bail. + if (!($entity_type == 'farm_asset' && $bundle == 'planting')) { return array(); } @@ -138,48 +152,6 @@ function hook_farm_ui_asset_views(FarmAsset $farm_asset) { // Example 2: explicitly set details like display, argument position, // and weight. - array( - 'name' => 'farm_log_input', - 'display' => 'block', - 'arg' => 2, - 'weight' => 10, - ), - ); -} - -/** - * Attach Views to taxonomy term pages. - * - * @param object $term - * The taxonomy term entity. - * - * @return array - * Returns an array of View to attach to taxonomy term pages. - * Each element in the array can either be the name of a View, - * or an array of options, including: - * 'name' - the machine name of the View - * 'display' - which display of the View should be used - * 'arg' - which argument the term id should be passed to in the View - * (this is useful if the View has more than one contextual filter) - * 'weight' - the weight of the View in the taxonomy page - * (this is useful for changing the order of Views) - * 'always' - always display, even if there are no View results - * (default is FALSE) - */ -function hook_farm_ui_taxonomy_views($term) { - - // If the term is not a crop, bail. - if ($term->vocabulary_machine_name != 'farm_crops') { - return array(); - } - - // Return a list of Views to include on Crops. - return array( - - // Example 1: simple View machine name. - 'farm_planting', - - // Example 2: explicitly set details like display, argument position, weight. array( 'name' => 'farm_log_input', 'display' => 'block', diff --git a/modules/farm/farm_ui/farm_ui.module b/modules/farm/farm_ui/farm_ui.module index 5d8d9cd4b..84f719e55 100644 --- a/modules/farm/farm_ui/farm_ui.module +++ b/modules/farm/farm_ui/farm_ui.module @@ -50,7 +50,7 @@ function farm_ui_entity_view($entity, $type, $view_mode, $langcode) { drupal_set_breadcrumb($breadcrumb); // Add Views to the entity. - $views = farm_ui_entity_views($type, $entity); + $views = farm_ui_entity_views($type, $bundle, $entity); if (!empty($views)) { $entity->content['views'] = $views; $entity->content['views']['#weight'] = 100; @@ -62,13 +62,15 @@ function farm_ui_entity_view($entity, $type, $view_mode, $langcode) { * * @param $entity_type * The entity type. Currently supports: 'farm_asset' or 'taxonomy_term'. + * @param $entity_bundle + * The entity bundle. * @param $entity * The loaded entity object. * * @return array * Returns a render array of Views to add to the entity page. */ -function farm_ui_entity_views($entity_type, $entity) { +function farm_ui_entity_views($entity_type, $entity_bundle, $entity) { // Start an empty build array. $build = array(); @@ -101,15 +103,8 @@ function farm_ui_entity_views($entity_type, $entity) { } } - // Ask modules for Views, based on the type. - switch ($entity_type) { - case 'farm_asset': - $module_views = module_invoke_all('farm_ui_asset_views', $entity); - break; - case 'taxonomy_term': - $module_views = module_invoke_all('farm_ui_taxonomy_views', $entity); - break; - } + // Ask modules for Views. + $module_views = module_invoke_all('farm_ui_entity_views', $entity_type, $entity_bundle, $entity); if (!empty($module_views)) { $views = array_merge($views, $module_views); } diff --git a/modules/farm/farm_water/farm_water_test/farm_water_test.module b/modules/farm/farm_water/farm_water_test/farm_water_test.module index d849153e5..ebbf0c964 100644 --- a/modules/farm/farm_water/farm_water_test/farm_water_test.module +++ b/modules/farm/farm_water/farm_water_test/farm_water_test.module @@ -24,17 +24,17 @@ function farm_water_test_farm_ui_entities() { } /** - * Implements hook_farm_ui_taxonomy_views(). + * Implements hook_farm_ui_entity_views(). */ -function farm_water_test_farm_ui_taxonomy_views($term) { - - // If the term is not an area, bail. - if ($term->vocabulary_machine_name != 'farm_areas') { - return array(); - } +function farm_water_test_farm_ui_entity_views($entity_type, $bundle, $entity) { + $views = array(); // Return a list of Views to include on Areas. - return array( - 'farm_water_test', - ); + if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') { + $views[] = array( + 'name' => 'farm_water_test', + ); + } + + return $views; }