merged idmaterio submodule
This commit is contained in:
		
							
								
								
									
										29
									
								
								sites/all/modules/gui/idmaterio/idmaterio.info
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								sites/all/modules/gui/idmaterio/idmaterio.info
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					name = Idmaterio
 | 
				
			||||||
 | 
					description = "The description of this module"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Core version (required)
 | 
				
			||||||
 | 
					core = 7.x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Package name (see http://drupal.org/node/542202 for a list of names)
 | 
				
			||||||
 | 
					; package = 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; PHP version requirement (optional)
 | 
				
			||||||
 | 
					; php = 5.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Loadable code files
 | 
				
			||||||
 | 
					; files[] = idmaterio.module
 | 
				
			||||||
 | 
					; files[] = idmaterio.admin.inc
 | 
				
			||||||
 | 
					; files[] = idmaterio.class.inc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Module dependencies
 | 
				
			||||||
 | 
					; dependencies[] = mymodule
 | 
				
			||||||
 | 
					; dependencies[] = theirmodule (1.2)
 | 
				
			||||||
 | 
					; dependencies[] = anothermodule (>=2.4)
 | 
				
			||||||
 | 
					; dependencies[] = views (3.x)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Configuration page
 | 
				
			||||||
 | 
					; configure = admin/config/idmaterio
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; For further information about configuration options, see
 | 
				
			||||||
 | 
					; - http://drupal.org/node/542202
 | 
				
			||||||
							
								
								
									
										121
									
								
								sites/all/modules/gui/idmaterio/idmaterio.module
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								sites/all/modules/gui/idmaterio/idmaterio.module
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,121 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @file
 | 
				
			||||||
 | 
					 * This is the file description for Idmaterio module.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * In this more verbose, multi-line description, you can specify what this
 | 
				
			||||||
 | 
					 * file does exactly. Make sure to wrap your documentation in column 78 so
 | 
				
			||||||
 | 
					 * that the file can be displayed nicely in default-sized consoles.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function computed_field_field_identifiant_compute(&$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
 | 
				
			||||||
 | 
						// dsm('-- computed --');
 | 
				
			||||||
 | 
						// dsm($entity_field, '$entity_field');
 | 
				
			||||||
 | 
						// dsm($entity_type, '$entity_type');
 | 
				
			||||||
 | 
						// dsm($entity, '$entity');
 | 
				
			||||||
 | 
						// dsm($field, '$field');
 | 
				
			||||||
 | 
						// dsm($instance, '$instance');
 | 
				
			||||||
 | 
						// dsm($items, '$items');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// dsm($entity_field[0]['value'], 'entity_field value');
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if (!empty($entity_field[0]['value'])) {  // the node is not new
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						  return $entity_field[0]['value'];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else {  // the node is new
 | 
				
			||||||
 | 
						  // get all same entities in same family
 | 
				
			||||||
 | 
							$query = new EntityFieldQuery();
 | 
				
			||||||
 | 
							$query
 | 
				
			||||||
 | 
								->entityCondition('entity_type', $entity_type)
 | 
				
			||||||
 | 
								->entityCondition('bundle', $entity->type)
 | 
				
			||||||
 | 
								->fieldCondition('field_famille', 'value', $entity->field_famille['und'][0]['value']);
 | 
				
			||||||
 | 
							$result = $query->execute();
 | 
				
			||||||
 | 
							if(is_array($result[$entity_type])){
 | 
				
			||||||
 | 
								$entities = entity_load($entity_type, array_keys($result[$entity_type]));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// get identifiants fo these entities
 | 
				
			||||||
 | 
								$ids = array();
 | 
				
			||||||
 | 
								foreach ($entities as $id => $e) {
 | 
				
			||||||
 | 
									$identifiant = field_view_field($entity_type, $e, 'field_identifiant');
 | 
				
			||||||
 | 
									$ids[] = $identifiant[0]['#markup'] ? intval($identifiant[0]['#markup']) : 0;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								sort($ids);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$value = strval(array_pop($ids) + 1);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								$value = '1';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// parse the value to a string as 0023 or 4458 or 0001
 | 
				
			||||||
 | 
							$value_parts = str_split($value);
 | 
				
			||||||
 | 
							while (count($value_parts) < 4) {
 | 
				
			||||||
 | 
								array_unshift($value_parts, "0");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// record the result
 | 
				
			||||||
 | 
								$entity_field[0]['value'] = implode('', $value_parts);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function computed_field_field_identifiant_display($field, $entity_field_item, $entity_lang = "en", $langcode = "en") {
 | 
				
			||||||
 | 
						return $entity_field_item['value'];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function computed_field_field_reference_materio_compute(&$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
 | 
				
			||||||
 | 
						// dsm('-- computed --');
 | 
				
			||||||
 | 
						// 	dsm($entity_field, '$entity_field');
 | 
				
			||||||
 | 
						// 	dsm($entity_type, '$entity_type');
 | 
				
			||||||
 | 
						// 	dsm($entity, '$entity');
 | 
				
			||||||
 | 
						// 	dsm($field, '$field');
 | 
				
			||||||
 | 
						// 	dsm($instance, '$instance');
 | 
				
			||||||
 | 
						// 	dsm($items, '$items');
 | 
				
			||||||
 | 
						if (!empty($entity_field[0]['value'])) {  // the node is not new
 | 
				
			||||||
 | 
						  return $entity_field[0]['value'];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else {  // the node is new
 | 
				
			||||||
 | 
							$entity_field[0]['value'] = $entity->field_famille['und'][0]['value'].'-'.$entity->field_identifiant['und'][0]['value'];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function computed_field_field_reference_materio_display($field, $entity_field_item, $entity_lang = "en", $langcode = "en") {
 | 
				
			||||||
 | 
						return $entity_field_item['value'];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Implements hook_form_alter().
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function idmaterio_form_alter(&$form, &$form_state, $form_id) {
 | 
				
			||||||
 | 
						if($form_id == "materiau_node_form"){
 | 
				
			||||||
 | 
							// dsm($form, '$form');
 | 
				
			||||||
 | 
							// dsm($form_state, '$form_state');
 | 
				
			||||||
 | 
							$ref = $form['field_reference_materio']['und'][0]['value']['#default_value'];
 | 
				
			||||||
 | 
							if($ref != ''){
 | 
				
			||||||
 | 
								$title = t('Edit').' '.$form['title']['#default_value'].' ('.$form['type']['#value'].' '.$ref.')';
 | 
				
			||||||
 | 
								// dsm($title, '$title');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								drupal_set_title($title);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$form['reference'] = array(
 | 
				
			||||||
 | 
								  '#markup' => t('Materio Reference').' : <span>'.$ref.'</span>',
 | 
				
			||||||
 | 
								  '#prefix' => '<div class="form-item materio-ref">',
 | 
				
			||||||
 | 
								  '#suffix' => '</div>',
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								$form['reference']['#placement'] = array(
 | 
				
			||||||
 | 
							    'region' => 'right',
 | 
				
			||||||
 | 
							    'weight' => 0,
 | 
				
			||||||
 | 
							    'has_required' => FALSE,
 | 
				
			||||||
 | 
							    'hidden' => FALSE,
 | 
				
			||||||
 | 
							  );
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
								// dsm(synonyms_get_synonyms(4346), 'synonyms_get_synonyms');
 | 
				
			||||||
 | 
								// dsm(synonyms_get_synonym_root('fenouille'), 'synonyms_get_synonym_root');
 | 
				
			||||||
 | 
								//dsm(synonyms_node_update_index($form['#node']));
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user