You are here

function _linkicon_field_widget_settings_form_alter in Link Icon 7

Alters the existing link field widget settings form elements.

1 call to _linkicon_field_widget_settings_form_alter()
linkicon_field_widget_settings_form_alter in ./linkicon.module
Alters the existing link field widget settings form elements.

File

includes/linkicon.admin.inc, line 308
Provides admin related functions.

Code

function _linkicon_field_widget_settings_form_alter(&$form, $settings) {
  if ($form['widget']['type']['#value'] == 'link_field') {
    $form['settings']['title']['#options'] += array(
      'predefined' => t('Predefined Title'),
    );

    // Avoid confusing static title by disabling it if predefined is selected.
    // We don't want to hide it so to have immediate awareness of this option.
    $form['settings']['title_value']['#states'] = array(
      'disabled' => array(
        ':input[name="instance[settings][title]"]' => array(
          'value' => 'predefined',
        ),
      ),
    );

    // Insert our extra option after title.
    $new_form['settings'] = array();
    foreach ($form['settings'] as $key => $value) {
      if ($key == 'title_value') {
        $new_form['settings']['title_predefined'] = array(
          '#type' => 'textarea',
          '#title' => t('Allowed titles'),
          '#default_value' => isset($settings['title_predefined']) ? $settings['title_predefined'] : '',
          '#description' => t('Enter the list of key|value pairs of predefined titles separated by new line, where key is the icon name without prefix, e.g.: <br />for <em>icon-facebook</em>, place <em>facebook|Facebook</em>. The prefix is defined at Display formatter so that you are not stuck in database when the icon vendor change prefixes from "icon-" to just "fa-", etc. Make sure the icon name is available at your icon set. To have a tooltip different from the title, add a third pipe value.<br />Warning! Pre-existing values will be reset. Token is supported for title and tooltip. Use the "Browse available tokens." under "Allow user-entered tokens" below if token module installed.'),
          '#states' => array(
            'visible' => array(
              ':input[name="instance[settings][title]"]' => array(
                'value' => 'predefined',
              ),
            ),
          ),
        );
      }
      $new_form['settings'][$key] = $value;
    }

    // Replace $form['settings'] with new form.
    $form['settings'] = $new_form['settings'];
  }
}