Merge hook_farm_ui_asset_views() and hook_farm_ui_taxonomy_views().
This commit is contained in:
parent
d644e54b6d
commit
3f16718b4a
|
@ -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) {
|
function farm_crop_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// If the entity is not a planting, bail.
|
|
||||||
if ($farm_asset->type != 'planting') {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a list of Views to include on Plantings.
|
// Return a list of Views to include on Plantings.
|
||||||
return array(
|
if ($entity_type == 'farm_asset' && $bundle == 'planting') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_movement',
|
'name' => 'farm_log_movement',
|
||||||
'weight' => 100,
|
'weight' => 100,
|
||||||
),
|
);
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_asset_children',
|
'name' => 'farm_asset_children',
|
||||||
'display' => 'page',
|
'display' => 'page',
|
||||||
'title' => t('Children'),
|
'title' => t('Children'),
|
||||||
'weight' => 110,
|
'weight' => 110,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// If the entity is a taxonomy_term...
|
||||||
* Implements hook_farm_ui_taxonomy_views().
|
elseif ($entity_type == 'taxonomy_term') {
|
||||||
*/
|
switch ($entity->vocabulary_machine_name) {
|
||||||
function farm_crop_farm_ui_taxonomy_views($term) {
|
|
||||||
|
|
||||||
// Start a list of View names.
|
// Farm areas:
|
||||||
$views = array();
|
case 'farm_areas':
|
||||||
|
$views[] = array(
|
||||||
|
'name' => 'farm_plantings',
|
||||||
|
'weight' => -20,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
// Switch logic depending on the vocabulary.
|
// Farm crops.
|
||||||
switch ($term->vocabulary_machine_name) {
|
case 'farm_crops':
|
||||||
|
$views[] = array(
|
||||||
|
'name' => 'farm_plantings',
|
||||||
|
'arg' => 2,
|
||||||
|
'always' => TRUE,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
// Farm areas:
|
// Farm crop family.
|
||||||
case 'farm_areas':
|
case 'farm_crop_families':
|
||||||
$views[] = array(
|
$views[] = 'farm_crops';
|
||||||
'name' => 'farm_plantings',
|
break;
|
||||||
'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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $views;
|
return $views;
|
||||||
|
|
|
@ -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) {
|
function farm_equipment_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// If the entity is not equipment, bail.
|
|
||||||
if ($farm_asset->type != 'equipment') {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a list of Views to include on Equipment.
|
// Return a list of Views to include on Equipment.
|
||||||
return array(
|
if ($entity_type == 'farm_asset' && $bundle == 'equipment') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_movement',
|
'name' => 'farm_log_movement',
|
||||||
'weight' => 100,
|
'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.
|
// Show equipment in area pages.
|
||||||
return array(
|
elseif ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_equipment',
|
'name' => 'farm_equipment',
|
||||||
'weight' => -10,
|
'weight' => -10,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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) {
|
function farm_livestock_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// If the entity is not an animal, bail.
|
|
||||||
if ($farm_asset->type != 'animal') {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a list of Views to include on Animals.
|
// Return a list of Views to include on Animals.
|
||||||
return array(
|
if ($entity_type == 'farm_asset' && $bundle == 'animal') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_movement',
|
'name' => 'farm_log_movement',
|
||||||
'weight' => 100,
|
'weight' => 100,
|
||||||
),
|
);
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_asset_children',
|
'name' => 'farm_asset_children',
|
||||||
'display' => 'page',
|
'display' => 'page',
|
||||||
'title' => t('Children'),
|
'title' => t('Children'),
|
||||||
'weight' => 110,
|
'weight' => 110,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// If the entity is a taxonomy_term...
|
||||||
* Implements hook_farm_ui_taxonomy_views().
|
elseif ($entity_type == 'taxonomy_term') {
|
||||||
*/
|
switch ($entity->vocabulary_machine_name) {
|
||||||
function farm_livestock_farm_ui_taxonomy_views($term) {
|
|
||||||
|
|
||||||
// Start a list of View names.
|
// Farm areas:
|
||||||
$views = array();
|
case 'farm_areas':
|
||||||
|
$views[] = array(
|
||||||
|
'name' => 'farm_animals',
|
||||||
|
'weight' => -10,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
// Switch logic depending on the vocabulary.
|
// Farm animal groups:
|
||||||
switch ($term->vocabulary_machine_name) {
|
case 'farm_animal_groups':
|
||||||
|
$views[] = array(
|
||||||
|
'name' => 'farm_animals',
|
||||||
|
'arg' => 2,
|
||||||
|
'always' => TRUE,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
// Farm areas:
|
// Farm animal types:
|
||||||
case 'farm_areas':
|
case 'farm_animal_types':
|
||||||
$views[] = array(
|
$views[] = array(
|
||||||
'name' => 'farm_animals',
|
'name' => 'farm_animals',
|
||||||
'weight' => -10,
|
'arg' => 3,
|
||||||
);
|
'always' => TRUE,
|
||||||
break;
|
);
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $views;
|
return $views;
|
||||||
|
|
|
@ -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) {
|
function farm_log_activity_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// 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 a list of Views to include on Areas.
|
||||||
return array(
|
if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_activity',
|
'name' => 'farm_log_activity',
|
||||||
'arg' => 2,
|
'arg' => 2,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
function farm_log_input_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// 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 a list of Views to include on Areas.
|
||||||
return array(
|
if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_input',
|
'name' => 'farm_log_input',
|
||||||
'arg' => 2,
|
'arg' => 2,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,25 +11,23 @@ include_once 'farm_log_movement.features.inc';
|
||||||
include_once 'farm_log_movement.location.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) {
|
function farm_log_movement_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// 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 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).
|
// Area asset history (at the bottom).
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_area_assets',
|
'name' => 'farm_area_assets',
|
||||||
'weight' => 100,
|
'weight' => 100,
|
||||||
'always' => TRUE,
|
'always' => TRUE,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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) {
|
function farm_log_observation_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// 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 a list of Views to include on Areas.
|
||||||
return array(
|
if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
|
$views[] = array(
|
||||||
// Observations in this area.
|
|
||||||
array(
|
|
||||||
'name' => 'farm_log_observation',
|
'name' => 'farm_log_observation',
|
||||||
'arg' => 2,
|
'arg' => 2,
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
function farm_sensor_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// If the entity is not sensor, bail.
|
|
||||||
if ($farm_asset->type != 'sensor') {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a list of Views to include on Sensors.
|
// Return a list of Views to include on Sensors.
|
||||||
return array(
|
if ($entity_type == 'farm_asset' && $bundle == 'sensor') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_movement',
|
'name' => 'farm_log_movement',
|
||||||
'weight' => 100,
|
'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.
|
// Show sensors in area pages.
|
||||||
return array(
|
elseif ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_sensors',
|
'name' => 'farm_sensors',
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.
|
// Show sensor data View on listener sensors.
|
||||||
if ($farm_asset->type != 'sensor') {
|
$views = array();
|
||||||
return array();
|
if ($entity_type == 'farm_asset' && $bundle == 'sensor' && $entity->sensor_type == 'listener') {
|
||||||
|
$views[] = array(
|
||||||
|
'farm_sensor_data',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
return $views;
|
||||||
// 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',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
function farm_soil_compost_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// If the entity is not a compost bail.
|
|
||||||
if ($farm_asset->type != 'compost') {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a list of Views to include on Compost assets.
|
// Return a list of Views to include on Compost assets.
|
||||||
return array(
|
if ($entity_type == 'farm_asset' && $bundle == 'compost') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_log_movement',
|
'name' => 'farm_log_movement',
|
||||||
'weight' => 100,
|
'weight' => 100,
|
||||||
),
|
);
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_asset_children',
|
'name' => 'farm_asset_children',
|
||||||
'display' => 'page',
|
'display' => 'page',
|
||||||
'title' => t('Children'),
|
'title' => t('Children'),
|
||||||
'weight' => 110,
|
'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.
|
// Show compost in area pages.
|
||||||
return array(
|
elseif ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
array(
|
$views[] = array(
|
||||||
'name' => 'farm_compost',
|
'name' => 'farm_compost',
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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) {
|
function farm_soil_test_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// 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 a list of Views to include on Areas.
|
||||||
return array(
|
if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
'farm_log_soil_tests',
|
$views[] = array(
|
||||||
);
|
'name' => 'farm_log_soil_tests',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ function hook_farm_ui_entities() {
|
||||||
// View absolutely needs to be at the very top or the very bottom of
|
// View absolutely needs to be at the very top or the very bottom of
|
||||||
// the list.
|
// the list.
|
||||||
/**
|
/**
|
||||||
* @see hook_farm_ui_asset_views() and hook_farm_ui_taxonomy_views()
|
* @see hook_farm_ui_entity_views()
|
||||||
*/
|
*/
|
||||||
'weight' => 10,
|
'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
|
* @param $entity_type
|
||||||
* The farm asset entity.
|
* The entity type. Currently supports: 'farm_asset' or 'taxonomy_term'.
|
||||||
|
* @param $bundle
|
||||||
|
* The entity bundle.
|
||||||
|
* @param $entity
|
||||||
|
* The loaded entity object.
|
||||||
*
|
*
|
||||||
* @return array
|
* @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 the entity is not a planting asset, bail.
|
||||||
if ($farm_asset->type != 'planting') {
|
if (!($entity_type == 'farm_asset' && $bundle == 'planting')) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,48 +152,6 @@ function hook_farm_ui_asset_views(FarmAsset $farm_asset) {
|
||||||
|
|
||||||
// Example 2: explicitly set details like display, argument position,
|
// Example 2: explicitly set details like display, argument position,
|
||||||
// and weight.
|
// 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(
|
array(
|
||||||
'name' => 'farm_log_input',
|
'name' => 'farm_log_input',
|
||||||
'display' => 'block',
|
'display' => 'block',
|
||||||
|
|
|
@ -50,7 +50,7 @@ function farm_ui_entity_view($entity, $type, $view_mode, $langcode) {
|
||||||
drupal_set_breadcrumb($breadcrumb);
|
drupal_set_breadcrumb($breadcrumb);
|
||||||
|
|
||||||
// Add Views to the entity.
|
// Add Views to the entity.
|
||||||
$views = farm_ui_entity_views($type, $entity);
|
$views = farm_ui_entity_views($type, $bundle, $entity);
|
||||||
if (!empty($views)) {
|
if (!empty($views)) {
|
||||||
$entity->content['views'] = $views;
|
$entity->content['views'] = $views;
|
||||||
$entity->content['views']['#weight'] = 100;
|
$entity->content['views']['#weight'] = 100;
|
||||||
|
@ -62,13 +62,15 @@ function farm_ui_entity_view($entity, $type, $view_mode, $langcode) {
|
||||||
*
|
*
|
||||||
* @param $entity_type
|
* @param $entity_type
|
||||||
* The entity type. Currently supports: 'farm_asset' or 'taxonomy_term'.
|
* The entity type. Currently supports: 'farm_asset' or 'taxonomy_term'.
|
||||||
|
* @param $entity_bundle
|
||||||
|
* The entity bundle.
|
||||||
* @param $entity
|
* @param $entity
|
||||||
* The loaded entity object.
|
* The loaded entity object.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* Returns a render array of Views to add to the entity page.
|
* 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.
|
// Start an empty build array.
|
||||||
$build = array();
|
$build = array();
|
||||||
|
@ -101,15 +103,8 @@ function farm_ui_entity_views($entity_type, $entity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask modules for Views, based on the type.
|
// Ask modules for Views.
|
||||||
switch ($entity_type) {
|
$module_views = module_invoke_all('farm_ui_entity_views', $entity_type, $entity_bundle, $entity);
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (!empty($module_views)) {
|
if (!empty($module_views)) {
|
||||||
$views = array_merge($views, $module_views);
|
$views = array_merge($views, $module_views);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
function farm_water_test_farm_ui_entity_views($entity_type, $bundle, $entity) {
|
||||||
|
$views = array();
|
||||||
// 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 a list of Views to include on Areas.
|
||||||
return array(
|
if ($entity_type == 'taxonomy_term' && $entity->vocabulary_machine_name == 'farm_areas') {
|
||||||
'farm_water_test',
|
$views[] = array(
|
||||||
);
|
'name' => 'farm_water_test',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $views;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue