87 lines
2.6 KiB
Plaintext

<?php
/**
* Implements hook_init().
*/
// function materio_showroom_init() {
// drupal_add_js(drupal_get_path('module', 'materio_showroom').'/js/materio_showroom.js');
// }
/**
* Implements hook_permission().
*/
// function materio_showroom_permission() {
// $perms = array(
// 'add showroom localisation' => array(
// 'title' => t('add showroom localisation'),
// 'description' => t('add showroom localisation'),
// ),
// );
//
// return $perms;
// }
/**
* Acts on a field collection item being inserted or updated.
*
* This hook is invoked before the field collection item is saved to the database.
*
* @param FieldCollectionItemEntity $field_collection_item
* The field collection item that is being inserted or updated.
*
* @see hook_entity_presave()
*/
function materio_showroom_entity_presave($entity, $type) {
// dsm($type);
if ($type == 'field_collection_item' && $entity->field_name == 'field_showroom_localisation') {
// dsm($entity);
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
// dsm($user);
if(isset($entity->field_showroom_localisation_loca[LANGUAGE_NONE])){
$user_showroom = $user->field_showroom[LANGUAGE_NONE][0]['tid'];
// dsm($user_showroom);
foreach ($entity->field_showroom_localisation_loca[LANGUAGE_NONE] as $i => $loca) {
if(empty($entity->field_showroom_localisation_show)){
$entity->field_showroom_localisation_show[LANGUAGE_NONE] = [];
}
if(empty($entity->field_showroom_localisation_show[LANGUAGE_NONE])){
$entity->field_showroom_localisation_show[LANGUAGE_NONE][] = [];
}
dsm($entity->field_showroom_localisation_show);
if(!isset($entity->original->field_showroom_localisation_show[LANGUAGE_NONE][$i]['tid'])){
$tid = $user_showroom;
}else{
$tid = $entity->original->field_showroom_localisation_show[LANGUAGE_NONE][$i]['tid'];
}
dsm($tid);
$entity->field_showroom_localisation_show[LANGUAGE_NONE][$i]['tid'] = $tid;
dsm($entity->field_showroom_localisation_show);
}
}
}
}
/**
* Implements hook_form_alter().
*/
// function materio_showroom_form_alter(&$form, &$form_state, $form_id) {
// // dsm($form_id);
// if( $form_id == "materiau_node_form" ){
// dsm($form);
// // $form['account']['pass']['#type'] = 'password';
// // $form['account']['pass']['#title'] = t('Password');
// //
// // $form['actions']['#type'] = "container";
// // $form['actions']['submit']['#value'] = t('Join');
// }
//
// }