function _ip_geoloc_plugin_style_diff_color_table_row_form in IP Geolocation Views & Maps 8
Same name and namespace in other branches
- 7 views/ip_geoloc_plugin_style.inc \_ip_geoloc_plugin_style_diff_color_table_row_form()
Diffs the color table plugin style row.
1 call to _ip_geoloc_plugin_style_diff_color_table_row_form()
- _ip_geoloc_plugin_style_differentiator_color_table_form in src/
Plugin/ views/ style/ ip_geoloc_plugin_style.inc - Plugin style color differ.
File
- src/
Plugin/ views/ style/ ip_geoloc_plugin_style.inc, line 410 - ip_geoloc_plugin_style.inc
Code
function _ip_geoloc_plugin_style_diff_color_table_row_form($is_openlayers, $row, $differentiator, $association = NULL) {
$differentiator_value = empty($association) ? NULL : $association['differentiator_value'];
$attr_class = $is_openlayers ? [
'differentiator ol',
] : [
'differentiator',
];
if (strpos($differentiator, 'field_') === 0) {
$field = field_info_field($differentiator);
$instances = ip_geoloc_get_field_instances($differentiator);
$instance = reset($instances);
$widget = $instance['widget']['type'];
if (strpos($widget, 'taxonomy') !== FALSE) {
// Covers core and Autocomplete Deluxe.
$vid = 0;
$vocabulary_name = $field['settings']['allowed_values'][0]['vocabulary'];
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
if ($vocabulary->machine_name == $vocabulary_name) {
break;
}
}
$options = [];
foreach (taxonomy_get_tree($vid) as $term) {
$options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
}
$form[$differentiator] = [
'#type' => empty($options) ? 'textfield' : 'select',
'#options' => $options,
'#default_value' => $differentiator_value,
'#attributes' => [
'class' => $attr_class,
],
];
}
else {
// No label, unless other modules override this.
$instance['label'] = '';
// Don't want asterisk to appear.
$instance['required'] = FALSE;
// Make sure the text field is wide enough, especially for the case of a
// range, which needs to receive two values and a separator.
if (isset($instance['widget']['settings']['size']) && $instance['widget']['settings']['size'] < 15) {
$instance['widget']['settings']['size'] = 15;
}
$items[0] = empty($differentiator_value) ? [] : is_array($differentiator_value) ? $differentiator_value : [
$differentiator_value,
];
if (isset($instance['default_value'])) {
$items[0] += is_array($instance['default_value']) && !empty($instance['default_value']) ? reset($instance['default_value']) : $instance['default_value'];
}
$form['#parents'] = [];
$form_state = [];
$form = field_default_form($instance['entity_type'], NULL, $field, $instance, LANGUAGE_NONE, $items, $form, $form_state);
if ($field['module'] == 'number' || $field['module'] == 'text') {
$form[$differentiator][LANGUAGE_NONE][0][key($field['columns'])]['#element_validate'] = [
'ip_geoloc_range_widget_validate',
];
}
$form[$differentiator]['#attributes']['class'][] = $attr_class;
}
}
else {
// Not a field, maybe an expression.
$form[$differentiator] = [
'#type' => 'textfield',
'#size' => 40,
'#default_value' => $differentiator_value,
'#element_validate' => [
'ip_geoloc_range_widget_validate',
],
'#attributes' => [
'class' => $attr_class,
],
];
}
$form['color'] = [
'#type' => 'select',
'#default_value' => empty($association) ? NULL : $association['color'],
'#options' => $is_openlayers ? ip_geoloc_openlayers_marker_layers() : ip_geoloc_marker_colors(),
'#attributes' => [
'class' => $is_openlayers ? [
'marker-color-ol',
] : [
'marker-color',
],
],
];
$form['special char'] = [
'#type' => 'textfield',
'#size' => 8,
'#default_value' => empty($association) ? NULL : $association['special char'],
];
$form['special char class'] = [
'#type' => 'textfield',
'#size' => 25,
'#default_value' => empty($association) ? NULL : $association['special char class'],
];
// We'll manually set the #parents property of these fields so that their
// values appear in the $form_state->getValue('color_table') array.
$form[$differentiator]['#parents'] = [
'color_table',
$row,
$differentiator,
];
$form['color']['#parents'] = [
'color_table',
$row,
'color',
];
$form['special char']['#parents'] = [
'color_table',
$row,
'special char',
];
$form['special char class']['#parents'] = [
'color_table',
$row,
'special char class',
];
return $form;
}