You are here

function yamaps_field_formatter_settings_form in Yandex.Maps 7

Implements hook_field_formatter_settings_form().

File

inc/yamaps.formatter.inc, line 81
Yandex Maps field formatter.

Code

function yamaps_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = [];
  switch ($display['type']) {
    case YAMAPS_DYNAMIC_FORMATTER:
      $element['yamaps_display_options'] = [
        '#type' => 'fieldset',
        '#title' => t('Display options'),
        '#tree' => TRUE,
      ];
      $element['yamaps_display_options']['display_type'] = [
        '#type' => 'radios',
        '#title' => t('Map display style for end user'),
        '#options' => [
          'map' => t('Map'),
          'map_button' => t('Map opened by button click'),
        ],
        '#default_value' => $settings['yamaps_display_options']['display_type'],
        '#required' => FALSE,
        '#description' => t('Configure how to display "Yandex Map" field for end user.'),
      ];
      $element['yamaps_display_options']['open_button_text'] = [
        '#type' => 'textfield',
        '#title' => t('"Open" button text'),
        '#default_value' => $settings['yamaps_display_options']['open_button_text'],
        '#required' => FALSE,
        '#description' => t('Text of button that opens map for end user.'),
        '#states' => [
          'visible' => [
            ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][yamaps_display_options][display_type]"]' => [
              'value' => 'map_button',
            ],
          ],
        ],
      ];
      $element['yamaps_display_options']['close_button_text'] = [
        '#type' => 'textfield',
        '#title' => t('"Close" button text'),
        '#default_value' => isset($settings['yamaps_display_options']['close_button_text']) ? $settings['yamaps_display_options']['close_button_text'] : t(YAMAPS_DEFAULT_CLOSE_MAP_TEXT),
        '#required' => FALSE,
        '#description' => t('Text of button that closes map for end user.'),
        '#states' => [
          'visible' => [
            ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][yamaps_display_options][display_type]"]' => [
              'value' => 'map_button',
            ],
          ],
        ],
      ];
      $element['controls'] = [
        '#title' => t('Show controls'),
        '#type' => 'checkbox',
        '#default_value' => $settings['controls'],
      ];
      $element['traffic'] = [
        '#title' => t('Show traffic'),
        '#type' => 'checkbox',
        '#default_value' => $settings['traffic'],
      ];
      $element['clusterer'] = [
        '#title' => t('Use clusterer'),
        '#type' => 'checkbox',
        '#default_value' => $settings['clusterer'],
      ];
      $element['auto_zoom'] = [
        '#title' => t('Auto zoom'),
        '#type' => 'checkbox',
        '#default_value' => $settings['auto_zoom'],
      ];
      $element['enable_polygons'] = [
        '#title' => t('Enable polygons'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_polygons'],
      ];
      $element['enable_routes'] = [
        '#title' => t('Enable routes'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_routes'],
      ];
      $element['enable_lines'] = [
        '#title' => t('Enable lines'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_lines'],
      ];
      $element['enable_placemarks'] = [
        '#title' => t('Enable placemarks'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_placemarks'],
      ];
      $element['behaviors'] = [
        '#title' => t('Available mouse events'),
        '#type' => 'checkboxes',
        '#options' => yamaps_get_behaviors_list(),
        '#default_value' => $settings['behaviors'],
      ];
      $element['width'] = [
        '#title' => t('Map width'),
        '#field_suffix' => ' ' . t('in pixels or in percentage'),
        '#type' => 'textfield',
        '#default_value' => $settings['width'],
        '#size' => 5,
        '#element_validate' => [
          'yamaps_field_validate_pixels_percentage',
        ],
        '#required' => TRUE,
      ];
      $element['height'] = [
        '#title' => t('Map height'),
        '#field_suffix' => ' ' . t('in pixels or in percentage'),
        '#type' => 'textfield',
        '#default_value' => $settings['height'],
        '#size' => 5,
        '#element_validate' => [
          'yamaps_field_validate_pixels_percentage',
        ],
        '#required' => TRUE,
      ];
      break;
    case YAMAPS_TEXT_FORMATTER:
      $element['width'] = [
        '#title' => t('Map width'),
        '#field_suffix' => ' ' . t('in pixels or in percentage'),
        '#type' => 'textfield',
        '#default_value' => $settings['width'],
        '#size' => 5,
        '#element_validate' => [
          'yamaps_field_validate_pixels_percentage',
        ],
        '#required' => TRUE,
      ];
      $element['behaviors'] = [
        '#title' => t('Available mouse events'),
        '#type' => 'checkboxes',
        '#options' => yamaps_get_behaviors_list(),
        '#default_value' => $settings['behaviors'],
      ];
      $element['height'] = [
        '#title' => t('Map height'),
        '#field_suffix' => ' ' . t('in pixels or in percentage'),
        '#type' => 'textfield',
        '#default_value' => $settings['height'],
        '#size' => 5,
        '#element_validate' => [
          'yamaps_field_validate_pixels_percentage',
        ],
        '#required' => TRUE,
      ];

      // Placemark options.
      $element['placemark'] = [
        '#title' => t('Placemark options'),
        '#type' => 'fieldset',
      ];
      $element['placemark']['placemark_display'] = [
        '#type' => 'checkbox',
        '#title' => t('Show placemark?'),
        '#default_value' => $settings['placemark']['placemark_display'],
      ];
      $element['placemark']['placemark_text'] = [
        '#type' => 'textfield',
        '#title' => t('Placemark text'),
        '#description' => t('Print <strong>[address]</strong> to display address from the field'),
        '#states' => [
          'visible' => [
            ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][placemark][placemark_display]"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
        '#default_value' => $settings['placemark']['placemark_text'],
      ];
      $options = [];
      foreach (array_keys(yamaps_get_colors()) as $color) {
        $options[$color] = t($color);
      }
      $element['placemark']['placemark_color'] = [
        '#title' => 'Placemark color',
        '#type' => 'radios',
        '#options' => $options,
        '#states' => [
          'visible' => [
            ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][placemark][placemark_display]"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
        '#default_value' => $settings['placemark']['placemark_color'],
      ];
      $element['control'] = [
        '#title' => t('Enable control'),
        '#type' => 'checkbox',
        '#default_value' => $settings['control'],
      ];
      $element['traffic'] = [
        '#type' => 'checkbox',
        '#title' => t('Show traffic?'),
        '#default_value' => $settings['traffic'],
      ];
      $element['clusterer'] = [
        '#type' => 'checkbox',
        '#title' => t('Use clusterer?'),
        '#default_value' => $settings['clusterer'],
      ];
      $element['auto_zoom'] = [
        '#type' => 'checkbox',
        '#title' => t('Auto zoom'),
        '#default_value' => $settings['auto_zoom'],
      ];
      $element['enable_polygons'] = [
        '#title' => t('Enable polygons'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_polygons'],
      ];
      $element['enable_routes'] = [
        '#title' => t('Enable routes'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_routes'],
      ];
      $element['enable_lines'] = [
        '#title' => t('Enable lines'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_lines'],
      ];
      $element['enable_placemarks'] = [
        '#title' => t('Enable placemarks'),
        '#type' => 'checkbox',
        '#default_value' => $settings['enable_placemarks'],
      ];
      break;
    case YAMAPS_STATIC_FORMATTER:
      $element['yamaps_display_options_static']['display_type_static'] = [
        '#type' => 'radios',
        '#title' => t('Map display style for end user'),
        '#options' => [
          'map' => t('Map'),
          'map_button' => t('Map opened by button click'),
        ],
        '#default_value' => $settings['yamaps_display_options_static']['display_type_static'],
        '#required' => FALSE,
        '#description' => t('Configure how to display "Yandex Map" field for end user.'),
      ];
      $element['yamaps_display_options_static']['open_button_text_static'] = [
        '#type' => 'textfield',
        '#title' => t('"Open" button text'),
        '#default_value' => $settings['yamaps_display_options_static']['open_button_text_static'],
        '#required' => FALSE,
        '#description' => t('Text of button that opens map for end user.'),
        '#states' => [
          'visible' => [
            ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][yamaps_display_options_static][display_type_static]"]' => [
              'value' => 'map_button',
            ],
          ],
        ],
      ];
      $element['yamaps_display_options_static']['close_button_text_static'] = [
        '#type' => 'textfield',
        '#title' => t('"Close" button text'),
        '#default_value' => isset($settings['yamaps_display_options_static']['close_button_text_static']) ? $settings['yamaps_display_options_static']['close_button_text_static'] : t(YAMAPS_DEFAULT_CLOSE_MAP_TEXT),
        '#required' => FALSE,
        '#description' => t('Text of button that closes map for end user.'),
        '#states' => [
          'visible' => [
            ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][yamaps_display_options_static][display_type_static]"]' => [
              'value' => 'map_button',
            ],
          ],
        ],
      ];
      $element['s_traffic'] = [
        '#title' => t('Show traffic'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_traffic'],
      ];
      $element['s_clusterer'] = [
        '#title' => t('Use clusterer'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_clusterer'],
      ];
      $element['s_auto_zoom'] = [
        '#title' => t('Auto zoom'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_auto_zoom'],
      ];
      $element['s_enable_polygons'] = [
        '#title' => t('Enable polygons'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_enable_polygons'],
      ];
      $element['s_enable_routes'] = [
        '#title' => t('Enable routes'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_enable_routes'],
      ];
      $element['s_enable_lines'] = [
        '#title' => t('Enable lines'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_enable_lines'],
      ];
      $element['s_enable_placemarks'] = [
        '#title' => t('Enable placemarks'),
        '#type' => 'checkbox',
        '#default_value' => $settings['s_enable_placemarks'],
      ];
      $element['s_width'] = [
        '#title' => t('Map width'),
        '#field_suffix' => ' ' . t('pixels'),
        '#type' => 'textfield',
        '#default_value' => $settings['s_width'],
        '#size' => 5,
        '#element_validate' => [
          'element_validate_integer_positive',
        ],
        '#required' => TRUE,
      ];
      $element['s_height'] = [
        '#title' => t('Map height'),
        '#field_suffix' => ' ' . t('pixels'),
        '#type' => 'textfield',
        '#default_value' => $settings['s_height'],
        '#size' => 5,
        '#element_validate' => [
          'element_validate_integer_positive',
        ],
        '#required' => TRUE,
      ];
      break;
  }
  return $element;
}