diff --git a/README.md b/README.md new file mode 100644 index 00000000..7fa6270c --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +FARM LOG +======== + +Provides a framework for dealing with quantities. + +This module is part of the [farmOS](http://drupal.org/project/farm) +distribution. + +DEPENDENCIES +------------ + +This module depends on the following modules: + + * Ctools (http://drupal.org/project/ctools) + * Features (http://drupal.org/project/features) + * Field Collection (http://drupal.org/project/field_collection) + * Fraction (http://drupal.org/project/fraction) + * Strongarm (http://drupal.org/project/strongarm) + +INSTALLATION +------------ + +Install as you would normally install a contributed drupal module. See: +http://drupal.org/documentation/install/modules-themes/modules-7 for further +information. + +MAINTAINERS +----------- + +Current maintainers: + * Michael Stenta (m.stenta) - https://drupal.org/user/581414 + +This project has been sponsored by: + * [Farmier](http://farmier.com) diff --git a/farm_quantity.features.field_base.inc b/farm_quantity.features.field_base.inc new file mode 100644 index 00000000..cfcb6e4f --- /dev/null +++ b/farm_quantity.features.field_base.inc @@ -0,0 +1,77 @@ + 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_farm_quantity', + 'indexes' => array( + 'revision_id' => array( + 0 => 'revision_id', + ), + ), + 'locked' => 0, + 'module' => 'field_collection', + 'settings' => array( + 'hide_blank_items' => 1, + 'path' => '', + ), + 'translatable' => 0, + 'type' => 'field_collection', + ); + + // Exported field_base: 'field_farm_quantity_units'. + $field_bases['field_farm_quantity_units'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_farm_quantity_units', + 'indexes' => array( + 'tid' => array( + 0 => 'tid', + ), + ), + 'locked' => 0, + 'module' => 'taxonomy', + 'settings' => array( + 'allowed_values' => array( + 0 => array( + 'vocabulary' => 'farm_quantity_units', + 'parent' => 0, + ), + ), + ), + 'translatable' => 0, + 'type' => 'taxonomy_term_reference', + ); + + // Exported field_base: 'field_farm_quantity_value'. + $field_bases['field_farm_quantity_value'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_farm_quantity_value', + 'indexes' => array(), + 'locked' => 0, + 'module' => 'fraction', + 'settings' => array(), + 'translatable' => 0, + 'type' => 'fraction', + ); + + return $field_bases; +} diff --git a/farm_quantity.features.field_instance.inc b/farm_quantity.features.field_instance.inc new file mode 100644 index 00000000..53a31722 --- /dev/null +++ b/farm_quantity.features.field_instance.inc @@ -0,0 +1,92 @@ + 'field_farm_quantity', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'module' => 'taxonomy', + 'settings' => array(), + 'type' => 'taxonomy_term_reference_plain', + 'weight' => 1, + ), + ), + 'entity_type' => 'field_collection_item', + 'field_name' => 'field_farm_quantity_units', + 'label' => 'Units', + 'required' => 1, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 0, + 'module' => 'taxonomy', + 'settings' => array( + 'autocomplete_path' => 'taxonomy/autocomplete', + 'size' => 60, + ), + 'type' => 'taxonomy_autocomplete', + 'weight' => 1, + ), + ); + + // Exported field_instance: + // 'field_collection_item-field_farm_quantity-field_farm_quantity_value'. + $field_instances['field_collection_item-field_farm_quantity-field_farm_quantity_value'] = array( + 'bundle' => 'field_farm_quantity', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'module' => 'fraction', + 'settings' => array( + 'auto_precision' => 1, + 'precision' => 0, + ), + 'type' => 'fraction_decimal', + 'weight' => 0, + ), + ), + 'entity_type' => 'field_collection_item', + 'field_name' => 'field_farm_quantity_value', + 'label' => 'Value', + 'required' => 1, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'fraction', + 'settings' => array( + 'auto_precision' => 1, + 'precision' => 0, + ), + 'type' => 'fraction_decimal', + 'weight' => 0, + ), + ); + + // Translatables + // Included for use with string extractors like potx. + t('Units'); + t('Value'); + + return $field_instances; +} diff --git a/farm_quantity.features.inc b/farm_quantity.features.inc new file mode 100644 index 00000000..a13df549 --- /dev/null +++ b/farm_quantity.features.inc @@ -0,0 +1,14 @@ + "1"); + } +} diff --git a/farm_quantity.features.taxonomy.inc b/farm_quantity.features.taxonomy.inc new file mode 100644 index 00000000..15f3a20c --- /dev/null +++ b/farm_quantity.features.taxonomy.inc @@ -0,0 +1,36 @@ + array( + 'name' => 'Farm Quantity Units', + 'machine_name' => 'farm_quantity_units', + 'description' => 'A vocabulary of units for describing quantities.', + 'hierarchy' => 0, + 'module' => 'taxonomy', + 'weight' => 0, + 'rdf_mapping' => array( + 'rdftype' => array( + 0 => 'skos:ConceptScheme', + ), + 'name' => array( + 'predicates' => array( + 0 => 'dc:title', + ), + ), + 'description' => array( + 'predicates' => array( + 0 => 'rdfs:comment', + ), + ), + ), + ), + ); +} diff --git a/farm_quantity.info b/farm_quantity.info index 6475809a..652f9196 100644 --- a/farm_quantity.info +++ b/farm_quantity.info @@ -2,3 +2,18 @@ name = Farm Quantity description = Provides a framework for dealing with quantities. core = 7.x package = farmOS +dependencies[] = ctools +dependencies[] = features +dependencies[] = field_collection +dependencies[] = fraction +dependencies[] = strongarm +dependencies[] = taxonomy +features[ctools][] = strongarm:strongarm:1 +features[features_api][] = api:2 +features[field_base][] = field_farm_quantity +features[field_base][] = field_farm_quantity_units +features[field_base][] = field_farm_quantity_value +features[field_instance][] = field_collection_item-field_farm_quantity-field_farm_quantity_units +features[field_instance][] = field_collection_item-field_farm_quantity-field_farm_quantity_value +features[taxonomy][] = farm_quantity_units +features[variable][] = pathauto_taxonomy_term_farm_quantity_units_pattern diff --git a/farm_quantity.module b/farm_quantity.module index 0ff1bb6d..05857a39 100644 --- a/farm_quantity.module +++ b/farm_quantity.module @@ -3,3 +3,37 @@ * @file * Farm quantity module. */ + +// Include Features code. +include_once 'farm_quantity.features.inc'; + +/** + * Implements hook_farm_access_perms(). + */ +function farm_quantity_farm_access_perms($role) { + + // Assemble a list of entity types provided by this module. + $types = array( + 'taxonomy' => array( + 'farm_quantity_units', + ), + ); + + // Grant different CRUD permissions based on the role. + $perms = array(); + switch ($role) { + + // Farm Manager and Worker + case 'Farm Manager': + case 'Farm Worker': + $perms = farm_access_entity_perms($types); + break; + + // Farm Viewer + case 'Farm Viewer': + $perms = farm_access_entity_perms($types, array('view')); + break; + } + + return $perms; +} diff --git a/farm_quantity.strongarm.inc b/farm_quantity.strongarm.inc new file mode 100644 index 00000000..b595db6f --- /dev/null +++ b/farm_quantity.strongarm.inc @@ -0,0 +1,21 @@ +disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'pathauto_taxonomy_term_farm_quantity_units_pattern'; + $strongarm->value = 'farm/unit/[term:name]'; + $export['pathauto_taxonomy_term_farm_quantity_units_pattern'] = $strongarm; + + return $export; +}