/** * Pre-render callback: Renders a link into #markup. * * Doing so during pre_render gives modules a chance to alter the link parts. * * @param array $element * A structured array whose keys form the arguments to _l(): * - #title: The link text to pass as argument to _l(). * - #url: The URL info either pointing to a route or a non routed path. * - #options: (optional) An array of options to pass to _l() or the link * generator. * * @return array * The passed-in element containing a rendered link in '#markup'. */ public static function preRenderLink($element) { // By default, link options to pass to _l() are normally set in #options. $element += array('#options' => array()); // However, within the scope of renderable elements, #attributes is a valid // way to specify attributes, too. Take them into account, but do not override // attributes from #options. if (isset($element['#attributes'])) { $element['#options'] += array('attributes' => array()); $element['#options']['attributes'] += $element['#attributes']; } // This #pre_render callback can be invoked from inside or outside of a Form // API context, and depending on that, a HTML ID may be already set in // different locations. #options should have precedence over Form API's #id. // #attributes have been taken over into #options above already. if (isset($element['#options']['attributes']['id'])) { $element['#id'] = $element['#options']['attributes']['id']; } elseif (isset($element['#id'])) { $element['#options']['attributes']['id'] = $element['#id']; } // Conditionally invoke self::preRenderAjaxForm(), if #ajax is set. if (isset($element['#ajax']) && !isset($element['#ajax_processed'])) { // If no HTML ID was found above, automatically create one. if (!isset($element['#id'])) { $element['#id'] = $element['#options']['attributes']['id'] = drupal_html_id('ajax-link'); } $element = static::preRenderAjaxForm($element); } if (!empty($element['#url'])) { $options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']); $element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options)); } return $element; }
/** * {@inheritdoc} */ public function preBuild(array &$build, ObjectInterface $context = NULL) { $map_id = $context->getId(); $layers = $this->getOption('layers', array()); $items = array(); $map_layers = $context->getObjects('layer'); $element_type = $this->getOption('multiselect', FALSE) ? 'checkbox' : 'radio'; // Only handle layers available in the map and configured in the control. // @TODO: use Form API (with form_process_* and stuff) $labels = $this->getOption('layer_labels', array()); foreach ($map_layers as $i => $map_layer) { if (isset($layers[$map_layer->getMachineName()])) { $classes = array(drupal_html_class($map_layer->getMachineName())); $checked = ''; if ($element_type == 'checkbox') { if ($map_layer->getOption('visible', 1)) { $checked = 'checked '; $classes[] = 'active'; } } $label = $map_layer->getName(); if (isset($labels[$map_layer->getMachineName()])) { $label = openlayers_i18n_string('openlayers:layerswitcher:' . $this->getMachineName() . ':' . $map_layer->getMachineName() . ':label', $labels[$map_layer->getMachineName()], array('sanitize' => TRUE)); } $items[] = array('data' => '<label><input type="' . $element_type . '" name="layer" ' . $checked . 'value="' . $map_layer->getMachineName() . '">' . $label . '</label>', 'id' => drupal_html_id($map_id . '-' . $map_layer->getMachineName()), 'class' => $classes); } } $title = openlayers_i18n_string('openlayers:layerswitcher:' . $this->getMachineName() . ':title', $this->getOption('label', 'Layers'), array('sanitize' => TRUE)); $layerswitcher = array('#theme' => 'item_list', '#type' => 'ul', '#title' => $title, '#items' => $items, '#attributes' => array('id' => drupal_html_id($this->getMachineName() . '-items'))); $this->setOption('element', '<div id="' . drupal_html_id($this->getMachineName()) . '" class="' . drupal_html_class($this->getMachineName()) . ' layerswitcher">' . drupal_render($layerswitcher) . '</div>'); // Allow the parent class to perform it's pre-build actions. parent::preBuild($build, $context); }
/** * Pre-processes variables for the "bootstrap_panel" theme hook. * * See template for list of available variables. * * @see bootstrap-panel.tpl.php * * @ingroup theme_preprocess */ function bootstrap_preprocess_bootstrap_panel(&$variables) { $element =& $variables['element']; // Set the element's attributes. element_set_attributes($element, array('id')); // Retrieve the attributes for the element. $attributes =& _bootstrap_get_attributes($element); // Add panel and panel-default classes. $attributes['class'][] = 'panel'; $attributes['class'][] = 'panel-default'; // states.js requires form-wrapper on fieldset to work properly. $attributes['class'][] = 'form-wrapper'; // Handle collapsible panels. $variables['collapsible'] = FALSE; if (isset($element['#collapsible'])) { $variables['collapsible'] = $element['#collapsible']; } $variables['collapsed'] = FALSE; if (isset($element['#collapsed'])) { $variables['collapsed'] = $element['#collapsed']; // Remove collapsed class since we only want it to apply to the inner element if ($index = array_search('collapsed', $attributes['class'])) { unset($attributes['class'][$index]); $attributes['class'] = array_values($attributes['class']); } } // Force grouped fieldsets to not be collapsible (for vertical tabs). if (!empty($element['#group'])) { $variables['collapsible'] = FALSE; $variables['collapsed'] = FALSE; } // Collapsible elements need an ID, so generate one for the fieldset's inner element. if ($variables['collapsible']) { // Generate an ID for the outer element if necessary. if (!isset($element['#id'])) { $element['#id'] = drupal_html_id('bootstrap-panel'); } $variables['id_inner'] = drupal_html_id($element['#id'] . '-inner'); } $variables['target'] = NULL; if (isset($element['#id'])) { $attributes['id'] = $element['#id']; if (isset($variables['id_inner'])) { $variables['target'] = '#' . $variables['id_inner']; } } // Build the panel content. $variables['content'] = $element['#children']; if (isset($element['#value'])) { $variables['content'] .= $element['#value']; } // Iterate over optional variables. $keys = array('description', 'prefix', 'suffix', 'title'); foreach ($keys as $key) { $variables[$key] = !empty($element["#{$key}"]) ? $element["#{$key}"] : FALSE; } // Add the attributes. $variables['attributes'] = $attributes; }
/** * Returns a ID that is guaranteed uniqueness. * * @return string * A unique id to be used to generate aria attributes. */ public function getAriaId() { static $id; if (!isset($id)) { $id = drupal_html_id($this->get('id')); } return $id; }
/** * Processes a container element. * * @param array $element * An associative array containing the properties and children of the * container. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param array $complete_form * The complete form structure. * * @return array * The processed element. */ public static function processContainer(&$element, FormStateInterface $form_state, &$complete_form) { // Generate the ID of the element if it's not explicitly given. if (!isset($element['#id'])) { $element['#id'] = drupal_html_id(implode('-', $element['#parents']) . '-wrapper'); } return $element; }
/** * {@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; }
/** * Implements theme_preprocess_bootstrap_modal(). * * @todo: Replace with "bootstrap_effect_fade" theme setting. */ function bootstrap_preprocess_bootstrap_modal(&$variables) { if (empty($variables['attributes']['id'])) { $variables['attributes']['id'] = drupal_html_id(strip_tags($variables['heading'])); } $variables['attributes']['class'][] = 'modal'; $variables['attributes']['class'][] = 'fade'; $variables['attributes']['tabindex'] = -1; $variables['attributes']['role'] = 'dialog'; $variables['attributes']['aria-hidden'] = 'true'; $variables['heading'] = $variables['html_heading'] ? $variables['heading'] : check_plain($variables['heading']); }
/** * {@inheritdoc} */ public function preRender(&$element) { $element += array('#type' => 'fieldset', '#title' => SafeMarkup::checkPlain($this->t($this->getLabel())), '#pre_render' => array(), '#attributes' => array()); if ($this->getSetting('description')) { $element += array('#description' => $this->getSetting('description')); } if ($this->getSetting('id')) { $element['#id'] = drupal_html_id($this->getSetting('id')); } if ($this->getSetting('classes')) { $element['#attributes'] += array('class' => explode(' ', $this->getSetting('classes'))); } }
/** * {@inheritdoc} */ public function preRender(&$element) { $element += array('#type' => 'details', '#title' => String::checkPlain(\Drupal::translation()->translate($this->getLabel())), '#open' => $this->getSetting('open')); if ($this->getSetting('id')) { $element['#id'] = drupal_html_id($this->getSetting('id')); } if ($this->getSetting('classes')) { $element += array('#attributes' => array('class' => explode(' ', $this->getSetting('classes')))); } if ($this->getSetting('description')) { $element += array('#description' => $this->getSetting('description')); } }
/** * Displays the bean. */ public function view($bean, $content, $view_mode = 'default', $langcode = NULL) { if ($purchase_contract_id = commerce_cba_get_purchase_contract_id()) { $html_id = drupal_html_id('AmazonAddressWidget'); $content['bean'][$bean->delta]['#attached']['library'][] = array('commerce_cba', 'amazon_widgets'); // @TODO: Add height and width. $callbacks = array('callbacks' => array('onAddressSelect' => 'commerce_cba_add_widget_info')); $display_mode = $view_mode == 'commerce_cba_read_only' ? 'Read' : 'Edit'; $data = array('commerce_cba' => array($html_id => array('html_id' => $html_id, 'purchaseContractId' => commerce_cba_get_purchase_contract_id(), 'widget_type' => 'AddressWidget', 'merchantId' => variable_get('cba_merchant_id', ''), 'displayMode' => $display_mode, 'destinationName' => isset($bean->settings['destination']) ? $bean->settings['destination'] : 'billing') + $callbacks)); $content['bean'][$bean->delta]['#attached']['js'][] = array('data' => $data, 'type' => 'setting'); $content['bean'][$bean->delta]['#type'] = 'container'; $content['bean'][$bean->delta]['#attributes'] = array('id' => $html_id); } return $content; }
/** * Tests that drupal_html_id() cleans the ID properly. */ function testDrupalHTMLId() { // Verify that letters, digits, and hyphens are not stripped from the ID. $id = 'abcdefghijklmnopqrstuvwxyz-0123456789'; $this->assertIdentical(drupal_html_id($id), $id, 'Verify valid characters pass through.'); // Verify that invalid characters are stripped from the ID. $this->assertIdentical(drupal_html_id('invalid,./:@\\^`{Üidentifier'), 'invalididentifier', 'Strip invalid characters.'); // Verify Drupal coding standards are enforced. $this->assertIdentical(drupal_html_id('ID NAME_[1]'), 'id-name-1', 'Enforce Drupal coding standards.'); // Reset the static cache so we can ensure the unique id count is at zero. drupal_static_reset('drupal_html_id'); // Clean up IDs with invalid starting characters. $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id', 'Test the uniqueness of IDs #1.'); $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id--2', 'Test the uniqueness of IDs #2.'); $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id--3', 'Test the uniqueness of IDs #3.'); }
function menta_menu_link(array $vars) { $element = $vars['element']; $sub_menu = ''; if ($element['#below']) { $sub_menu = drupal_render($element['#below']); } $output = l($element['#title'], $element['#href'], $element['#localized_options']); // Adding a class depending on the TITLE of the link (not constant) $element['#attributes']['class'][] = drupal_html_id($element['#title']); // Adding a class depending on the ID of the link (constant) if (isset($element['#original_link']['mlid']) && !empty($element['#original_link']['mlid'])) { $element['#attributes']['class'][] = 'mid-' . $element['#original_link']['mlid']; } return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n"; }
/** * Displays the bean. */ public function view($bean, $content, $view_mode = 'default', $langcode = NULL) { // There's no point in displaying the button if amazon js was not included. if (($js = commerce_cba_javascript_file()) && ($purchase_contract_id = commerce_cba_get_purchase_contract_id())) { $html_id = drupal_html_id('AmazonWalletWidget'); $content['bean'][$bean->delta]['#attached']['library'] = array(array('commerce_cba', 'amazon_widgets')); // @TODO: Add height and width. $callbacks = array('callbacks' => array('onPaymentSelect' => 'commerce_cba_add_widget_info')); $display_mode = $view_mode == 'commerce_cba_read_only' ? 'Read' : 'Edit'; $data = array('commerce_cba' => array($html_id => array('html_id' => $html_id, 'widget_type' => 'WalletWidget', 'merchantId' => variable_get('cba_merchant_id', ''), 'purchaseContractId' => commerce_cba_get_purchase_contract_id(), 'displayMode' => $display_mode) + $callbacks)); $content['bean'][$bean->delta]['#attached']['js'][] = array('data' => $data, 'type' => 'setting'); $content['bean'][$bean->delta]['#type'] = 'container'; $content['bean'][$bean->delta]['#attributes'] = array('id' => $html_id); } return $content; }
/** * {@inheritdoc} */ public function init(array $data) { // Mash the provided configuration with the defaults. foreach ($this->defaultProperties() as $property => $value) { if (isset($data[$property])) { $this->{$property} = $data[$property]; } } // If there are options ensure the provided ones overwrite the defaults. if (isset($data['options'])) { $this->options = array_replace_recursive((array) $this->options, (array) $data['options']); } // We need to ensure the object has a proper machine name. if (empty($this->machine_name)) { $this->machine_name = drupal_html_id($this->getType() . '-' . time()); } }
/** * Tests default and custom block categories. */ public function testBlockCategory() { $this->drupalLogin($this->drupalCreateUser(array('administer views', 'administer blocks'))); // Create a new view in the UI. $edit = array(); $edit['label'] = $this->randomString(); $edit['id'] = strtolower($this->randomMachineName()); $edit['show[wizard_key]'] = 'standard:views_test_data'; $edit['description'] = $this->randomString(); $edit['block[create]'] = TRUE; $edit['block[style][row_plugin]'] = 'fields'; $this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit')); // Test that the block was given a default category corresponding to its // base table. $arguments = array(':id' => 'edit-category-lists-views', ':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-1', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_1', 'theme' => 'stark')), ':text' => $edit['label']); $this->drupalGet('admin/structure/block'); $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments); $this->assertTrue(!empty($elements), 'The test block appears in the category for its base table.'); // Duplicate the block before changing the category. $this->drupalPostForm('admin/structure/views/view/' . $edit['id'] . '/edit/block_1', array(), t('Duplicate @display_title', array('@display_title' => 'Block'))); $this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_2'); // Change the block category to a random string. $this->drupalGet('admin/structure/views/view/' . $edit['id'] . '/edit/block_1'); $label = t('Lists (Views)'); $link = $this->xpath('//a[@id="views-block-1-block-category" and normalize-space(text())=:label]', array(':label' => $label)); $this->assertTrue(!empty($link)); $this->clickLink($label); $category = $this->randomString(); $this->drupalPostForm(NULL, array('block_category' => $category), t('Apply')); // Duplicate the block after changing the category. $this->drupalPostForm(NULL, array(), t('Duplicate @display_title', array('@display_title' => 'Block'))); $this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_3'); $this->drupalPostForm(NULL, array(), t('Save')); // Test that the blocks are listed under the correct categories. $category_id = drupal_html_id('edit-category-' . String::checkPlain($category)); $arguments[':id'] = $category_id; $this->drupalGet('admin/structure/block'); $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments); $this->assertTrue(!empty($elements), 'The test block appears in the custom category.'); $arguments = array(':id' => 'edit-category-lists-views', ':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-2', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_2', 'theme' => 'stark')), ':text' => $edit['label']); $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments); $this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.'); $arguments = array(':id' => $category_id, ':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-3', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_3', 'theme' => 'stark')), ':text' => $edit['label']); $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments); $this->assertTrue(!empty($elements), 'The second duplicated test block appears in the custom category.'); }
function template_preprocess_section(&$vars) { $theme = drupalexp_get_theme(); $section = $vars['section']; $vars['theme_hook_suggestions'][] = 'section__' . $theme->theme; $vars['theme_hook_suggestions'][] = 'section__' . $section->key; if (isset($section->sticky) && $section->sticky) { $vars['classes_array'][] = 'dexp-sticky'; drupal_add_js(drupal_get_path('theme', 'drupalexp') . '/assets/js/drupalexp-sticky.js'); } if (isset($section->colpadding) && $section->colpadding != '' && $section->colpadding != 15 && $section->colpadding >= 0) { $vars['attributes_array']['data-padding'] = $section->colpadding; $vars['classes_array'][] = 'custompadding'; } if (isset($section->custom_class) && $section->custom_class != '') { $vars['classes_array'][] = $section->custom_class; } if (isset($section->hphone) && $section->hphone) { $vars['classes_array'][] = 'hidden-xs'; } if (isset($section->htablet) && $section->htablet) { $vars['classes_array'][] = 'hidden-sm'; } if (isset($section->hdesktop) && $section->hdesktop) { $vars['classes_array'][] = 'hidden-md'; $vars['classes_array'][] = 'hidden-lg'; } if (isset($section->vphone) && $section->vphone) { $vars['classes_array'][] = 'visible-xs'; } if (isset($section->vtablet) && $section->vtablet) { $vars['classes_array'][] = 'visible-sm'; } if (isset($section->vdesktop) && $section->vdesktop) { $vars['classes_array'][] = 'visible-md'; $vars['classes_array'][] = 'visible-lg'; } $vars['container_class'] = $section->fullwidth == 'no' ? 'container' : 'dexp-container'; $vars['attributes_array']['class'] = $vars['classes_array']; $vars['attributes_array']['id'] = drupal_html_id('section-' . $section->key); $vars['html_id'] = $vars['attributes_array']['id']; if (isset($section->backgroundcolor) && $section->backgroundcolor) { $vars['attributes_array']['style'] = "background-color:{$section->backgroundcolor}"; } }
/** * Expands a radios element into individual radio elements. */ public static function processRadios(&$element, FormStateInterface $form_state, &$complete_form) { if (count($element['#options']) > 0) { $weight = 0; foreach ($element['#options'] as $key => $choice) { // Maintain order of options as defined in #options, in case the element // defines custom option sub-elements, but does not define all option // sub-elements. $weight += 0.001; $element += array($key => array()); // Generate the parents as the autogenerator does, so we will have a // unique id for each radio button. $parents_for_id = array_merge($element['#parents'], array($key)); $element[$key] += array('#type' => 'radio', '#title' => $choice, '#return_value' => $key, '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : FALSE, '#attributes' => $element['#attributes'], '#parents' => $element['#parents'], '#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)), '#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL, '#weight' => $weight); } } return $element; }
/** * Displays the bean. */ public function view($bean, $content, $view_mode = 'default', $langcode = NULL, $test = NULL) { // There's no point in displaying the button if amazon js was not included. if (($js = commerce_cba_javascript_file()) && isset($bean->order) && ($order = $bean->order)) { if (!empty($order->commerce_cba_amazon_order_ids)) { $content['bean'][$bean->delta]['#attached']['library'] = array(array('commerce_cba', 'amazon_widgets')); $order_ids = field_get_items('commerce_order', $order, 'commerce_cba_amazon_order_ids'); foreach ($order_ids as $order_id) { $html_id = drupal_html_id('OrderDetailsWidget'); // @TODO: Add height and width. $data = array('commerce_cba' => array($html_id => array('html_id' => $html_id, 'widget_type' => 'OrderDetailsWidget', 'merchantId' => variable_get('cba_merchant_id', ''), 'orderId' => $order_id['value']))); $content['bean'][$bean->delta][$html_id]['#attached']['js'][] = array('data' => $data, 'type' => 'setting'); $content['bean'][$bean->delta][$html_id]['#type'] = 'container'; $content['bean'][$bean->delta][$html_id]['#attributes'] = array('id' => $html_id); } } } return $content; }
/** * Pre-processes variables for the "bootstrap_carousel" theme hook. * * See template for list of available variables. * * @see bootstrap-carousel.tpl.php * * @ingroup theme_preprocess */ function bootstrap_preprocess_bootstrap_carousel(&$variables) { $variables['attributes']['class'][] = 'carousel'; $variables['attributes']['class'][] = 'slide'; $variables['attributes']['data-ride'] = 'carousel'; if (empty($variables['attributes']['id'])) { $variables['attributes']['id'] = drupal_html_id('carousel'); } $default_data_attributes = array('interval' => 5000, 'pause' => TRUE, 'wrap' => TRUE); foreach ($default_data_attributes as $name => $value) { if ($variables[$name] !== $value) { // Convert PHP booleans to the JSON equivalent, otherwise they'll be // interpreted as integers when they're parsed. if (is_bool($variables[$name])) { $variables[$name] = $variables[$name] ? 'true' : 'false'; } $variables['attributes']['data-' . $name] = $variables[$name]; } } }
/** * Implements hook_preprocess_bootstrap_panel(). */ function bootstrap_preprocess_bootstrap_panel(&$variables) { $element =& $variables['element']; $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array(); $attributes['class'][] = 'panel'; $attributes['class'][] = 'panel-default'; // states.js requires form-wrapper on fieldset to work properly. $attributes['class'][] = 'form-wrapper'; $variables['collapsible'] = FALSE; if (isset($element['#collapsible'])) { $variables['collapsible'] = $element['#collapsible']; } $variables['collapsed'] = FALSE; if (isset($element['#collapsed'])) { $variables['collapsed'] = $element['#collapsed']; } // Force grouped fieldsets to not be collapsible (for vertical tabs). if (!empty($element['#group'])) { $variables['collapsible'] = FALSE; $variables['collapsed'] = FALSE; } if (!isset($element['#id']) && $variables['collapsible']) { $element['#id'] = drupal_html_id('bootstrap-panel'); } $variables['target'] = NULL; if (isset($element['#id'])) { $attributes['id'] = $element['#id']; $variables['target'] = '#' . $element['#id'] . ' > .collapse'; } $variables['content'] = $element['#children']; if (isset($element['#value'])) { $variables['content'] .= $element['#value']; } // Iterate over optional variables. $keys = array('description', 'prefix', 'suffix', 'title'); foreach ($keys as $key) { $variables[$key] = !empty($element["#{$key}"]) ? $element["#{$key}"] : FALSE; } $variables['attributes'] = $attributes; }
/** * Returns HTML for help text based on file upload validators. * * @param array $variables * An associative array containing: * - description: The normal description for this field, specified by the * user. * - upload_validators: An array of upload validators as used in * $element['#upload_validators']. * * @return string * The constructed HTML. * * @see theme_file_upload_help() * * @ingroup theme_functions */ function bootstrap_file_upload_help($variables) { // If popover's are disabled, just theme this normally. if (!bootstrap_setting('popover_enabled')) { return theme_file_upload_help($variables); } $build = array(); if (!empty($variables['description'])) { $build['description'] = array('#markup' => $variables['description'] . '<br>'); } $descriptions = array(); $upload_validators = $variables['upload_validators']; if (isset($upload_validators['file_validate_size'])) { $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>')); } if (isset($upload_validators['file_validate_extensions'])) { $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>')); } if (isset($upload_validators['file_validate_image_resolution'])) { $max = $upload_validators['file_validate_image_resolution'][0]; $min = $upload_validators['file_validate_image_resolution'][1]; if ($min && $max && $min == $max) { $descriptions[] = t('Images must be exactly !size pixels.', array('!size' => '<strong>' . $max . '</strong>')); } elseif ($min && $max) { $descriptions[] = t('Images must be between !min and !max pixels.', array('!min' => '<strong>' . $min . '</strong>', '!max' => '<strong>' . $max . '</strong>')); } elseif ($min) { $descriptions[] = t('Images must be larger than !min pixels.', array('!min' => '<strong>' . $min . '</strong>')); } elseif ($max) { $descriptions[] = t('Images must be smaller than !max pixels.', array('!max' => '<strong>' . $max . '</strong>')); } } if ($descriptions) { $id = drupal_html_id('upload-instructions'); $build['instructions'] = array('#theme' => 'link__file_upload_requirements', '#text' => _bootstrap_icon('question-sign') . ' ' . t('More information'), '#path' => '#', '#options' => array('attributes' => array('data-toggle' => 'popover', 'data-target' => "#{$id}", 'data-html' => TRUE, 'data-placement' => 'bottom', 'data-title' => t('File requirements')), 'html' => TRUE, 'external' => TRUE)); $build['requirements'] = array('#theme_wrappers' => array('container__file_upload_requirements'), '#attributes' => array('id' => $id, 'class' => array('element-invisible', 'help-block'))); $build['requirements']['validators'] = array('#theme' => 'item_list__file_upload_requirements', '#items' => $descriptions); } return drupal_render($build); }
/** * Displays the bean. */ public function view($bean, $content, $view_mode = 'default', $langcode = NULL) { // There's no point in displaying the button if amazon js was not included. if ($js = commerce_cba_javascript_file()) { $html_id = drupal_html_id('AmazonInlineWidget'); $content['bean'][$bean->delta]['#attached']['library'] = array(array('commerce_cba', 'amazon_widgets')); $callbacks = array(); if ($bean->settings['button_type'] == 'checkout') { $callbacks = array('callbacks' => array('onAuthorize' => 'commerce_cba_redirect_checkout')); } elseif ($bean->settings['button_type'] == 'addressBook') { $callbacks = array('callbacks' => array('onAuthorize' => 'commerce_cba_address_redirect_checkout')); } $content['bean'][$bean->delta]['#attached']['js'][] = array('data' => array($html_id => $html_id, 'commerce_cba' => array($html_id => array('merchantId' => variable_get('cba_merchant_id', ''), 'purchaseContractId' => commerce_cba_get_purchase_contract_id(), 'widget_type' => 'InlineCheckoutWidget', 'checkout_pane' => isset($bean->checkout_pane) ? $bean->checkout_pane : NULL, 'settings' => array('buttonType' => isset($bean->settings['button_type']) ? $bean->settings['button_type'] : 'checkout', 'buttonSettings' => array('size' => isset($bean->settings['button_settings']['size']) ? $bean->settings['button_settings']['size'] : 'large', 'color' => isset($bean->settings['button_settings']['color']) ? $bean->settings['button_settings']['color'] : 'orange', 'background' => isset($bean->settings['button_settings']['background']) ? $bean->settings['button_settings']['background'] : 'white'))) + $callbacks)), 'type' => 'setting'); $content['bean'][$bean->delta]['#attached']['css'] = array(drupal_get_path('module', 'commerce_cba') . '/css/commerce_cba.css'); $content['bean'][$bean->delta]['#type'] = 'container'; $content['bean'][$bean->delta]['#attributes'] = array('id' => $html_id); // Place the button aligned to the right if it's checkout. if ($bean->settings['button_type'] == 'checkout') { $content['bean'][$bean->delta]['#attributes']['class'] = 'checkout-by-amazon-pay'; } } return $content; }
> <?php foreach ($items as $delta => $item) { ?> <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?> "<?php print $item_attributes[$delta]; ?> > <?php if ($item['#file']->type == "video") { ?> <?php $rel = 'lightframe[' . drupal_html_id('video') . ']'; $video = explode('//v/', $item['#file']->uri); $path = "//www.youtube.com/embed/" . $video[1]; ?> <a href="<?php print $path; ?> " rel="<?php print $rel; ?> " title=""> <?php print render($item); ?> <div class="video-overlay"> <i class="fa fa-search"></i>
/** * Implements hook_preprocess_region(). */ function alpha_alpha_preprocess_region(&$vars) { $vars['attributes_array']['id'] = drupal_html_id('region-' . $vars['region']); $vars['content_attributes_array']['class'][] = 'region-inner'; $vars['content_attributes_array']['class'][] = $vars['attributes_array']['id'] . '-inner'; }
/** * Tests that the block form has a theme selector when not passed via the URL. */ public function testBlockThemeSelector() { // Enable all themes. theme_enable(array('bartik', 'seven')); $theme_settings = $this->container->get('config.factory')->get('system.theme'); foreach (array('bartik', 'stark', 'seven') as $theme) { $this->drupalGet('admin/structure/block/list/' . $theme); $this->assertTitle(t('Block layout') . ' | Drupal'); // Select the 'Powered by Drupal' block to be placed. $block = array(); $block['id'] = strtolower($this->randomName()); $block['theme'] = $theme; $block['region'] = 'content'; $this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block')); $this->assertText(t('The block configuration has been saved.')); $this->assertUrl('admin/structure/block/list/' . $theme . '?block-placement=' . drupal_html_class($block['id'])); // Set the default theme and ensure the block is placed. $theme_settings->set('default', $theme)->save(); $this->drupalGet(''); $elements = $this->xpath('//div[@id = :id]', array(':id' => drupal_html_id('block-' . $block['id']))); $this->assertTrue(!empty($elements), 'The block was found.'); } }
/** * Render the interior contents of a single pane. * * This method retrieves pane content and produces a ready-to-render content * object. It also manages pane-specific caching. * * @param stdClass $pane * A Panels pane object, as loaded from the database. * @return stdClass $content * A renderable object, containing a subject, content, etc. Based on the * renderable objects used by the block system. */ function render_pane_content(&$pane) { ctools_include('context'); // TODO finally safe to remove this check? if (!is_array($this->display->context)) { watchdog('panels', 'renderer::render_pane_content() hit with a non-array for the context', $this->display, WATCHDOG_DEBUG); $this->display->context = array(); } $caching = !empty($pane->cache['method']) && empty($this->display->skip_cache); if ($caching && ($cache = panels_get_cached_content($this->display, $this->display->args, $this->display->context, $pane))) { $content = $cache->content; } else { if ($caching) { // This is created before rendering so that calls to drupal_add_js // and drupal_add_css will be captured. $cache = new panels_cache_object(); } $content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, array(), $this->display->args, $this->display->context); foreach (module_implements('panels_pane_content_alter') as $module) { $function = $module . '_panels_pane_content_alter'; $function($content, $pane, $this->display->args, $this->display->context, $this, $this->display); } if ($caching && isset($cache)) { $cache->set_content($content); panels_set_cached_content($cache, $this->display, $this->display->args, $this->display->context, $pane); $content = $cache->content; } } // If there's content, check if we've css configuration to add. if (!empty($content)) { // Pass long the css_id that is usually available. if (!empty($pane->css['css_id'])) { $id = ctools_context_keyword_substitute($pane->css['css_id'], array(), $this->display->context); $content->css_id = drupal_html_id($id); } // Pass long the css_class that is usually available. if (!empty($pane->css['css_class'])) { $class = ctools_context_keyword_substitute($pane->css['css_class'], array(), $this->display->context, array('css safe' => TRUE)); $content->css_class = check_plain(drupal_strtolower($class)); } } return $content; }
/** * Wraps drupal_html_id(). * * @return string */ protected function drupalHtmlId($id) { return drupal_html_id($id); }
/** * {@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; }
/** * Because forms may be split up into sections, this provides * an easy URL to exactly the right section. Don't override this. */ public function optionLink($text, $section, $class = '', $title = '') { if (!empty($class)) { $text = '<span>' . $text . '</span>'; } if (!trim($text)) { $text = t('Broken field'); } if (empty($title)) { $title = $text; } return l($text, 'admin/structure/views/nojs/display/' . $this->view->storage->id() . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => array('views-ajax-link', $class), 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)); }
/** * Custom form radios process function. * * Roll out a single radios element to a list of radios, using the options * array as index. While doing that, create a container element underneath * each option, which contains the settings related to that option. * * @see form_process_radios() */ public static function processContainerRadios($element) { if (count($element['#options']) > 0) { foreach ($element['#options'] as $key => $choice) { $element += array($key => array()); // Generate the parents as the autogenerator does, so we will have a // unique id for each radio button. $parents_for_id = array_merge($element['#parents'], array($key)); $element[$key] += array('#type' => 'radio', '#title' => $choice, '#return_value' => $key, '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL, '#attributes' => $element['#attributes'], '#parents' => $element['#parents'], '#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)), '#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL); $element[$key . '_options'] = array('#type' => 'container', '#attributes' => array('class' => array('views-admin-dependent'))); } } return $element; }