You are here

function slick_get_admin_assets in Slick Carousel 7.2

Same name and namespace in other branches
  1. 7.3 includes/slick.admin.inc \slick_get_admin_assets()

Returns reusable logic, styling and assets across Slick fields and Views.

1 call to slick_get_admin_assets()
_slick_fields_field_formatter_settings_form in slick_fields/includes/slick_fields.formatters.admin.inc
Off-loaded hook_field_formatter_settings_form().

File

includes/slick.admin.inc, line 854
Contains optional functions called only if needed by admin pages.

Code

function slick_get_admin_assets(array &$elements, $settings = array()) {
  $excludes = array(
    'container',
    'fieldset',
    'item',
    'hidden',
  );
  $admin_css = variable_get('slick_admin_css', TRUE);
  foreach (element_children($elements) as $key) {
    if (isset($elements[$key]['#type']) && !in_array($elements[$key]['#type'], $excludes)) {
      if (!isset($elements[$key]['#default_value']) && isset($settings[$key])) {
        $elements[$key]['#default_value'] = $settings[$key];
      }
      if (!isset($elements[$key]['#attributes']) && isset($elements[$key]['#description'])) {
        $elements[$key]['#attributes'] = array(
          'class' => array(
            'is-tooltip',
          ),
        );
      }
      if ($admin_css) {
        if ($elements[$key]['#type'] == 'checkbox' && $elements[$key]['#type'] != 'checkboxes') {
          $elements[$key]['#field_suffix'] = '';
          $elements[$key]['#title_display'] = 'before';
        }
        elseif ($elements[$key]['#type'] == 'checkboxes' && !empty($elements[$key]['#options'])) {
          foreach ($elements[$key]['#options'] as $i => $option) {
            $elements[$key][$i]['#field_suffix'] = '';
            $elements[$key][$i]['#title_display'] = 'before';
          }
        }
      }
      if ($elements[$key]['#type'] == 'select' && $key != 'optionset') {
        if (!isset($elements[$key]['#empty_option']) && !isset($elements[$key]['#required'])) {
          $elements[$key]['#empty_option'] = t('- None -');
        }
      }
    }
  }
  if ($admin_css) {
    if (module_exists('slick_ui')) {
      $elements['#attached']['library'][] = array(
        'slick_ui',
        'slick.ui',
      );
    }
    else {
      $slick_path = drupal_get_path('module', 'slick');
      $elements['#attached']['css'] = array(
        $slick_path . '/css/admin/slick.admin--ui.css' => array(
          'group' => CSS_THEME + 1,
        ),
        $slick_path . '/css/admin/slick.admin--ui--field.css' => array(
          'group' => CSS_THEME + 1,
        ),
      );
      $elements['#attached']['js'][] = $slick_path . '/js/slick.admin.ui.min.js';
    }
  }
  drupal_alter('slick_admin_assets_info', $elements, $settings);
}