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, $langcode) { return $entity_field_item['value']; } /** * Implements hook_form_alter(). */ function idmaterio_form_alter(&$form, &$form_state, $form_id) { if($form_id == "materiau_node_form"){ // $node = $form_state['node']; // dsm($form, '$form'); // dsm($form_state, '$form_state'); // // // $form['field_id_materio']['#markup'] = $node->field_famille['und']['default_value'] .'-'. $node->field_identifiant['und'][0]['value']; } } function idmaterio_nodeformcols_pre_form_alter(&$form){ // dsm($form, 'node pre form col alter $form'); // $form['field_identifiant']['#prefix'] = '
'; // $form['field_identifiant'] ['#markup'] = '

Hello !

'; // $form['field_identifiant']['#suffix'] = '
'; // $form['materio_id'] = array( // '#type'=>'markup', // '#prefix' => '
', // '#markup' => '

Hello !

', // '#suffix' => '
', // '#weight' => $form['field_identifiant']['#weight'], // ); } function idmaterio_nodeformcols_post_form_alter(&$form){ // dsm($form, 'node post form col alter $form'); // $form['materio_id'] = array( // '#type'=>'markup', // '#prefix' => '
', // '#markup' => '

Hello !

', // '#suffix' => '
', // '#weight' => $form['field_identifiant']['#weight'], // ); // }