materio_showroom.module 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Implements hook_init().
  4. */
  5. // function materio_showroom_init() {
  6. // drupal_add_js(drupal_get_path('module', 'materio_showroom').'/js/materio_showroom.js');
  7. // }
  8. /**
  9. * Implements hook_permission().
  10. */
  11. // function materio_showroom_permission() {
  12. // $perms = array(
  13. // 'add showroom localisation' => array(
  14. // 'title' => t('add showroom localisation'),
  15. // 'description' => t('add showroom localisation'),
  16. // ),
  17. // );
  18. //
  19. // return $perms;
  20. // }
  21. /**
  22. * Acts on a field collection item being inserted or updated.
  23. *
  24. * This hook is invoked before the field collection item is saved to the database.
  25. *
  26. * @param FieldCollectionItemEntity $field_collection_item
  27. * The field collection item that is being inserted or updated.
  28. *
  29. * @see hook_entity_presave()
  30. */
  31. function materio_showroom_entity_presave($entity, $type) {
  32. // dsm($type);
  33. if ($type == 'field_collection_item' && $entity->field_name == 'field_showroom_localisation') {
  34. // dsm($entity);
  35. global $user;
  36. $user = user_load($user->uid); // Make sure the user object is fully loaded
  37. // dsm($user);
  38. if(isset($entity->field_showroom_localisation_loca[LANGUAGE_NONE])){
  39. $user_showroom = $user->field_showroom[LANGUAGE_NONE][0]['tid'];
  40. // dsm($user_showroom);
  41. foreach ($entity->field_showroom_localisation_loca[LANGUAGE_NONE] as $i => $loca) {
  42. if(empty($entity->field_showroom_localisation_show)){
  43. $entity->field_showroom_localisation_show[LANGUAGE_NONE] = [];
  44. }
  45. if(empty($entity->field_showroom_localisation_show[LANGUAGE_NONE])){
  46. $entity->field_showroom_localisation_show[LANGUAGE_NONE][] = [];
  47. }
  48. dsm($entity->field_showroom_localisation_show);
  49. if(!isset($entity->original->field_showroom_localisation_show[LANGUAGE_NONE][$i]['tid'])){
  50. $tid = $user_showroom;
  51. }else{
  52. $tid = $entity->original->field_showroom_localisation_show[LANGUAGE_NONE][$i]['tid'];
  53. }
  54. dsm($tid);
  55. $entity->field_showroom_localisation_show[LANGUAGE_NONE][$i]['tid'] = $tid;
  56. dsm($entity->field_showroom_localisation_show);
  57. }
  58. }
  59. }
  60. }
  61. /**
  62. * Implements hook_form_alter().
  63. */
  64. // function materio_showroom_form_alter(&$form, &$form_state, $form_id) {
  65. // // dsm($form_id);
  66. // if( $form_id == "materiau_node_form" ){
  67. // dsm($form);
  68. // // $form['account']['pass']['#type'] = 'password';
  69. // // $form['account']['pass']['#title'] = t('Password');
  70. // //
  71. // // $form['actions']['#type'] = "container";
  72. // // $form['actions']['submit']['#value'] = t('Join');
  73. // }
  74. //
  75. // }