|
@@ -182,16 +182,13 @@ function materio_showroom_field_widget_info() {
|
|
|
* 'rgb' form element.
|
|
|
*/
|
|
|
function materio_showroom_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
|
|
- $locval = isset($items[$delta]['location']) ? $items[$delta]['location'] : '';
|
|
|
- $showroom_tid = isset($items[$delta]['showroom_tid']) ? $items[$delta]['showroom_tid'] : 0;
|
|
|
-
|
|
|
$widget = $element;
|
|
|
$widget['#delta'] = $delta;
|
|
|
|
|
|
switch ($instance['widget']['type']) {
|
|
|
- // TODO: loop through showrooms and don't allow more than one field by show room
|
|
|
-
|
|
|
- case 'materio_showroom_location_text':
|
|
|
+ case 'materio_showroom_location_text':
|
|
|
+ $locval = isset($items[$delta]['location']) ? $items[$delta]['location'] : '';
|
|
|
+ $showroom_tid = isset($items[$delta]['showroom_tid']) ? $items[$delta]['showroom_tid'] : 0;
|
|
|
|
|
|
$widget['showroom_tid'] = array(
|
|
|
'#type' => 'hidden',
|
|
@@ -211,6 +208,11 @@ function materio_showroom_field_widget_form(&$form, &$form_state, $field, $insta
|
|
|
'#maxlength' => 255,
|
|
|
);
|
|
|
|
|
|
+ $widget['#attached'] = array(
|
|
|
+ // Add javascript to remove the draggable behaviour.
|
|
|
+ 'js' => array(drupal_get_path('module', 'materio_showroom') . '/js/materio_showroom.js'),
|
|
|
+ );
|
|
|
+
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -279,6 +281,8 @@ function _materio_showroom_alter_location_field_form(&$form, &$form_state, $form
|
|
|
$node = $form['#node'];
|
|
|
$nodetype = $form['type']['#value'];
|
|
|
|
|
|
+ // dsm($form_state, 'form_state');
|
|
|
+
|
|
|
global $user;
|
|
|
$user = user_load($user->uid); // Make sure the user object is fully loaded
|
|
|
// dsm($user, 'user');
|
|
@@ -311,13 +315,14 @@ function _materio_showroom_alter_location_field_form(&$form, &$form_state, $form
|
|
|
foreach ($showroomfieldinstances as $field_name) {
|
|
|
// retrive various field infos
|
|
|
$field_info = field_info_field($field_name);
|
|
|
- $field_instance = field_info_instance('node', $field_name, $nodetype);
|
|
|
// dsm($field_info, 'field_info');
|
|
|
+ $field_instance = field_info_instance('node', $field_name, $nodetype);
|
|
|
|
|
|
// get all terms from chosen vocabulary in field instance widget settings
|
|
|
$vid = $field_instance['widget']['settings']['vocabulary'];
|
|
|
$voc = taxonomy_vocabulary_load($vid);
|
|
|
$tree = taxonomy_get_tree($vid);
|
|
|
+ // dsm($tree, 'tree');
|
|
|
foreach ($tree as $key => $term) {
|
|
|
$terms[$term->tid] = $term->name;
|
|
|
}
|
|
@@ -334,44 +339,58 @@ function _materio_showroom_alter_location_field_form(&$form, &$form_state, $form
|
|
|
|
|
|
// get already recorded values
|
|
|
$old_items = field_get_items('node', $node, $field_name);
|
|
|
+ // dsm($old_items, 'old_items');
|
|
|
foreach ($old_items as $i => $value) {
|
|
|
$values[$value['showroom_tid']] = $value['location'];
|
|
|
}
|
|
|
// dsm($values, 'values');
|
|
|
|
|
|
// build new item list
|
|
|
- foreach ($terms as $tid => $name) {
|
|
|
- $items[] = array(
|
|
|
- 'showroom_tid' => $tid,
|
|
|
- 'location' => isset($values[$tid]) ? $values[$tid] : ''
|
|
|
- );
|
|
|
- }
|
|
|
+ // for ($k=0; $k < 3; $k++) {
|
|
|
+ foreach ($terms as $tid => $name) {
|
|
|
+ $items[] = array(
|
|
|
+ 'showroom_tid' => "$tid",
|
|
|
+ 'location' => isset($values[$tid]) ? $values[$tid] : ''
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // }
|
|
|
// dsm($items, 'items');
|
|
|
|
|
|
+ // change form_state items count
|
|
|
+ // without this, form wont populated with all wanted items
|
|
|
+ $form_state['field'][$field_name][LANGUAGE_NONE]['items_count'] = count($items);
|
|
|
+
|
|
|
// retrieve new field form with our custom items
|
|
|
- $new_field_form = field_default_form('node', $node, $field_info, $field_instance, LANGUAGE_NONE, $items, $form, $form_state);
|
|
|
- // dsm($new_field_form, 'default_form');
|
|
|
+ $new_field_form = field_default_form('node', null, $field_info, $field_instance, LANGUAGE_NONE, $items, $form, $form_state)[$field_name];
|
|
|
+ // dsm($new_field_form, 'new_field_form');
|
|
|
+
|
|
|
+
|
|
|
+ // $elements = field_multiple_value_form($field_info, $field_instance, LANGUAGE_NONE, $items, $form, $form_state);
|
|
|
+ // dsm($elements, 'elements');
|
|
|
+
|
|
|
|
|
|
// change items location field title
|
|
|
// and check access comparing term id with user taged with
|
|
|
$i = 0;
|
|
|
foreach ($terms as $tid => $name) {
|
|
|
- $item = $new_field_form[$field_name][LANGUAGE_NONE][$i];
|
|
|
- $new_field_form[$field_name][LANGUAGE_NONE][$i]['location']['#title'] = $terms[$item['showroom_tid']['#default_value']];
|
|
|
+ $item = $new_field_form[LANGUAGE_NONE][$i];
|
|
|
+ $new_field_form[LANGUAGE_NONE][$i]['location']['#title'] = $terms[$item['showroom_tid']['#default_value']];
|
|
|
$disabled = !user_access('materio showroom edit all samples fields', $user) && !in_array($tid, $user_showrooms);
|
|
|
- $new_field_form[$field_name][LANGUAGE_NONE][$i]['location']['#disabled'] = $disabled;
|
|
|
+ $new_field_form[LANGUAGE_NONE][$i]['location']['#disabled'] = $disabled;
|
|
|
$i++;
|
|
|
}
|
|
|
|
|
|
// remove the last one more item added by default
|
|
|
- unset($new_field_form[$field_name][LANGUAGE_NONE][$i]);
|
|
|
+ unset($new_field_form[LANGUAGE_NONE][$i]);
|
|
|
+
|
|
|
+ // remove "add more" button
|
|
|
+ unset($new_field_form[LANGUAGE_NONE]['add_more']);
|
|
|
+
|
|
|
+ // dsm($new_field_form, 'new_field_form');
|
|
|
|
|
|
// delete normal field form and replace it with our new custom field form
|
|
|
unset($form[$field_name]);
|
|
|
- $form[$field_name] = $new_field_form[$field_name];
|
|
|
-
|
|
|
- // remove "add more" button
|
|
|
- unset($form[$field_name]['und']['add_more']);
|
|
|
+ $form[$field_name] = $new_field_form;
|
|
|
}
|
|
|
}
|
|
|
}
|