/** * {@inheritdoc} */ public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) { /** @var \Drupal\tour\TourInterface[] $entities */ $build = array(); foreach ($entities as $entity_id => $entity) { $tips = $entity->getTips(); $count = count($tips); $list_items = array(); foreach ($tips as $index => $tip) { if ($output = $tip->getOutput()) { $attributes = array('class' => array('tip-module-' . drupal_clean_css_identifier($entity->get('module')), 'tip-type-' . drupal_clean_css_identifier($tip->get('plugin')), 'tip-' . drupal_clean_css_identifier($tip->get('id')))); $list_items[] = array('output' => $output, 'counter' => array('#type' => 'container', '#attributes' => array('class' => array('tour-progress')), '#children' => t('!tour_item of !total', array('!tour_item' => $index + 1, '!total' => $count))), '#wrapper_attributes' => $tip->getAttributes() + $attributes); } } // If there is at least one tour item, build the tour. if ($list_items) { end($list_items); $key = key($list_items); $list_items[$key]['#wrapper_attributes']['data-text'] = t('End tour'); $build[$entity_id] = array('#theme' => 'item_list', '#items' => $list_items, '#list_type' => 'ol', '#attributes' => array('id' => 'tour', 'class' => array('hidden')), '#cache' => ['tags' => $entity->getCacheTags()]); } } // If at least one tour was built, attach the tour library. if ($build) { $build['#attached']['library'][] = 'tour/tour'; } return $build; }
function masthead_preprocess_html(&$vars) { $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach ($aliases as $alias) { $vars['classes_array'][] = drupal_clean_css_identifier($alias); } }
function danbury_preprocess_html(&$variables) { $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach ($aliases as $alias) { $variables['classes_array'][] = 'path-' . drupal_clean_css_identifier($alias); } }
/** * Implement da_vinci_preprocess_user_profile(). */ function da_vinci_preprocess_user_profile(&$vars) { if (!empty($vars['elements']['#view_mode'])) { // Add suggestion for user entity view modes: $vars['theme_hook_suggestions'][] = 'user_profile__' . $vars['elements']['#view_mode']; // Add view-mode class: $vars['classes_array'][] = 'user-' . drupal_clean_css_identifier($vars['elements']['#view_mode']); } }
/** * Preprocessor for theme('html') * * @see html.tpl.php */ function apigee_bootstrap_preprocess_html(&$vars) { // Add some additional body classes based on path $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach ($aliases as $alias) { $vars['classes_array'][] = drupal_clean_css_identifier($alias); } }
function templateName_preprocess_html(&$variables) { $node = node_load(arg(1)); $results = taxonomy_node_get_terms($node); if (is_array($results)) { foreach ($results as $item) { $variables['classes_array'][] = "taxonomy-" . strtolower(drupal_clean_css_identifier($item->name)); } } }
/** * {@inheritdoc} */ public function getId() { if (!isset($this->id)) { $css_map_name = drupal_clean_css_identifier($this->getMachineName()); // Use uniqid to ensure we've really an unique id - otherwise there will // occur issues with caching. $this->id = drupal_html_id('openlayers-map-' . $css_map_name . '-' . uniqid('', TRUE)); } return $this->id; }
/** * Override or insert variables into the html template. * * @param $vars * An array of variables to pass to the theme template. */ function jbase_preprocess_html(&$vars) { // give <body> tag a unique class depending on PATHs $path_alias = strtolower(drupal_clean_css_identifier(drupal_get_path_alias($_GET['q']))); if ($path_alias == 'node') { $vars['classes_array'][] = ''; } else { $vars['classes_array'][] = 'path-' . $path_alias; } // Add to the array of body classes // layout classes $vars['classes_array'][] = 'layout-' . (!empty($vars['page']['sidebar_first']) ? 'first-main' : 'main') . (!empty($vars['page']['sidebar_second']) ? '-second' : ''); // headers classes if (!empty($vars['page']['header_first']) || !empty($vars['page']['header_second']) || !empty($vars['page']['header_third'])) { $header_regions = 'header'; $header_regions .= !empty($vars['page']['header_first']) ? '-first' : ''; $header_regions .= !empty($vars['page']['header_second']) ? '-second' : ''; $header_regions .= !empty($vars['page']['header_third']) ? '-third' : ''; $vars['classes_array'][] = $header_regions; } // preface classes if (!empty($vars['page']['preface_first']) || !empty($vars['page']['preface_second']) || !empty($vars['page']['preface_third'])) { $preface_regions = 'preface'; $preface_regions .= !empty($vars['page']['preface_first']) ? '-first' : ''; $preface_regions .= !empty($vars['page']['preface_second']) ? '-second' : ''; $preface_regions .= !empty($vars['page']['preface_third']) ? '-third' : ''; $vars['classes_array'][] = $preface_regions; } // postscripts classes if (!empty($vars['page']['postscript_first']) || !empty($vars['page']['postscript_second']) || !empty($vars['page']['postscript_third'])) { $postscript_regions = 'postscript'; $postscript_regions .= !empty($vars['page']['postscript_first']) ? '-first' : ''; $postscript_regions .= !empty($vars['page']['postscript_second']) ? '-second' : ''; $postscript_regions .= !empty($vars['page']['postscript_third']) ? '-third' : ''; $vars['classes_array'][] = $postscript_regions; } // footers classes if (!empty($vars['page']['footer_first']) || !empty($vars['page']['footer_second']) || !empty($vars['page']['footer_third'])) { $footer_regions = 'footers'; $footer_regions .= !empty($vars['page']['footer_first']) ? '-first' : ''; $footer_regions .= !empty($vars['page']['footer_second']) ? '-second' : ''; $footer_regions .= !empty($vars['page']['footer_third']) ? '-third' : ''; $vars['classes_array'][] = $footer_regions; } // Panels classes $vars['classes_array'][] = module_exists('panels') && panels_get_current_page_display() ? 'panels' : ''; if (module_exists('panels') && panels_get_current_page_display()) { $panels_display = panels_get_current_page_display(); $vars['classes_array'][] = 'panels-' . strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $panels_display->layout)); } $vars['classes_array'] = array_filter($vars['classes_array']); // IE stylesheets drupal_add_css(path_to_theme() . '/css/ie7-fixes.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 7', '!IE' => FALSE), 'preprocess' => FALSE)); drupal_add_css(path_to_theme() . '/css/ie8-fixes.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 8', '!IE' => FALSE), 'preprocess' => FALSE)); }
function zeven_preprocess_html(&$vars) { # add role-class in body tag if ($vars['user']) { foreach ($vars['user']->roles as $key => $role) { $role_class = 'role-' . drupal_clean_css_identifier($role); $role_class = strtolower($role_class); $vars['classes_array'][] = $role_class; } } }
/** * Return the token-replaced row or column classes for the specified result. * * @param int $result_index * The delta of the result item to get custom classes for. * @param string $type * The type of custom grid class to return, either "row" or "col". * * @return string * A space-delimited string of classes. */ public function getCustomClass($result_index, $type) { $class = $this->options[$type . '_class_custom']; if ($this->usesFields() && $this->view->field) { $class = strip_tags($this->tokenizeValue($class, $result_index)); } $classes = explode(' ', $class); foreach ($classes as &$class) { $class = drupal_clean_css_identifier($class); } return implode(' ', $classes); }
/** * Add Page Body Class * Add Custom Title to Home Page * @param $vars */ function masthead_preprocess_html(&$vars) { $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach ($aliases as $alias) { $vars['classes_array'][] = drupal_clean_css_identifier($alias); } if (drupal_is_front_page() == TRUE) { $site_name = variable_get('site_name', 'Drupal'); $vars['head_title'] = 'Home | ' . $site_name; } }
/** * Implements theme_preprocess_page(). */ function townsquare_bootstrap_preprocess_page(&$vars) { global $user; $vars['primary_local_tasks'] = menu_primary_local_tasks(); $vars['secondary_local_tasks'] = menu_secondary_local_tasks(); // The following menu stuff is lame foreach ($vars['main_menu'] as $item => $options) { $vars['main_menu'][$item]['html'] = TRUE; $vars['main_menu'][$item]['attributes']['id'] = 'menu-link-' . drupal_clean_css_identifier($options['href']); } $admin_menu = menu_tree_all_data('management'); $children = array_pop($admin_menu); if ($children) { foreach ($children['below'] as $key => $value) { $children['below'][$key]['below'] = array(); } $vars['admin_menu'] = menu_tree_output($children['below']); } // Add user picture if logged in if ($user->uid) { $vars['user_name'] = check_plain($user->name); if (!empty($user->picture)) { if (is_numeric($user->picture)) { $user->picture = file_load($user->picture); } if (!empty($user->picture->uri)) { $filepath = $user->picture->uri; } } elseif (variable_get('user_picture_default', '')) { $filepath = variable_get('user_picture_default', ''); } if (isset($filepath)) { $alt = t("@user's picture", array('@user' => format_username($user))); if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style', ''))) { $vars['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt)); } else { $vars['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt)); } } else { $vars['user_picture'] = '<i class="icon-user"></i>'; } } else { unset($vars['secondary_menu']); $vars['login'] = drupal_get_form('user_login_block'); } // Add Bootstrap $path = libraries_get_path('bootstrap'); drupal_add_css($path . '/css/bootstrap.css'); drupal_add_css($path . '/css/bootstrap-responsive.css'); drupal_add_js($path . '/js/bootstrap.js'); $path = libraries_get_path('font-awesome'); drupal_add_css($path . '/css/font-awesome.css'); }
/** * @param $vars */ function cni_preprocess_html(&$vars) { $base_path = base_path(); $conf_path = conf_path(); $site_css = $base_path . $conf_path . '/cni-site.css'; if (file_exists($_SERVER['DOCUMENT_ROOT'] . $site_css)) { drupal_add_css($site_css, array('type' => 'file', 'media' => 'all', 'preprocess' => false, 'every_page' => true, 'weight' => 999, 'group' => CSS_THEME)); } /* Add Page Body Class */ $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach ($aliases as $alias) { $vars['classes_array'][] = drupal_clean_css_identifier($alias); } }
function standardcommunitychurch_preprocess_html(&$vars) { $path = drupal_get_path_alias(); $aliases = explode('/', $path); foreach ($aliases as $alias) { $vars['classes_array'][] = drupal_clean_css_identifier('alias-' . $alias); } $viewport = array('#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1, maximum-scale=1')); drupal_add_html_head($viewport, 'viewport'); if (drupal_is_front_page()) { drupal_add_js(path_to_theme() . '/js/home.js', array('group' => JS_THEME, 'type' => 'file', 'scope' => 'footer')); drupal_add_css(path_to_theme() . '/css/vendor/flexslider.css', array('group' => CSS_SYSTEM, 'type' => 'file')); drupal_add_js(path_to_theme() . '/js/vendor/jquery.flexslider-min.js', array('group' => JS_LIBRARY, 'type' => 'file', 'scope' => 'footer')); } }
/** * Implements hook_preprocess_panels_pane(). */ function drupalmel_theme_preprocess_semantic_panels_pane(&$variables) { switch ($variables['pane']->subtype) { // Add <span> to site name string. case 'blockify-blockify-site-name': preg_match_all('/([A-Z][a-z]+|[0-9]+)/', variable_get('site_name', NULL), $parts); $name = ''; if (isset($parts[1])) { foreach ($parts[1] as $delta => $part) { $id = drupal_clean_css_identifier($part); $name .= '<span class="part-' . $delta . ' part-' . $id . '">' . filter_xss($part) . '</span>'; } } $variables['content_html'] = str_replace('<span>' . variable_get('site_name', NULL) . '</span>', $name, $variables['content_html']); break; } }
/** * @param $vars */ function cni_preprocess_html(&$vars) { /* Add Page Body Class */ $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach ($aliases as $alias) { $vars['classes_array'][] = drupal_clean_css_identifier($alias); } /* * Hide Log In link from logged in users * A call to hook_menu_alter in etype.module does not do the trick */ global $user; if ($user->uid > 0) { drupal_add_js(drupal_get_path('theme', 'cni') . '/js/user-menu.js', 'file'); } }
/** * Tests upload and remove buttons for a single-valued File field. */ function testSingleValuedWidget() { $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); $this->createFileField($field_name, 'node', $type_name); $test_file = $this->getTestFile('text'); foreach (array('nojs', 'js') as $type) { // Create a new node with the uploaded file and ensure it got uploaded // successfully. // @todo This only tests a 'nojs' submission, because drupalPostAjaxForm() // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); // Ensure the edit page has a remove button instead of an upload button. $this->drupalGet("node/{$nid}/edit"); $this->assertNoFieldByXPath('//input[@type="submit"]', t('Upload'), 'Node with file does not display the "Upload" button.'); $this->assertFieldByXpath('//input[@type="submit"]', t('Remove'), 'Node with file displays the "Remove" button.'); // "Click" the remove button (emulating either a nojs or js submission). switch ($type) { case 'nojs': $this->drupalPostForm(NULL, array(), t('Remove')); break; case 'js': $button = $this->xpath('//input[@type="submit" and @value="' . t('Remove') . '"]'); $this->drupalPostAjaxForm(NULL, array(), array((string) $button[0]['name'] => (string) $button[0]['value'])); break; } // Ensure the page now has an upload button instead of a remove button. $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'After clicking the "Remove" button, it is no longer displayed.'); $this->assertFieldByXpath('//input[@type="submit"]', t('Upload'), 'After clicking the "Remove" button, the "Upload" button is displayed.'); // Test label has correct 'for' attribute. $label = $this->xpath("//label[@for='edit-" . drupal_clean_css_identifier($field_name) . "-0-upload']"); $this->assertTrue(isset($label[0]), 'Label for upload found.'); // Save the node and ensure it does not have the file. $this->drupalPostForm(NULL, array(), t('Save and keep published')); $node = node_load($nid, TRUE); $this->assertTrue(empty($node->{$field_name}->target_id), 'File was successfully removed from the node.'); } }
/** * Tests that drupal_clean_css_identifier() cleans the identifier properly. */ function testDrupalCleanCSSIdentifier() { // Verify that no valid ASCII characters are stripped from the identifier. $identifier = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'; $this->assertIdentical(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid ASCII characters pass through.'); // Verify that valid UTF-8 characters are not stripped from the identifier. $identifier = '¡¢£¤¥'; $this->assertIdentical(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid UTF-8 characters pass through.'); // Verify that invalid characters (including non-breaking space) are stripped from the identifier. $this->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.'); // Verify that double underscores are not stripped from the identifier. $identifier = 'css__identifier__with__double__underscores'; $this->assertIdentical(drupal_clean_css_identifier($identifier), $identifier, 'Verify double underscores pass through.'); // Verify that an identifier starting with a digit is replaced. $this->assertIdentical(drupal_clean_css_identifier('1cssidentifier', array()), '_cssidentifier', 'Verify identifier starting with a digit is replaced.'); // Verify that an identifier starting with a hyphen followed by a digit is // replaced. $this->assertIdentical(drupal_clean_css_identifier('-1cssidentifier', array()), '__cssidentifier', 'Verify identifier starting with a hyphen followed by a digit is replaced.'); // Verify that an identifier starting with two hyphens is replaced. $this->assertIdentical(drupal_clean_css_identifier('--cssidentifier', array()), '__cssidentifier', 'Verify identifier starting with two hyphens is replaced.'); }
function edit_form(&$form, &$form_state) { parent::edit_form($form, $form_state); $module_path = drupal_get_path('module', 'slick'); $optionset = $form_state['item']; $options = $optionset->options; $form['#attached']['css'][] = $module_path . '/css/admin/slick.admin--ui.css'; $form['#attached']['css'][] = $module_path . '/css/admin/slick.admin--vertical-tabs.css'; $form['#attached']['js'][] = $module_path . '/js/slick.admin.ui.js'; $form['#attributes']['class'][] = 'no-js'; $form['#attributes']['class'][] = 'form--slick'; $form['#attributes']['class'][] = 'form--compact'; $form['#attributes']['class'][] = 'form--optionset'; $form['#attributes']['class'][] = 'clearfix'; $form['info']['label']['#attributes']['class'][] = 'is-tooltip'; $form['info']['name']['#attributes']['class'][] = 'is-tooltip'; $form['info']['label']['#prefix'] = '<div class="form--slick__header has-tooltip clearfix">'; // Skins. $skins = slick_skins(TRUE); $form['skin'] = array('#type' => 'select', '#title' => t('Skin'), '#options' => $skins, '#default_value' => $optionset->skin, '#description' => t('Skins allow swappable layouts like next/prev links, split image and caption, etc. Make sure to provide a dedicated slide layout per field. However a combination of skins and options may lead to unpredictable layouts, get dirty yourself. See main <a href="@skin">README.txt</a> for details on Skins.', array('@skin' => url($module_path . '/README.txt'))), '#attributes' => array('class' => array('is-tooltip'))); $form['breakpoints'] = array('#title' => t('Breakpoints'), '#type' => 'textfield', '#description' => t('The number of breakpoints added to Responsive display.'), '#default_value' => isset($form_state['values']['breakpoints']) ? $form_state['values']['breakpoints'] : $optionset->breakpoints, '#suffix' => '</div>', '#ajax' => array('callback' => 'slick_add_breakpoints_ajax_callback', 'wrapper' => 'breakpoints-ajax-wrapper', 'event' => 'change'), '#attributes' => array('class' => array('is-tooltip'))); // Options. $form['options'] = array('#type' => 'vertical_tabs', '#tree' => TRUE); // Image styles. $image_styles = image_style_options(FALSE); $form['options']['general'] = array('#type' => 'fieldset', '#title' => t('General'), '#attributes' => array('class' => array('has-tooltip', 'fieldset--no-checkboxes-label'))); $form['options']['general']['normal'] = array('#type' => 'select', '#title' => t('Image style'), '#description' => t('Image style for the main/background image, overriden by field. Thumbnails are defined per field basis.'), '#empty_option' => t('None (original image)'), '#options' => $image_styles, '#default_value' => isset($options['general']['normal']) ? $options['general']['normal'] : '', '#attributes' => array('class' => array('is-tooltip'))); /* @todo drop it or test elementTransition.js $form['options']['general']['transition'] = array( '#type' => 'select', '#title' => t('Transition effect'), '#description' => t('Custom CSS3 transition effect.'), '#empty_option' => t('- None -'), '#options' => _slick_transition_options(), '#default_value' => isset($options['general']['transition']) ? $options['general']['transition'] : '', ); */ $form['options']['general']['template_class'] = array('#type' => 'textfield', '#title' => t('Wrapper class'), '#description' => t('Additional template wrapper classes separated by spaces to gain more control per optionset.'), '#default_value' => isset($options['general']['template_class']) ? $options['general']['template_class'] : '', '#attributes' => array('class' => array('is-tooltip'))); $form['options']['general']['goodies'] = array('#type' => 'checkboxes', '#title' => t('Goodies'), '#default_value' => !empty($options['general']['goodies']) ? array_values((array) $options['general']['goodies']) : array(), '#options' => array('pattern' => t('Use pattern overlay'), 'arrow-down' => t('Use arrow down')), '#description' => t('<ol><li>Pattern overlay is background image with pattern placed over the main stage.</li><li>Arrow down to scroll down into a certain page section, make sure to provide target selector.</li></ol>'), '#attributes' => array('class' => array('is-tooltip'))); $form['options']['general']['arrow_down_target'] = array('#type' => 'textfield', '#title' => t('Arrow down target'), '#description' => t('Valid CSS selector to scroll to, e.g.: #main, or #content.'), '#default_value' => isset($options['general']['arrow_down_target']) ? $options['general']['arrow_down_target'] : '', '#states' => array('visible' => array(':input[name*=arrow-down]' => array('checked' => TRUE))), '#attributes' => array('class' => array('is-tooltip'))); $form['options']['general']['arrow_down_offset'] = array('#type' => 'textfield', '#title' => t('Arrow down offset'), '#description' => t('Offset when scrolled down from the top.'), '#default_value' => isset($options['general']['arrow_down_offset']) ? $options['general']['arrow_down_offset'] : '', '#states' => array('visible' => array(':input[name*=arrow-down]' => array('checked' => TRUE))), '#attributes' => array('class' => array('is-tooltip'))); // Add empty suffix to style checkboxes like iOS. foreach ($form['options']['general']['goodies']['#options'] as $key => $value) { $form['options']['general']['goodies'][$key]['#field_suffix'] = ''; $form['options']['general']['goodies'][$key]['#title_display'] = 'before'; } // Main options. $slick_options = slick_get_options(); $form['options']['settings'] = array('#title' => t('Settings'), '#type' => 'fieldset', '#collapsible' => FALSE, '#tree' => TRUE, '#attributes' => array('class' => array('fieldset--settings', 'has-tooltip'))); foreach ($slick_options as $name => $values) { $form['options']['settings'][$name] = array('#title' => $values['title'], '#description' => $values['description'], '#type' => $values['type'], '#default_value' => isset($options['settings'][$name]) ? $options['settings'][$name] : $values['default'], '#attributes' => array('class' => array('is-tooltip'))); if (isset($values['field_suffix'])) { $form['options']['settings'][$name]['#field_suffix'] = $values['field_suffix']; } if ($values['type'] == 'textfield') { $form['options']['settings'][$name]['#size'] = 20; $form['options']['settings'][$name]['#maxlength'] = 255; } if (!isset($values['field_suffix']) && $values['cast'] == 'bool') { $form['options']['settings'][$name]['#field_suffix'] = ''; $form['options']['settings'][$name]['#title_display'] = 'before'; } if ($values['cast'] == 'int') { $form['options']['settings'][$name]['#maxlength'] = 60; $form['options']['settings'][$name]['#attributes']['class'][] = 'form-text--int'; } if (isset($values['states'])) { $form['options']['settings'][$name]['#states'] = $values['states']; } if (isset($values['options'])) { $form['options']['settings'][$name]['#options'] = $values['options']; } if (isset($values['empty_option'])) { $form['options']['settings'][$name]['#empty_option'] = $values['empty_option']; } // Expand textfield for easy edit. if (in_array($name, array('prevArrow', 'nextArrow'))) { $form['options']['settings'][$name]['#attributes']['class'][] = 'js-expandable'; } } // Responsive options. $form['options']['responsives'] = array('#title' => t('Responsive display'), '#type' => 'fieldset', '#description' => t('Containing breakpoints and settings objects. Settings set at a given breakpoint/screen width is self-contained and does not inherit the main settings, but defaults. Currently only supports Desktop first: starts breakpoint from the largest to smallest.'), '#collapsible' => FALSE, '#tree' => TRUE); $form['options']['responsives']['responsive'] = array('#title' => t('Responsive'), '#type' => 'fieldset', '#collapsible' => FALSE, '#attributes' => array('class' => array('has-tooltip', 'fieldset--responsive--ajax')), '#prefix' => '<div id="breakpoints-ajax-wrapper">', '#suffix' => '</div>'); $breakpoints_count = isset($form_state['values']['breakpoints']) ? $form_state['values']['breakpoints'] : $optionset->breakpoints; $form_state['breakpoints_count'] = $breakpoints_count; if ($form_state['breakpoints_count'] > 0) { $slick_options = slick_get_responsive_options($form_state['breakpoints_count']); foreach ($slick_options as $i => $values) { if ($values['type'] == 'fieldset') { $fieldset_class = drupal_clean_css_identifier(drupal_strtolower($values['title'])); $form['options']['responsives']['responsive'][$i] = array('#title' => $values['title'], '#type' => $values['type'], '#collapsible' => TRUE, '#collapsed' => TRUE, '#attributes' => array('class' => array('fieldset--responsive', 'fieldset--' . $fieldset_class, 'has-tooltip'))); foreach ($values as $key => $vals) { if (is_array($vals)) { if ($vals['type'] == 'fieldset') { if (!isset($vals['default']) && $vals['type'] == 'fieldset') { $form['options']['responsives']['responsive'][$i][$key] = array('#title' => $vals['title'], '#type' => $vals['type'], '#collapsible' => FALSE, '#collapsed' => FALSE, '#attributes' => array('class' => array('fieldset--settings', 'fieldset--' . $fieldset_class, 'has-tooltip'))); } foreach ($vals as $k => $value) { if ($value && is_array($value)) { $form['options']['responsives']['responsive'][$i][$key][$k] = array('#title' => $value['title'], '#description' => $value['description'], '#type' => $value['type'], '#attributes' => array('class' => array('is-tooltip'))); if ($value['type'] != 'fieldset') { $form['options']['responsives']['responsive'][$i][$key][$k]['#default_value'] = isset($options['responsives']['responsive'][$i][$key][$k]) ? $options['responsives']['responsive'][$i][$key][$k] : $value['default']; } if (isset($value['states'])) { // Specify proper states for the breakpoint form elements. $states = ''; switch ($k) { case 'pauseOnHover': case 'pauseOnDotsHover': case 'autoplaySpeed': $states = array('visible' => array(':input[name*="options[responsives][responsive][' . $i . '][settings][autoplay]"]' => array('checked' => TRUE))); break; case 'appendArrows': $states = array('visible' => array(':input[name*="options[responsives][responsive][' . $i . '][settings][arrows]"]' => array('checked' => TRUE))); break; case 'centerPadding': $states = array('visible' => array(':input[name*="options[responsives][responsive][' . $i . '][settings][centerMode]"]' => array('checked' => TRUE))); break; case 'touchThreshold': $states = array('visible' => array(':input[name*="options[responsives][responsive][' . $i . '][settings][touchMove]"]' => array('checked' => TRUE))); break; } if ($states) { $form['options']['responsives']['responsive'][$i][$key][$k]['#states'] = $states; } } if (isset($value['options'])) { $form['options']['responsives']['responsive'][$i][$key][$k]['#options'] = $value['options']; } if (isset($value['empty_option'])) { $form['options']['responsives']['responsive'][$i][$key][$k]['#empty_option'] = $value['empty_option']; } if (isset($value['field_suffix'])) { $form['options']['responsives']['responsive'][$i][$key][$k]['#field_suffix'] = $value['field_suffix']; } if (!isset($value['field_suffix']) && $value['cast'] == 'bool') { $form['options']['responsives']['responsive'][$i][$key][$k]['#field_suffix'] = ''; $form['options']['responsives']['responsive'][$i][$key][$k]['#title_display'] = 'before'; } } } } else { $form['options']['responsives']['responsive'][$i][$key] = array('#title' => $vals['title'], '#description' => $vals['description'], '#type' => $vals['type'], '#default_value' => isset($options['responsives']['responsive'][$i][$key]) ? $options['responsives']['responsive'][$i][$key] : $vals['default'], '#attributes' => array('class' => array('is-tooltip'))); if ($vals['type'] == 'textfield') { $form['options']['responsives']['responsive'][$i][$key]['#size'] = 20; $form['options']['responsives']['responsive'][$i][$key]['#maxlength'] = 255; } if ($vals['cast'] == 'int') { $form['options']['responsives']['responsive'][$i][$key]['#maxlength'] = 60; } if (isset($vals['states'])) { $form['options']['responsives']['responsive'][$i][$key]['#states'] = $vals['states']; } if (isset($vals['options'])) { $form['options']['responsives']['responsive'][$i][$key]['#options'] = $vals['options']; } if (isset($vals['field_suffix'])) { $form['options']['responsives']['responsive'][$i][$key]['#field_suffix'] = $vals['field_suffix']; } if (!isset($vals['field_suffix']) && $vals['cast'] == 'bool') { $form['options']['responsives']['responsive'][$i][$key]['#field_suffix'] = ''; $form['options']['responsives']['responsive'][$i][$key]['#title_display'] = 'before'; } } } } } } } }
/** * Return the class of the field's wrapper. */ public function elementWrapperClasses($row_index = NULL) { $classes = explode(' ', $this->options['element_wrapper_class']); foreach ($classes as &$class) { $class = $this->tokenizeValue($class, $row_index); $class = drupal_clean_css_identifier($class); } return implode(' ', $classes); }
/** * Returns HTML for a single local action link. * * This function overrides theme_menu_local_action() to add the icons that ship * with Bootstrap to the action links. * * @param $variables * An associative array containing: * - element: A render element containing: * - #link: A menu link array with "title", "href", "localized_options", and * "icon" keys. If "icon" is not passed, it defaults to "plus-sign". * * @ingroup themeable * * @see theme_menu_local_action(). */ function bootstrap_menu_local_action($variables) { $link = $variables['element']['#link']; // Build the icon rendering element. if (empty($link['icon'])) { $link['icon'] = 'plus-sign'; } $icon = '<i class="' . drupal_clean_css_identifier('icon-' . $link['icon']) . '"></i>'; // Format the action link. $output = '<li>'; if (isset($link['href'])) { $options = isset($link['localized_options']) ? $link['localized_options'] : array(); // If the title is not HTML, sanitize it. if (empty($link['localized_options']['html'])) { $link['title'] = check_plain($link['title']); } // Force HTML so we can add the icon rendering element. $options['html'] = TRUE; $output .= l($icon . $link['title'], $link['href'], $options); } elseif (!empty($link['localized_options']['html'])) { $output .= $icon . $link['title']; } else { $output .= $icon . check_plain($link['title']); } $output .= "</li>\n"; return $output; }
// Correctly format some bundles if ($bundle === 'shop_categories') { $bundle = 'shop_category'; } if ($bundle === 'product_display') { $bundle = 'product'; } // Clean up the css identifier $field_type_css = drupal_clean_css_identifier($bundle); } // Set the CSS BEM element name if (isset($element['#field_name'])) { // Strip the field_ prefix if present $field_name = preg_replace(array('/field_/', '/[_-]{2,}/'), array('', '_'), $element['#field_name']); // Clean up the css identifier $field_name_css = drupal_clean_css_identifier($field_name); } // Build the item attributes array $attributes = array('class' => array()); $attributes['class'][] = $field_name_css; $attributes['class'][] = $field_type_css . '__' . $field_name_css; ?> <?php if (isset($items) && !empty($items)) { ?> <?php if (!$label_hidden) { ?>
foreach ($types as $type) { ?> <?php if ($view->date_info->style_max_items_behavior != 'more') { ?> <?php print theme('calendar_stripe_stripe', array('type' => $type)); ?> <?php } ?> <?php } ?> <div class="view-item <?php print drupal_clean_css_identifier('view-item-' . $view->name); ?> "> <?php if ($view->date_info->style_max_items_behavior != 'more') { ?> <div class="multiple-events"> <?php print l(t('Click to see all @count events', array('@count' => $count)), $link); ?> </div> </div> <?php } else { ?> <div class="calendar-more"><?php
function negd_theme_field($variables) { $output = ''; // Render the label, if it's not hidden. if (!$variables['label_hidden']) { $output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ': </div>'; } // Render the items. $output .= '<div class="field-items"' . $variables['content_attributes'] . '>'; foreach ($variables['items'] as $delta => $item) { $item2 = drupal_render($item); $classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even'); $output .= '<div class=" ' . drupal_clean_css_identifier(strtolower($item2)) . ' ' . $classes . '"' . $variables['item_attributes'][$delta] . '>' . $item2 . '</div>'; } $output .= '</div>'; // Render the top-level DIV. $output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>'; return $output; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Don't show the form when batch operations are in progress. if ($batch = batch_get() && isset($batch['current_set'])) { return array('#theme' => ''); } // Make sure that we validate because this form might be submitted // multiple times per page. $form_state['must_validate'] = TRUE; /** @var \Drupal\views\ViewExecutable $view */ $view = $form_state['view']; $display =& $form_state['display']; $form_state['input'] = $view->getExposedInput(); // Let form plugins know this is for exposed widgets. $form_state['exposed'] = TRUE; // Check if the form was already created if ($cache = $this->exposedFormCache->getForm($view->storage->id(), $view->current_display)) { return $cache; } $form['#info'] = array(); // Go through each handler and let it generate its exposed widget. foreach ($view->display_handler->handlers as $type => $value) { /** @var \Drupal\views\Plugin\views\HandlerBase $handler */ foreach ($view->{$type} as $id => $handler) { if ($handler->canExpose() && $handler->isExposed()) { // Grouped exposed filters have their own forms. // Instead of render the standard exposed form, a new Select or // Radio form field is rendered with the available groups. // When an user choose an option the selected value is split // into the operator and value that the item represents. if ($handler->isAGroup()) { $handler->groupForm($form, $form_state); $id = $handler->options['group_info']['identifier']; } else { $handler->buildExposedForm($form, $form_state); } if ($info = $handler->exposedInfo()) { $form['#info']["{$type}-{$id}"] = $info; } } } } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#name' => '', '#type' => 'submit', '#value' => $this->t('Apply'), '#id' => drupal_html_id('edit-submit-' . $view->storage->id())); $form['#action'] = url($view->display_handler->getUrl()); $form['#theme'] = $view->buildThemeFunctions('views_exposed_form'); $form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . String::checkPlain($view->storage->id()) . '-' . String::checkPlain($display['id'])); // $form['#attributes']['class'] = array('views-exposed-form'); /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ $exposed_form_plugin = $form_state['exposed_form_plugin']; $exposed_form_plugin->exposedFormAlter($form, $form_state); // Save the form. $this->exposedFormCache->setForm($view->storage->id(), $view->current_display, $form); return $form; }
/** * Views preprocessing * Add view type class (e.g., node, teaser, list, table) */ function webpro_core_preprocess_views_view(&$vars) { $vars['css_name'] = $vars['css_name'] . ' view-style-' . drupal_clean_css_identifier(strtolower($vars['view']->plugin_name)); }
<div class="views-field-<?php print drupal_clean_css_identifier($view->field[$field]->field); ?> "> <?php if ($view->field[$field]->label()) { ?> <label class="view-label-<?php print drupal_clean_css_identifier($view->field[$field]->field); ?> "> <?php print $view->field[$field]->label(); ?> : </label> <?php } ?> <div class="views-content-<?php print drupal_clean_css_identifier($view->field[$field]->field); ?> "> <?php print $view->style_plugin->rendered_fields[$count][$field]; ?> </div> </div>
/** * Return the token replaced row class for the specified row. */ public function getRowClass($row_index) { if ($this->usesRowClass()) { $class = $this->options['row_class']; if ($this->usesFields() && $this->view->field) { $class = strip_tags($this->tokenizeValue($class, $row_index)); } $classes = explode(' ', $class); foreach ($classes as &$class) { $class = drupal_clean_css_identifier($class); } return implode(' ', $classes); } }
/** * Overwrite theme_fieldset(). */ function bht_theme_fieldset($variables) { $element = $variables['element']; // If we have a webform component, use the key as class. if (isset($variables['element']['#webform_component']['form_key'])) { $class = $variables['element']['#webform_component']['form_key']; // Format the css class to Drupal standards. $class = drupal_clean_css_identifier($class); $element['#attributes']['class'] = $class; } elseif (isset($variables['element']['#title'])) { // Keep only lowercase printable standard ASCII characters. $class = strtolower(trim(preg_replace("/[^A-Za-z0-9 ]/", '', $variables['element']['#title']))); // Format the css class to Drupal standards. $class = drupal_clean_css_identifier($class); $element['#attributes']['class'] = $class; } $output = '<fieldset' . drupal_attributes($element['#attributes']) . '>'; if (!empty($element['#title'])) { $output .= '<legend>' . $element['#title'] . '</legend>'; } if (!empty($element['#description'])) { $output .= '<small>' . $element['#description'] . '</small>'; } $output .= $element['#children']; if (isset($element['#value'])) { $output .= $element['#value']; } $output .= "</fieldset>\n"; return $output; }
/** * Implements hook_form_alter(). */ function omega_form_alter(&$form, &$form_state, $form_id) { if (!empty($form['#attributes']['class']) && is_string($form['#attributes']['class'])) { $form['#attributes']['class'] = explode(' ', $form['#attributes']['class']); } // Duplicate the form ID as a class so we can reduce specificity in our CSS. if (!empty($form['#id'])) { $form['#attributes']['class'][] = drupal_clean_css_identifier($form['#id']); } else { $form['#attributes']['class'][] = drupal_clean_css_identifier($form_id); } }