当前位置: 首页>>代码示例>>PHP>>正文


PHP drupal_html_id函数代码示例

本文整理汇总了PHP中drupal_html_id函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_html_id函数的具体用法?PHP drupal_html_id怎么用?PHP drupal_html_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了drupal_html_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preRenderLink

 /**
  * 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;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:49,代码来源:Link.php

示例2: preBuild

 /**
  * {@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);
 }
开发者ID:akapivo,项目名称:www.dmi.be,代码行数:36,代码来源:LayerSwitcher.php

示例3: bootstrap_preprocess_bootstrap_panel

/**
 * 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;
}
开发者ID:himolde,项目名称:sjoportalen,代码行数:68,代码来源:bootstrap-panel.vars.php

示例4: getAriaId

 /**
  * 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;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:TipPluginText.php

示例5: processContainer

 /**
  * 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;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:22,代码来源:Container.php

示例6: getId

 /**
  * {@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;
 }
开发者ID:josemrc,项目名称:ae2web,代码行数:13,代码来源:Map.php

示例7: bootstrap_preprocess_bootstrap_modal

/**
 * 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']);
}
开发者ID:Lanou94,项目名称:intranet,代码行数:17,代码来源:bootstrap-modal.vars.php

示例8: preRender

 /**
  * {@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')));
     }
 }
开发者ID:lokeoke,项目名称:d8intranet,代码行数:16,代码来源:Fieldset.php

示例9: preRender

 /**
  * {@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'));
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:16,代码来源:Details.php

示例10: view

 /**
  * 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;
 }
开发者ID:bunnywong,项目名称:isnatura.com.hk,代码行数:18,代码来源:CommerceCbaAddress.class.php

示例11: testDrupalHTMLId

 /**
  * 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.');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:HtmlIdentifierUnitTest.php

示例12: menta_menu_link

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";
}
开发者ID:bruria1,项目名称:menta,代码行数:16,代码来源:template.php

示例13: view

 /**
  * 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;
 }
开发者ID:bunnywong,项目名称:isnatura.com.hk,代码行数:19,代码来源:CommerceCbaWallet.class.php

示例14: init

 /**
  * {@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());
     }
 }
开发者ID:EMerino236,项目名称:afiperudrupal,代码行数:20,代码来源:Object.php

示例15: testBlockCategory

 /**
  * 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.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:49,代码来源:DisplayBlockTest.php


注:本文中的drupal_html_id函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。