function _linkicon_field_formatter_settings_form in Link Icon 7
Implements hook_field_formatter_settings_form().
1 call to _linkicon_field_formatter_settings_form()
File
- includes/
linkicon.admin.inc, line 11 - Provides admin related functions.
Code
function _linkicon_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$path = drupal_get_path('module', 'linkicon');
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$elements = array();
$elements['linkicon_prefix'] = array(
'#type' => 'textfield',
'#title' => t('Icon prefix class'),
'#description' => t('A "prefix" or "namespace", e.g.: icon (Fontello), fa (FontAwesome), st-icon (Stackicons), genericon, fonticon, etc. <br />If the link title is <em>Facebook</em>, it will create classes: <em>icon icon-facebook</em> for Fontello, or <em>fa fa-facebook</em> for FontAwesome > 3. <br />The individual icon class itself is based on the link title key matching the pattern: icon-KEY, or fa-KEY.<br />To add classes for the A tag, such as button, external, etc, use the widget settings instead. <br />If icon API present and integration used, it will be ignored and managed/overriden by icon API.'),
'#required' => TRUE,
);
$elements['linkicon_wrapper_class'] = array(
'#type' => 'textfield',
'#title' => t('Additional wrapper class'),
'#description' => t('Additional wrapper class for the entire icon list.'),
);
$elements['linkicon_icon_class'] = array(
'#type' => 'textfield',
'#title' => t('Additional icon classes'),
'#description' => t('Additional icon class for the actual icon apart from <strong>linkicon__icon icon</strong> separated by spaces, e.g: fab fas far.'),
);
$elements['linkicon_load'] = array(
'#type' => 'checkbox',
'#title' => t('Allow linkicon to provide CSS assets'),
'#description' => t('Otherwise, DIY accordingly.'),
);
$elements['linkicon_vertical'] = array(
'#type' => 'checkbox',
'#title' => t('Vertical'),
'#description' => t('By default, icons are displayed inline. Check to make icons stacked vertically.'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['linkicon_style'] = array(
'#type' => 'select',
'#title' => t('Icon style'),
'#options' => array(
'round' => t('Round'),
'round-2' => t('Round 2'),
'round-5' => t('Round 5'),
'round-8' => t('Round 8'),
'round-10' => t('Round 10'),
'square' => t('Square'),
'button' => t('Button'),
),
'#empty_option' => t('- None -'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
'#description' => t('Button is more prominent if the title text is not hidden over the background color.'),
);
$elements['linkicon_color'] = array(
'#type' => 'select',
'#title' => t('Icon background color'),
'#options' => array(
'grey' => t('Grey'),
'dark' => t('Dark'),
'purple' => t('Purple'),
'orange' => t('Orange'),
'blue' => t('Blue'),
'lime' => t('Lime'),
'red' => t('Red'),
),
'#empty_option' => t('- None -'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
'#description' => t('Basic background color. You should do proper theming to suit your design better, and disable all this.'),
);
$elements['linkicon_tooltip'] = array(
'#type' => 'checkbox',
'#title' => t('Display title as tooltip'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['linkicon_no_text'] = array(
'#type' => 'checkbox',
'#title' => t('Visually hide the title text'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['linkicon_maxlength'] = array(
'#type' => 'textfield',
'#title' => t('The title and tooltip maxlength'),
'#description' => t('Limit the amount of characters if using token replacement for the title and tooltip as defined at the widget settings, default to 60 characters.'),
'#size' => 6,
'#maxlength' => 3,
);
$elements['linkicon_global_title'] = array(
'#type' => 'textfield',
'#title' => t('Override title with a generic link title'),
'#description' => t('If provided, the link title will be overriden with this text, e.g.: Visit the site, View Demo.'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_no_text"]' => array(
'checked' => FALSE,
),
),
),
);
$elements['linkicon_position'] = array(
'#type' => 'select',
'#title' => t('Icon position to the title text'),
'#description' => t('By default icon is before the text.'),
'#options' => array(
'bottom' => t('Bottom'),
'right' => t('Right'),
'top' => t('Top'),
),
'#empty_option' => t('Left'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_no_text"]' => array(
'checked' => FALSE,
),
),
),
);
$icon_sizes = array(
'small' => t('Small'),
'medium' => t('Medium'),
'large' => t('Large'),
'xlarge' => t('X-large'),
'xxlarge' => t('Xx-large'),
);
$elements['linkicon_size'] = array(
'#type' => 'select',
'#title' => t('Icon font size'),
'#options' => $icon_sizes,
'#empty_option' => t('Default'),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['linkicon_font'] = array(
'#type' => 'textfield',
'#title' => t('Path to font icon CSS file'),
'#description' => t('Valid path to CSS file, e.g.: sites/all/libraries/fontello/css/fontello.css. <br />Leave blank if your theme has already had one. Overriden if Icon API preferred, or if the prefix matches one, e.g.: fontawesome.module. <br />Please be aware of possible conflicts if you installed different icon fonts <br />due to their namespace collision. Most icon fonts tend to make use the same .icon:before.'),
'#element_validate' => array(
'_linkicon_element_validate_font_path',
),
'#states' => array(
'visible' => array(
':input[name*="linkicon_load"]' => array(
'checked' => TRUE,
),
),
),
);
// Build a preview.
if (function_exists('icon_bundles')) {
$providers = icon_providers();
$provider_options = array();
foreach ($providers as $provider) {
$provider_options[$provider['name']] = $provider['title'];
}
// @todo filter by status flag
if ($provider_options) {
$elements['linkicon_bundle'] = array(
'#type' => 'select',
'#title' => t('Icon module integration'),
'#options' => $provider_options,
'#description' => t('The above icon module providers are detected. You can choose which icon CSS file to load with this module. <br />Make sure that you have a working module that loads relevant CSS accordingly. <br />Known working modules as of this writing: fontawesome, and icomoon. This integration is optional.'),
'#empty_option' => t('- None -'),
);
}
}
$config = linkicon_simplify_settings($settings);
$config['_preview'] = TRUE;
$config['id'] = 'linkicon-preview';
if (!empty($config['bundle']) || !empty($config['font']) || module_exists('fontawesome')) {
$prefix_class = check_plain($config['prefix']);
$icon_previews = array();
$linkicon_item = array(
'#theme' => 'linkicon_item',
'#title' => 'Twitter',
'#icon_name' => 'twitter',
'#settings' => $config,
);
$icon = drupal_render($linkicon_item);
$tooltip = '';
if ($config['tooltip']) {
$tooltip = ' data-title="Twitter"';
}
foreach ($icon_sizes as $key => $size) {
$is_active = $key == $config['size'] ? ' active' : '';
$icon_previews[] = array(
'#markup' => '<a class="linkicon__item linkicon--' . $key . $is_active . '" href="#"' . $tooltip . '>' . $icon . '</a>',
);
}
$preview = array(
'#theme' => 'linkicon',
'#items' => $icon_previews,
'#config' => $config,
);
if ($config['load']) {
$preview['#attached']['css'][] = array(
'data' => $path . '/css/linkicon.css',
);
if ($config['font'] && empty($config['bundle'])) {
$preview['#attached']['css'][] = array(
'data' => strip_tags($config['font']),
);
}
}
$elements['linkicon_size_preview'] = array(
'#markup' => drupal_render($preview),
);
}
$defaults = linkicon_defaults();
foreach (element_children($elements) as $element) {
if (isset($elements[$element]['#type']) && !isset($elements[$element]['#default_value'])) {
$default = isset($defaults[$element]) ? $defaults[$element] : '';
$elements[$element]['#default_value'] = isset($settings[$element]) ? $settings[$element] : $default;
}
}
return $elements;
}