View source
<?php
include_once 'farm_crop.features.inc';
function farm_crop_help($path, $arg) {
if ($path == 'farm/assets/plantings') {
return t('Plantings can be used to represent groups of plants (eg: a field of corn, or a group of seedlings), or they can be used to represent individual plants (eg: in the case of nurseries). For more information, see the <a href="@plantings_doc_url">Plantings</a> documentation.', array(
'@plantings_doc_url' => url('https://farmOS.org/guide/assets/plantings'),
));
}
elseif ($path == 'farm/logs/seedings') {
return t('Seeding logs represent when <a href="@plantings_url">Planting assets</a> are seeded directly into the ground (or into containers). For more information, see the <a href="@plantings_doc_url">Plantings</a> documentation.', array(
'@plantings_url' => url('farm/assets/plantings'),
'@plantings_doc_url' => url('https://farmOS.org/guide/assets/plantings'),
));
}
elseif ($path == 'farm/logs/transplantings') {
return t('Transplanting logs represent when <a href="@plantings_url">Planting assets</a> are transplanted from one place to another. For more information, see the <a href="@plantings_doc_url">Plantings</a> documentation.', array(
'@plantings_url' => url('farm/assets/plantings'),
'@plantings_doc_url' => url('https://farmOS.org/guide/assets/plantings'),
));
}
}
function farm_crop_form_farm_asset_form_alter(&$form, &$form_state, $form_id) {
$asset = $form['farm_asset']['#value'];
if (empty($asset->type) || $asset->type != 'planting') {
return;
}
if (!empty($form['farm_asset']['#value']->is_new)) {
drupal_set_message(t('Tip: Use the <a href="@path">Planting Quick Form</a> to quickly record a planting and create seedings and other logs associated with it in one step.', array(
'@path' => url('farm/quick/planting'),
)));
}
}
function farm_crop_farm_ui_entities() {
return array(
'farm_asset' => array(
'planting' => array(
'label' => t('Planting'),
'label_plural' => t('Plantings'),
'view' => 'farm_plantings',
),
),
'log' => array(
'farm_seeding' => array(
'label' => t('Seeding'),
'label_plural' => t('Seedings'),
'view' => 'farm_log_seeding',
'farm_asset' => 'planting',
'areas' => TRUE,
'weight' => -90,
),
'farm_transplanting' => array(
'label' => t('Transplanting'),
'label_plural' => t('Transplantings'),
'view' => 'farm_log_transplanting',
'farm_asset' => 'planting',
'areas' => TRUE,
'weight' => -80,
),
),
'taxonomy_term' => array(
'farm_crops' => array(
'label' => t('Crop/variety'),
'label_plural' => t('Crops/varieties'),
'view' => 'farm_crops',
'farm_asset' => 'planting',
'asset_view_arg' => 2,
),
'farm_crop_families' => array(
'label' => t('Crop Family'),
'label_plural' => t('Crop Families'),
),
),
);
}
function farm_crop_farm_ui_entity_views($entity_type, $bundle, $entity) {
$views = array();
if ($entity_type == 'taxonomy_term') {
switch ($entity->vocabulary_machine_name) {
case 'farm_crop_families':
$views[] = 'farm_crops';
break;
}
}
return $views;
}
function farm_crop_farm_log_categories() {
return array(
'Plantings',
);
}
function farm_crop_farm_log_categories_populate($log) {
$categories = array();
if (in_array($log->type, array(
'farm_seeding',
'farm_transplanting',
))) {
$categories[] = 'Plantings';
}
return $categories;
}
function farm_crop_feeds_importer_default_alter(&$importers) {
$name = 'farm_asset_planting';
if (!empty($importers[$name])) {
$mappings = array(
array(
'source' => 'Crop/variety',
'target' => 'field_farm_crop',
'term_search' => '0',
'autocreate' => 1,
'language' => 'und',
),
array(
'source' => 'Season',
'target' => 'field_farm_season',
'term_search' => '0',
'autocreate' => 1,
'language' => 'und',
),
);
$importer_mappings =& $importers[$name]->config['processor']['config']['mappings'];
$importer_mappings = array_merge($importer_mappings, $mappings);
}
$name = 'log_farm_seeding';
if (!empty($importers[$name])) {
$mappings = array(
array(
'source' => 'Source/supplier',
'target' => 'field_farm_seed_source',
'unique' => FALSE,
'language' => 'und',
),
);
$importer_mappings =& $importers[$name]->config['processor']['config']['mappings'];
$importer_mappings = array_merge($importer_mappings, $mappings);
}
}
function farm_crop_feeds_tamper_default_alter(&$feeds_tampers) {
if (!module_exists('farm_import')) {
return;
}
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'animal', 'Crop/variety', 'required');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'planting', 'Crop/variety', 'explode');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
$feeds_tamper = farm_import_feeds_tamper_plugin('farm_asset', 'planting', 'Crop/variety', 'trim');
$feeds_tampers[$feeds_tamper->id] = $feeds_tamper;
}
function farm_crop_families() {
$families = array();
$vocabulary = taxonomy_vocabulary_machine_name_load('farm_crop_families');
if (empty($vocabulary) || !isset($vocabulary->vid)) {
return $families;
}
return taxonomy_get_tree($vocabulary->vid);
}
function farm_crop_family_crops($crop_family_tids = FALSE) {
$crops = array();
if ($crop_family_tids != FALSE) {
if (!is_array($crop_family_tids)) {
$crop_family_tids = array(
$crop_family_tids,
);
}
}
$farm_crops = taxonomy_vocabulary_machine_name_load('farm_crops');
if (empty($farm_crops) || !isset($farm_crops->vid)) {
return $crops;
}
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('vid', $farm_crops->vid)
->fieldOrderBy('field_farm_crop_family', 'tid');
if (is_array($crop_family_tids)) {
$query
->fieldCondition('field_farm_crop_family', 'tid', $crop_family_tids, 'IN');
}
$results = $query
->execute();
if (!empty($results['taxonomy_term'])) {
$term_ids = array_keys($results['taxonomy_term']);
$crops = taxonomy_term_load_multiple($term_ids);
}
return $crops;
}