Issue #2893550: Use Entityreference View Widget for referencing areas

This commit is contained in:
Michael Stenta 2017-07-11 09:40:16 -04:00
commit 60259c2ae0
17 changed files with 505 additions and 258 deletions

View File

@ -4,6 +4,7 @@ core = 7.x
package = farmOS
dependencies[] = colorbox
dependencies[] = ctools
dependencies[] = entityreference_view_widget
dependencies[] = farm_fields
dependencies[] = farm_map
dependencies[] = features
@ -45,6 +46,7 @@ features[openlayers_components][] = farm_area_component_areas_zoom_to_source
features[openlayers_maps][] = farm_areas
features[taxonomy][] = farm_areas
features[variable][] = pathauto_taxonomy_term_farm_areas_pattern
features[views_view][] = farm_area_entityreference_view
features[views_view][] = farm_areas
features[views_view][] = farm_areas_geojson
files[] = views/handlers/farm_area_handler_field_details.inc

View File

@ -10,6 +10,133 @@
function farm_area_views_default_views() {
$export = array();
$view = new view();
$view->name = 'farm_area_entityreference_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'Farm Area Entityreference View';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'view farm areas';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Header: Global: Unfiltered text */
$handler->display->display_options['header']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['header']['area_text_custom']['table'] = 'views';
$handler->display->display_options['header']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['header']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['header']['area_text_custom']['content'] = 'Select the area(s) you would like to reference and click "Submit". Use the filters to narrow down the list.';
/* No results behavior: Global: Unfiltered text */
$handler->display->display_options['empty']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['empty']['area_text_custom']['table'] = 'views';
$handler->display->display_options['empty']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['empty']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['empty']['area_text_custom']['content'] = 'No assets found.';
/* Relationship: Taxonomy term: Parent term */
$handler->display->display_options['relationships']['parent']['id'] = 'parent';
$handler->display->display_options['relationships']['parent']['table'] = 'taxonomy_term_hierarchy';
$handler->display->display_options['relationships']['parent']['field'] = 'parent';
/* Field: Taxonomy term: Term ID */
$handler->display->display_options['fields']['tid']['id'] = 'tid';
$handler->display->display_options['fields']['tid']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['tid']['field'] = 'tid';
$handler->display->display_options['fields']['tid']['exclude'] = TRUE;
/* Field: Taxonomy term: Term ID */
$handler->display->display_options['fields']['tid_1']['id'] = 'tid_1';
$handler->display->display_options['fields']['tid_1']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['tid_1']['field'] = 'tid';
$handler->display->display_options['fields']['tid_1']['relationship'] = 'parent';
$handler->display->display_options['fields']['tid_1']['exclude'] = TRUE;
/* Field: Entity Reference View Widget Checkbox: Taxonomy term */
$handler->display->display_options['fields']['entityreference_view_widget']['id'] = 'entityreference_view_widget';
$handler->display->display_options['fields']['entityreference_view_widget']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['entityreference_view_widget']['field'] = 'entityreference_view_widget';
$handler->display->display_options['fields']['entityreference_view_widget']['label'] = '';
$handler->display->display_options['fields']['entityreference_view_widget']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['entityreference_view_widget']['ervw']['force_single'] = 0;
$handler->display->display_options['fields']['entityreference_view_widget']['ervw']['label_display'] = 'after';
/* Sort criterion: Taxonomy term: Weight */
$handler->display->display_options['sorts']['weight']['id'] = 'weight';
$handler->display->display_options['sorts']['weight']['table'] = 'taxonomy_term_data';
$handler->display->display_options['sorts']['weight']['field'] = 'weight';
/* Sort criterion: Taxonomy term: Name */
$handler->display->display_options['sorts']['name']['id'] = 'name';
$handler->display->display_options['sorts']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['sorts']['name']['field'] = 'name';
/* Contextual filter: Taxonomy term: Term ID */
$handler->display->display_options['arguments']['tid']['id'] = 'tid';
$handler->display->display_options['arguments']['tid']['table'] = 'taxonomy_term_data';
$handler->display->display_options['arguments']['tid']['field'] = 'tid';
$handler->display->display_options['arguments']['tid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['tid']['not'] = TRUE;
/* Filter criterion: Taxonomy vocabulary: Machine name */
$handler->display->display_options['filters']['machine_name']['id'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['filters']['machine_name']['field'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['value'] = array(
'farm_areas' => 'farm_areas',
);
/* Filter criterion: Taxonomy term: Name */
$handler->display->display_options['filters']['name']['id'] = 'name';
$handler->display->display_options['filters']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['filters']['name']['field'] = 'name';
$handler->display->display_options['filters']['name']['operator'] = 'contains';
$handler->display->display_options['filters']['name']['exposed'] = TRUE;
$handler->display->display_options['filters']['name']['expose']['operator_id'] = 'name_op';
$handler->display->display_options['filters']['name']['expose']['label'] = 'Search';
$handler->display->display_options['filters']['name']['expose']['operator'] = 'name_op';
$handler->display->display_options['filters']['name']['expose']['identifier'] = 'name';
/* Display: Entity Reference View Widget */
$handler = $view->new_display('entityreference_view_widget', 'Entity Reference View Widget', 'entityreference_view_widget');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Select areas';
$handler->display->display_options['defaults']['use_ajax'] = FALSE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'tree';
$handler->display->display_options['style_options']['main_field'] = 'tid';
$handler->display->display_options['style_options']['parent_field'] = 'tid_1';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$translatables['farm_area_entityreference_view'] = array(
t('Master'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Select the area(s) you would like to reference and click "Submit". Use the filters to narrow down the list.'),
t('No assets found.'),
t('Parent'),
t('Term ID'),
t('.'),
t(','),
t('All'),
t('Search'),
t('Entity Reference View Widget'),
t('Select areas'),
);
$export['farm_area_entityreference_view'] = $view;
$view = new view();
$view->name = 'farm_areas';
$view->description = '';
@ -91,6 +218,10 @@ function farm_area_views_default_views() {
$handler->display->display_options['sorts']['weight']['id'] = 'weight';
$handler->display->display_options['sorts']['weight']['table'] = 'taxonomy_term_data';
$handler->display->display_options['sorts']['weight']['field'] = 'weight';
/* Sort criterion: Taxonomy term: Name */
$handler->display->display_options['sorts']['name']['id'] = 'name';
$handler->display->display_options['sorts']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['sorts']['name']['field'] = 'name';
/* Filter criterion: Taxonomy vocabulary: Machine name */
$handler->display->display_options['filters']['machine_name']['id'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['table'] = 'taxonomy_vocabulary';

View File

@ -630,43 +630,3 @@ function farm_asset_type_get_names() {
}
return $names;
}
/**
* Helper function for retrieving a list of assets from the ?farm_asset URL
* query parameter.
*
* @return array
* Returns the asset objects in an array.
*/
function farm_asset_load_assets_from_url() {
// Initialize an empty array.
$assets = array();
// If the "farm_asset" GET parameter isn't set, bail.
$params = drupal_get_query_parameters();
if (empty($params['farm_asset'])) {
return $assets;
}
// If only a single asset id is passed, convert it to an array.
if (!is_array($params['farm_asset'])) {
$params['farm_asset'] = array($params['farm_asset']);
}
// Validate that all the asset IDs are valid by loading the assets themselves.
$assets = array();
foreach($params['farm_asset'] as $asset_id) {
// Attempt to load the asset.
$asset = farm_asset_load($asset_id);
// If it loaded, add it to the array.
if (!empty($asset)) {
$assets[] = $asset;
}
}
// Return the array of assets.
return $assets;
}

View File

@ -15,3 +15,137 @@ function farm_fields_farm_access_perms($role) {
return $perms;
}
/**
* Helper function for pre-populating entityreference fields in entity forms.
*
* @param array $form
* The entity form array to modify, passed by reference.
* @param string $entity_type
* The entity type that is being referenced.
* @param string $field_name
* The machine name of the entity reference field.
* @param array $entity_ids
* An array of entities to add to the references.
*/
function farm_fields_prepopulate_entityreference(&$form, $entity_type, $field_name, $entity_ids) {
// Load the field instance definition.
$form_entity_type = $form['#entity_type'];
$form_entity_bundle = $form['#bundle'];
$field_base = field_info_field($field_name);
$field_instance = field_info_instance($form_entity_type, $field_name, $form_entity_bundle);
// Set the field value key based on the field type.
$value_key = 'value';
switch ($field_base['type']) {
case 'entity_reference';
$value_key = 'target_id';
break;
case 'taxonomy_term_reference':
$value_key = 'tid';
break;
}
// Validate the entity IDs by loading them. Rebuild the list of IDs using
// only the entities that loaded.
$entities = entity_load($entity_type, $entity_ids);
$entity_ids = array();
foreach ($entities as $entity) {
$entity_ids[] = entity_id($entity_type, $entity);
}
// If there are no entity IDs, bail.
if (empty($entity_ids)) {
return;
}
// If the widget type is "radios/checkboxes" or "select list"...
if (in_array($field_instance['widget']['type'], array('options_buttons', 'options_select'))) {
// Use the array of IDs as the field's default value.
if (empty($form[$field_name][LANGUAGE_NONE]['#default_value'])) {
$form[$field_name][LANGUAGE_NONE]['#default_value'] = $entity_ids;
}
}
// If the widget type is "autocomplete" or "autocomplete tags"...
elseif (in_array($field_instance['widget']['type'], array('entityreference_autocomplete', 'entityreference_autocomplete_tags'))) {
// Build a list of entity labels in the format that the widget expects.
$labels = array();
foreach ($entities as $id => $entity) {
$labels[] = entity_label($entity_type, $entity) . ' (' . $id . ')';
}
// For "autocomplete", add each one as a separate field.
if ($field_instance['widget']['type'] == 'entityreference_autocomplete') {
foreach ($labels as $key => $label) {
// If the item isn't empty, skip it.
if (!empty($form[$field_name][LANGUAGE_NONE][$key][$value_key]['#default_value'])) {
continue;
}
/**
* @todo
* This seems to be the easiest way to auto-populate entityreference_autocomplete
* widgets, but it is MESSY! If anyone can figure out a better way, I will buy
* you a beer.
*/
// Copy the initial array structure from the first element.
$form[$field_name][LANGUAGE_NONE][$key] = $form[$field_name][LANGUAGE_NONE][0];
// Set the default, delta, and weight values.
$form[$field_name][LANGUAGE_NONE][$key][$value_key]['#default_value'] = $label;
$form[$field_name][LANGUAGE_NONE][$key][$value_key]['#delta'] = $key;
$form[$field_name][LANGUAGE_NONE][$key][$value_key]['#weight'] = $key;
// Only make the first one required.
if ($key > 0) {
$form[$field_name][LANGUAGE_NONE][$key][$value_key]['#required'] = 0;
}
$form[$field_name][LANGUAGE_NONE]['#max_delta'] = $key;
$form[$field_name][LANGUAGE_NONE][$key]['_weight']['#delta'] = $key;
$form[$field_name][LANGUAGE_NONE][$key]['_weight']['#default_value'] = $key;
}
}
// For "autocomplete tags", implode them all into one comma-separated list.
elseif ($field_instance['widget']['type'] == 'entityreference_autocomplete_tags') {
if (empty($form[$field_name][LANGUAGE_NONE]['#default_value'])) {
$form[$field_name][LANGUAGE_NONE]['#default_value'] = implode(', ', $labels);
}
}
}
// If the widget type is "entity reference view widget"...
elseif ($field_instance['widget']['type'] == 'entityreference_view_widget') {
// Add a set of checkbox form elements, as the entityreference_view_widget
// module expects...
foreach ($entities as $id => $entity) {
// If the item isn't empty, skip it.
$children = element_children($form[$field_name][LANGUAGE_NONE]);
foreach ($children as $child) {
if (!empty($form[$field_name][LANGUAGE_NONE][$child][$value_key]['#value'])) {
continue 2;
}
}
// Add the checkbox element.
$form[$field_name][LANGUAGE_NONE][$id][$value_key] = array(
'#type' => 'checkbox',
'#return_value' => $id,
'#value' => $id,
'#title_display' => 'after',
'#attributes' => array(
'checked' => 'checked',
),
'#title' => entity_label($entity_type, $entity),
);
}
}
}

View File

@ -12,23 +12,9 @@ include_once 'farm_log.features.inc';
*/
function farm_log_form_alter(&$form, &$form_state, $form_id) {
// If this is a log form...
// If this is a log form, attempt to prepopulate entityreference fields.
if ($form_id == 'log_form') {
// If there is an asset(s) reference field, try to prepopulate it.
if (!empty($form['field_farm_asset'])) {
farm_log_form_prepopulate_asset($form);
}
// If there is an area(s) reference field, try to prepopulate it.
if (!empty($form['field_farm_area'])) {
farm_log_form_prepopulate_area($form);
}
// If there is an owner reference field, try to prepopulate it.
if (!empty($form['field_farm_log_owner'])) {
farm_log_form_prepopulate_owner($form);
}
farm_log_prepopulate_log_form_references($form);
}
}
@ -149,187 +135,84 @@ function farm_log_populate_geometry($entity) {
}
/**
* Helper function for enabling asset prepopulation in log forms.
* Helper function for populating entity reference fields in log forms.
*
* @param array $form
* The form array to modify, passed by reference.
*
* @return array|bool
* Returns the asset objects in an array, if found, FALSE otherwise.
*/
function farm_log_form_prepopulate_asset(array &$form) {
function farm_log_prepopulate_log_form_references(&$form) {
// Load assets from the ?farm_asset query parameter.
$assets = farm_asset_load_assets_from_url();
// Define the fields we will be populating.
$fields = array(
'field_farm_asset' => array(
'entity_type' => 'farm_asset',
'url_param' => 'farm_asset',
),
'field_farm_area' => array(
'entity_type' => 'taxonomy_term',
'url_param' => 'farm_area',
),
'field_farm_log_owner' => array(
'entity_type' => 'user',
),
);
// If there are no assets, bail.
if (empty($assets)) {
return FALSE;
}
// Populate the fields.
foreach ($fields as $field => $info) {
// Load the field instance definition.
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$field_instance = field_info_instance($entity_type, 'field_farm_asset', $bundle);
// Start with an empty array of IDs.
$ids = array();
// If the widget type is "radios/checkboxes" or "select list"...
if (in_array($field_instance['widget']['type'], array('options_buttons', 'options_select'))) {
// Build a list of asset ID.
$asset_ids = array();
foreach ($assets as $asset) {
$asset_ids[] = $asset->id;
// If the field does not exist on the log, skip it.
if (!isset($form[$field])) {
continue;
}
// Use the array of asset IDs as the field's default value.
if (empty($form['field_farm_asset'][LANGUAGE_NONE]['#default_value'])) {
$form['field_farm_asset'][LANGUAGE_NONE]['#default_value'] = $asset_ids;
}
}
// If the widget type is "autocomplete" or "autocomplete tags"...
elseif (in_array($field_instance['widget']['type'], array('entityreference_autocomplete', 'entityreference_autocomplete_tags'))) {
// Build a list of asset labels in the format that the widget expects.
$asset_labels = array();
foreach ($assets as $asset) {
$asset_labels[] = entity_label('farm_asset', $asset) . ' (' . $asset->id . ')';
// If a URL param is available, get a list of entity IDs from it.
if (!empty($info['url_param'])) {
$ids = farm_log_ids_from_url($info['url_param']);
}
// For "autocomplete", add each one as a separate field.
if ($field_instance['widget']['type'] == 'entityreference_autocomplete') {
foreach ($asset_labels as $key => $label) {
// If the item isn't empty, skip it.
if (!empty($form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id']['#default_value'])) {
continue;
}
/**
* @todo
* This seems to be the easiest way to autopopulate entityreference_autocomplete
* widgets, but it is MESSY! If anyone can figure out a better way, I will buy
* you a beer.
*/
// Copy the initial array structure from the first element.
$form['field_farm_asset'][LANGUAGE_NONE][$key] = $form['field_farm_asset'][LANGUAGE_NONE][0];
// Set the default, delta, and weight values.
$form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id']['#default_value'] = $label;
$form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id']['#delta'] = $key;
$form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id']['#weight'] = $key;
// Only make the first one required.
if ($key > 0) {
$form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id']['#required'] = 0;
}
$form['field_farm_asset'][LANGUAGE_NONE]['#max_delta'] = $key;
$form['field_farm_asset'][LANGUAGE_NONE][$key]['_weight']['#delta'] = $key;
$form['field_farm_asset'][LANGUAGE_NONE][$key]['_weight']['#default_value'] = $key;
// Or, if the entity type is 'user', load the ID from the current user.
elseif ($info['entity_type'] == 'user') {
global $user;
if (!empty($user->uid)) {
$ids[] = $user->uid;
}
}
// For "autocomplete tags", implode them all into one comma-separated list.
elseif ($field_instance['widget']['type'] == 'entityreference_autocomplete_tags') {
if (empty($form['field_farm_asset'][LANGUAGE_NONE]['#default_value'])) {
$form['field_farm_asset'][LANGUAGE_NONE]['#default_value'] = implode(', ', $asset_labels);
}
// If there are no IDs, skip.
if (empty($ids)) {
continue;
}
// Prepopulate with the farm_fields helper function.
farm_fields_prepopulate_entityreference($form, $info['entity_type'], $field, $ids);
}
// If the widget type is "entity reference view widget"...
elseif ($field_instance['widget']['type'] == 'entityreference_view_widget') {
// Add a set of checkbox form elements, as the entityreference_view_widget
// module expects...
foreach ($assets as $key => $asset) {
// If the item isn't empty, skip it.
if (!empty($form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id'])) {
continue;
}
// Add the checkbox element.
$form['field_farm_asset'][LANGUAGE_NONE][$key]['target_id'] = array(
'#type' => 'checkbox',
'#return_value' => $asset->id,
'#value' => $asset->id,
'#title_display' => 'after',
'#attributes' => array(
'checked' => 'checked',
),
'#title' => entity_label('farm_asset', $asset),
);
}
}
return $assets;
}
/**
* Helper function for enabling area prepopulation in log forms.
* Helper function for retrieving a list of entity IDs from a URL query param.
*
* @param array $form
* The form array to modify, passed by reference.
* @param string $param
* The URL query param to look at.
*
* @return TaxonomyTerm term
* Returns the taxonomy term object, if found.
* @return array
* Returns an array of IDs.
*/
function farm_log_form_prepopulate_area(array &$form) {
$area = NULL;
function farm_log_ids_from_url($param) {
// Alias for the field's default value.
$field_value = &$form['field_farm_area'][LANGUAGE_NONE]['#default_value'];
// If the "farm_area" query parameter is set...
// If the GET parameter isn't set, bail.
$params = drupal_get_query_parameters();
if (!empty($params['farm_area'])) {
// Verify that the farm_area is valid.
$area = taxonomy_term_load($params['farm_area']);
if ($area) {
// Add the area to the form.
$form['farm_area'] = array(
'#type' => 'value',
'#value' => $area,
);
// Prepopulate the area reference field.
if (empty($field_value)) {
$field_value = $area->tid;
}
}
if (empty($params[$param])) {
return array();
}
return $area;
}
/**
* Helper function for enabling owner prepopulation in log forms.
*
* @param array $form
* The form array to modify, passed by reference.
*/
function farm_log_form_prepopulate_owner(array &$form) {
// Alias for the field's default value.
$field_value = &$form['field_farm_log_owner'][LANGUAGE_NONE]['#default_value'];
// Only proceed if the field is empty.
if (!empty($field_value)) {
return;
}
// Load the current authenticated user.
global $user;
// If the user id is empty for whatever reason, bail.
if (empty($user->uid)) {
return;
}
// Add the user's id to the list of log owners.
$field_value = array($user->uid);
// If only a single ID is passed, convert it to an array.
if (!is_array($params[$param])) {
$params[$param] = array($params[$param]);
}
// Return the array of IDs.
return $params[$param];
}

View File

@ -34,9 +34,17 @@ function farm_log_activity_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 4,
),
);

View File

@ -10,6 +10,45 @@
function farm_log_harvest_field_default_field_instances() {
$field_instances = array();
// Exported field_instance: 'log-farm_harvest-field_farm_area'.
$field_instances['log-farm_harvest-field_farm_area'] = array(
'bundle' => 'farm_harvest',
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas is this harvest taking place in?',
'display' => array(
'default' => array(
'label' => 'inline',
'module' => 'taxonomy',
'settings' => array(),
'type' => 'taxonomy_term_reference_link',
'weight' => 2,
),
),
'entity_type' => 'log',
'field_name' => 'field_farm_area',
'label' => 'Areas',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 12,
),
);
// Exported field_instance: 'log-farm_harvest-field_farm_asset'.
$field_instances['log-farm_harvest-field_farm_asset'] = array(
'bundle' => 'farm_harvest',
@ -69,7 +108,7 @@ function farm_log_harvest_field_default_field_instances() {
'module' => 'file',
'settings' => array(),
'type' => 'file_table',
'weight' => 7,
'weight' => 8,
),
'token' => array(
'label' => 'above',
@ -115,7 +154,7 @@ function farm_log_harvest_field_default_field_instances() {
'map_layer_preset' => 'farm_map_geofield_formatter:openlayers_geofield_layer_formatter',
),
'type' => 'openlayers_geofield',
'weight' => 8,
'weight' => 9,
),
'token' => array(
'label' => 'above',
@ -162,7 +201,7 @@ function farm_log_harvest_field_default_field_instances() {
'use_geocoder' => 1,
),
'type' => 'openlayers_geofield',
'weight' => 3,
'weight' => 4,
),
);
@ -187,7 +226,7 @@ function farm_log_harvest_field_default_field_instances() {
'colorbox_node_style_first' => 'large',
),
'type' => 'colorbox',
'weight' => 6,
'weight' => 7,
),
'token' => array(
'label' => 'above',
@ -235,7 +274,7 @@ function farm_log_harvest_field_default_field_instances() {
'module' => 'taxonomy',
'settings' => array(),
'type' => 'taxonomy_term_reference_plain',
'weight' => 4,
'weight' => 5,
),
),
'entity_type' => 'log',
@ -269,7 +308,7 @@ function farm_log_harvest_field_default_field_instances() {
'link' => FALSE,
),
'type' => 'entityreference_label',
'weight' => 5,
'weight' => 6,
),
),
'entity_type' => 'log',
@ -336,7 +375,7 @@ function farm_log_harvest_field_default_field_instances() {
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 9,
'weight' => 10,
),
),
'entity_type' => 'log',
@ -351,7 +390,7 @@ function farm_log_harvest_field_default_field_instances() {
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 4,
'weight' => 5,
),
);
@ -367,7 +406,7 @@ function farm_log_harvest_field_default_field_instances() {
'module' => 'text',
'settings' => array(),
'type' => 'text_default',
'weight' => 3,
'weight' => 4,
),
'token' => array(
'label' => 'above',
@ -391,7 +430,7 @@ function farm_log_harvest_field_default_field_instances() {
'rows' => 5,
),
'type' => 'text_textarea',
'weight' => 3,
'weight' => 14,
),
);
@ -409,7 +448,7 @@ function farm_log_harvest_field_default_field_instances() {
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 2,
'weight' => 3,
),
'token' => array(
'label' => 'above',
@ -430,12 +469,13 @@ function farm_log_harvest_field_default_field_instances() {
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 2,
'weight' => 3,
),
);
// Translatables
// Included for use with string extractors like potx.
t('Areas');
t('Assets');
t('Describe the quantity of this harvest, using a value and a unit of measurement. For example, if you harvested 100 pounds of potatoes, enter "100" in the Value field, and "lbs" in the Units field. As you type the unit, you will have the option of selecting from units that you\'ve entered in the past.');
t('Files');
@ -452,6 +492,7 @@ function farm_log_harvest_field_default_field_instances() {
t('This field is optional. It allows you to store geospatial data along with this harvest.');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('Use this to organize your logs into categories for easier searching and filtering later.');
t('What areas is this harvest taking place in?');
t('What assets do this harvest log pertain to?');
return $field_instances;

View File

@ -10,6 +10,35 @@
function farm_log_harvest_field_group_info() {
$field_groups = array();
$field_group = new stdClass();
$field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
$field_group->api_version = 1;
$field_group->identifier = 'group_farm_areas|log|farm_harvest|form';
$field_group->group_name = 'group_farm_areas';
$field_group->entity_type = 'log';
$field_group->bundle = 'farm_harvest';
$field_group->mode = 'form';
$field_group->parent_name = '';
$field_group->data = array(
'label' => 'Areas',
'weight' => '2',
'children' => array(
0 => 'field_farm_area',
),
'format_type' => 'fieldset',
'format_settings' => array(
'label' => 'Areas',
'instance_settings' => array(
'required_fields' => 1,
'id' => '',
'classes' => 'group-farm-areas field-group-fieldset',
'description' => '',
),
'formatter' => 'collapsed',
),
);
$field_groups['group_farm_areas|log|farm_harvest|form'] = $field_group;
$field_group = new stdClass();
$field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
$field_group->api_version = 1;
@ -50,7 +79,7 @@ function farm_log_harvest_field_group_info() {
$field_group->parent_name = '';
$field_group->data = array(
'label' => 'Assignment',
'weight' => '7',
'weight' => '8',
'children' => array(
0 => 'field_farm_log_owner',
),
@ -79,7 +108,7 @@ function farm_log_harvest_field_group_info() {
$field_group->parent_name = '';
$field_group->data = array(
'label' => 'Category',
'weight' => '6',
'weight' => '7',
'children' => array(
0 => 'field_farm_log_category',
),
@ -108,7 +137,7 @@ function farm_log_harvest_field_group_info() {
$field_group->parent_name = '';
$field_group->data = array(
'label' => 'File attachments',
'weight' => '8',
'weight' => '9',
'children' => array(
0 => 'field_farm_files',
1 => 'field_farm_images',
@ -168,7 +197,7 @@ function farm_log_harvest_field_group_info() {
$field_group->parent_name = '';
$field_group->data = array(
'label' => 'Notes',
'weight' => '5',
'weight' => '6',
'children' => array(
0 => 'field_farm_notes',
),
@ -188,6 +217,7 @@ function farm_log_harvest_field_group_info() {
// Translatables
// Included for use with string extractors like potx.
t('Areas');
t('Assets');
t('Assignment');
t('Category');

View File

@ -10,6 +10,7 @@ dependencies[] = entity
dependencies[] = entity_token
dependencies[] = entityreference
dependencies[] = entityreference_view_widget
dependencies[] = farm_area
dependencies[] = farm_asset
dependencies[] = farm_fields
dependencies[] = farm_log_movement
@ -34,12 +35,14 @@ dependencies[] = views_data_export
features[ctools][] = field_group:field_group:1
features[ctools][] = views:views_default:3.0
features[features_api][] = api:2
features[field_group][] = group_farm_areas|log|farm_harvest|form
features[field_group][] = group_farm_assets|log|farm_harvest|form
features[field_group][] = group_farm_assignment|log|farm_harvest|form
features[field_group][] = group_farm_category|log|farm_harvest|form
features[field_group][] = group_farm_files|log|farm_harvest|form
features[field_group][] = group_farm_general|log|farm_harvest|form
features[field_group][] = group_farm_notes|log|farm_harvest|form
features[field_instance][] = log-farm_harvest-field_farm_area
features[field_instance][] = log-farm_harvest-field_farm_asset
features[field_instance][] = log-farm_harvest-field_farm_files
features[field_instance][] = log-farm_harvest-field_farm_geofield

View File

@ -232,6 +232,11 @@ function farm_log_harvest_views_default_views() {
'link' => 1,
);
$handler->display->display_options['fields']['field_farm_asset']['delta_offset'] = '0';
/* Field: Log: Areas */
$handler->display->display_options['fields']['field_farm_area']['id'] = 'field_farm_area';
$handler->display->display_options['fields']['field_farm_area']['table'] = 'field_data_field_farm_area';
$handler->display->display_options['fields']['field_farm_area']['field'] = 'field_farm_area';
$handler->display->display_options['fields']['field_farm_area']['delta_offset'] = '0';
/* Field: Log: Sale lot number */
$handler->display->display_options['fields']['field_farm_lot_number']['id'] = 'field_farm_lot_number';
$handler->display->display_options['fields']['field_farm_lot_number']['table'] = 'field_data_field_farm_lot_number';

View File

@ -40,9 +40,17 @@ function farm_log_input_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 12,
),
);

View File

@ -80,7 +80,7 @@ function farm_log_movement_field_default_field_instances() {
// 'field_collection_item-field_farm_movement-field_farm_move_from'.
$field_instances['field_collection_item-field_farm_movement-field_farm_move_from'] = array(
'bundle' => 'field_farm_movement',
'default_value' => NULL,
'default_value' => array(),
'deleted' => 0,
'description' => 'Specify the area(s) that assets are being moved from. This field is optional, and is only used for reference. You may leave this blank as a way of setting initial location. If the assets currently have a location set from a previously logged movement, this field will be automatically filled using that information.',
'display' => array(
@ -101,9 +101,17 @@ function farm_log_movement_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 4,
),
);
@ -112,7 +120,7 @@ function farm_log_movement_field_default_field_instances() {
// 'field_collection_item-field_farm_movement-field_farm_move_to'.
$field_instances['field_collection_item-field_farm_movement-field_farm_move_to'] = array(
'bundle' => 'field_farm_movement',
'default_value' => NULL,
'default_value' => array(),
'deleted' => 0,
'description' => 'Specify the area(s) that assets are being moved to. If you need to specify more precise locations (in addition to these areas), use the Geometry field below.',
'display' => array(
@ -133,9 +141,17 @@ function farm_log_movement_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 2,
),
);

View File

@ -15,7 +15,7 @@ function farm_log_observation_field_default_field_instances() {
'bundle' => 'farm_observation',
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas did this observation take place in?',
'description' => 'What areas is this observation taking place in?',
'display' => array(
'default' => array(
'label' => 'inline',
@ -34,9 +34,17 @@ function farm_log_observation_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 3,
),
);
@ -413,7 +421,7 @@ function farm_log_observation_field_default_field_instances() {
t('This field is optional. It allows you to store geospatial data along with this observation.');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('Use this to organize your logs into categories for easier searching and filtering later.');
t('What areas did this observation take place in?');
t('What areas is this observation taking place in?');
t('What assets do this observation log pertain to?');
return $field_instances;

View File

@ -15,7 +15,7 @@ function farm_soil_test_field_default_field_instances() {
'bundle' => 'farm_soil_test',
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas were this soil sample taken from?',
'description' => 'What areas is this sample being taken from?',
'display' => array(
'default' => array(
'label' => 'inline',
@ -34,9 +34,17 @@ function farm_soil_test_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 2,
),
);
@ -339,7 +347,7 @@ function farm_soil_test_field_default_field_instances() {
t('Sample Points');
t('Soil Names');
t('Use the map to pinpoint the location(s) from which this sample is taken. If you are preparing a soil test, you may be sampling multiple points within a given area. All the points that comprise this sample should be included.');
t('What areas were this soil sample taken from?');
t('What areas is this sample being taken from?');
t('What laboratory performed the soil test?');
return $field_instances;

View File

@ -7,6 +7,7 @@ dependencies[] = ctools
dependencies[] = date
dependencies[] = entity
dependencies[] = entityreference
dependencies[] = entityreference_view_widget
dependencies[] = farm_area
dependencies[] = farm_fields
dependencies[] = farm_map

View File

@ -13,9 +13,9 @@ function farm_water_test_field_default_field_instances() {
// Exported field_instance: 'log-farm_water_test-field_farm_area'.
$field_instances['log-farm_water_test-field_farm_area'] = array(
'bundle' => 'farm_water_test',
'default_value' => NULL,
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas were this water sample taken from?',
'description' => 'What areas is this water sample being taken from?',
'display' => array(
'default' => array(
'label' => 'inline',
@ -34,9 +34,17 @@ function farm_water_test_field_default_field_instances() {
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'module' => 'entityreference_view_widget',
'settings' => array(
'allow_duplicates' => 0,
'close_modal' => 1,
'pass_argument' => 1,
'pass_arguments' => '',
'rendered_entity' => 0,
'view' => 'farm_area_entityreference_view|entityreference_view_widget',
'view_mode' => 'full',
),
'type' => 'entityreference_view_widget',
'weight' => 7,
),
);
@ -306,7 +314,7 @@ function farm_water_test_field_default_field_instances() {
t('Photos');
t('Sample points');
t('Use the map to pinpoint the location(s) from which this sample is taken.');
t('What areas were this water sample taken from?');
t('What areas is this water sample being taken from?');
t('What laboratory performed the water test?');
return $field_instances;

View File

@ -6,6 +6,7 @@ dependencies[] = colorbox
dependencies[] = ctools
dependencies[] = entity
dependencies[] = entityreference
dependencies[] = entityreference_view_widget
dependencies[] = farm_area
dependencies[] = farm_fields
dependencies[] = farm_water