You are here

function yamaps_settings_page in Yandex.Maps 7

Form builder for admin settings form.

1 string reference to 'yamaps_settings_page'
yamaps_menu in ./yamaps.module
Implements hook_menu().

File

./yamaps.admin.inc, line 11
Yandex Maps Admin UI file.

Code

function yamaps_settings_page($form, &$form_state) {
  $form['yamaps_api_key'] = [
    '#title' => t('API key for Yandex.Maps API'),
    '#type' => 'textfield',
    '#default_value' => variable_get('yamaps_api_key', ''),
    '#required' => TRUE,
    '#description' => t('Since Yandex changed access to their API we have to send API key. You can get API key !api_link. More info you can find !here', [
      '!api_link' => l(t('here'), 'https://developer.tech.yandex.ru'),
      '!here' => l(t('here'), 'https://yandex.ru/blog/mapsapi/novye-pravila-dostupa-k-api-kart'),
    ]),
  ];

  // Set amount of blocks admin can create.
  $form['yamaps_blocks_amount'] = [
    '#title' => t('Set amount of Yandex Maps blocks'),
    '#description' => t('Amount of Yandex Maps blocks available on !blocks_page.', [
      '!blocks_page' => l(t('Blocks page'), 'admin/structure/block'),
    ]),
    '#element_validate' => [
      'element_validate_integer_positive',
    ],
    '#type' => 'textfield',
    '#maxlength' => 2,
    '#default_value' => variable_get('yamaps_blocks_amount', YAMAPS_DEFAULT_BLOCK_AMOUNT),
    '#required' => TRUE,
  ];
  $display_options = variable_get('yamaps_block_edit_display_options', []);

  // Container for display options.
  $form['yamaps_block_edit_display_options'] = [
    '#type' => 'fieldset',
    '#title' => t('Display options'),
    '#tree' => TRUE,
  ];

  // Display options.
  $form['yamaps_block_edit_display_options']['display_type'] = [
    '#type' => 'radios',
    '#title' => t('Map display style in admin UI for blocks'),
    '#options' => [
      'map' => t('Map'),
      'map_button' => t('Map opened by button click'),
    ],
    '#default_value' => isset($display_options['display_type']) ? $display_options['display_type'] : 'map',
    '#required' => FALSE,
    '#description' => t('Configure how to display "Yandex Map" field while creating new / updating blocks.
    This setting applies to admin UI only. To display map opening in block by button click for end users select
    appropriate option in "Map display style for end users" section of the appropriate block.'),
  ];

  // Text on button that opens map by click.
  $form['yamaps_block_edit_display_options']['open_button_text'] = [
    '#type' => 'textfield',
    '#title' => t('"Open" button text'),
    '#default_value' => isset($display_options['open_button_text']) ? t($display_options['open_button_text']) : t(YAMAPS_DEFAULT_OPEN_MAP_TEXT),
    '#required' => FALSE,
    '#description' => t('Specify text to display on the button opening map in case of "Map opened by button click" option.
    This setting applies to admin UI only. To configure text on the button opening map for end users select appropriate
    option in "Manage Display" section of the appropriate block.'),
    '#states' => [
      'visible' => [
        ':input[name="yamaps_block_edit_display_options[display_type]"]' => [
          'value' => 'map_button',
        ],
      ],
    ],
  ];

  // Text on button that closes map by click.
  $form['yamaps_block_edit_display_options']['close_button_text'] = [
    '#type' => 'textfield',
    '#title' => t('"Close" button text'),
    '#default_value' => isset($display_options['close_button_text']) ? t($display_options['close_button_text']) : t(YAMAPS_DEFAULT_CLOSE_MAP_TEXT),
    '#required' => FALSE,
    '#description' => t('Specify text to display on the button closing map in case of "Map opened by button click" option.
    This setting applies to admin UI only. To configure text on the button closing map for end users select appropriate
    option in "Manage Display" section of the appropriate block.'),
    '#states' => [
      'visible' => [
        ':input[name="yamaps_block_edit_display_options[display_type]"]' => [
          'value' => 'map_button',
        ],
      ],
    ],
  ];
  $form['yamaps_block_edit_display_options']['width'] = [
    '#title' => t('Map width in admin UI'),
    '#field_suffix' => ' ' . t('in pixels (px) or percentage (%).'),
    '#type' => 'textfield',
    '#default_value' => isset($display_options['width']) ? $display_options['width'] : YAMAPS_DEFAULT_ADMIN_UI_MAP_WIDTH,
    '#size' => 5,
    '#element_validate' => [
      'yamaps_field_validate_pixels_percentage',
    ],
    '#required' => TRUE,
    '#description' => t('Set width for the map in "block edit" form.'),
  ];
  $form['yamaps_block_edit_display_options']['height'] = [
    '#title' => t('Map height in admin UI'),
    '#field_suffix' => ' ' . t('in pixels (px) or percentage (%).'),
    '#type' => 'textfield',
    '#default_value' => isset($display_options['height']) ? $display_options['height'] : YAMAPS_DEFAULT_ADMIN_UI_MAP_HEIGHT,
    '#size' => 5,
    '#element_validate' => [
      'yamaps_field_validate_pixels_percentage',
    ],
    '#required' => TRUE,
    '#description' => t('Set height for the map in "block edit" form.'),
  ];
  return system_settings_form($form);
}