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


PHP Html::getUniqueId方法代码示例

本文整理汇总了PHP中Drupal\Component\Utility\Html::getUniqueId方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::getUniqueId方法的具体用法?PHP Html::getUniqueId怎么用?PHP Html::getUniqueId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Component\Utility\Html的用法示例。


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

示例1: preRenderToolbarItem

 /**
  * Provides markup for associating a tray trigger with a tray element.
  *
  * A tray is a responsive container that wraps renderable content. Trays
  * present content well on small and large screens alike.
  *
  * @param array $element
  *   A renderable array.
  *
  * @return array
  *   A renderable array.
  */
 public static function preRenderToolbarItem($element)
 {
     // Assign each item a unique ID.
     $id = Html::getUniqueId('toolbar-item');
     // Provide attributes for a toolbar item.
     $attributes = array('id' => $id);
     // If tray content is present, markup the tray and its associated trigger.
     if (!empty($element['tray'])) {
         // Provide attributes necessary for trays.
         $attributes += array('data-toolbar-tray' => $id . '-tray', 'aria-owns' => $id, 'role' => 'button', 'aria-pressed' => 'false');
         // Merge in module-provided attributes.
         $element['tab'] += array('#attributes' => array());
         $element['tab']['#attributes'] += $attributes;
         $element['tab']['#attributes']['class'][] = 'trigger';
         // Provide attributes for the tray theme wrapper.
         $attributes = array('id' => $id . '-tray', 'data-toolbar-tray' => $id . '-tray', 'aria-owned-by' => $id);
         // Merge in module-provided attributes.
         if (!isset($element['tray']['#wrapper_attributes'])) {
             $element['tray']['#wrapper_attributes'] = array();
         }
         $element['tray']['#wrapper_attributes'] += $attributes;
         $element['tray']['#wrapper_attributes']['class'][] = 'toolbar-tray';
     }
     $element['tab']['#attributes']['class'][] = 'toolbar-item';
     return $element;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:38,代码来源:ToolbarItem.php

示例2: 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'] = HtmlUtility::getUniqueId('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:Nikola-xiii,项目名称:d8intranet,代码行数:49,代码来源:Link.php

示例3: preprocessVariables

 /**
  * {@inheritdoc}
  */
 protected function preprocessVariables(Variables $variables, $hook, array $info)
 {
     // Retrieve the ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-carousel')));
     unset($variables['id']);
     // Build slides.
     foreach ($variables->slides as $key => &$slide) {
         if (!isset($slide['attributes'])) {
             $slide['attributes'] = [];
         }
         $slide['attributes'] = new Attribute($slide['attributes']);
     }
     // Build controls.
     if ($variables->controls) {
         $left_icon = Bootstrap::glyphicon('chevron-left');
         $right_icon = Bootstrap::glyphicon('chevron-right');
         $url = Url::fromUserInput("#{$id}");
         $variables->controls = ['left' => ['#type' => 'link', '#title' => new FormattableMarkup(Element::create($left_icon)->render() . '<span class="sr-only">@text</span>', ['@text' => t('Previous')]), '#url' => $url, '#attributes' => ['class' => ['left', 'carousel-control'], 'role' => 'button', 'data-slide' => 'prev']], 'right' => ['#type' => 'link', '#title' => new FormattableMarkup(Element::create($right_icon)->render() . '<span class="sr-only">@text</span>', ['@text' => t('Next')]), '#url' => $url, '#attributes' => ['class' => ['right', 'carousel-control'], 'role' => 'button', 'data-slide' => 'next']]];
     }
     // Build indicators.
     if ($variables->indicators) {
         $variables->indicators = ['#theme' => 'item_list__bootstrap_carousel_indicators', '#list_type' => 'ol', '#items' => array_keys($variables->slides), '#target' => "#{$id}", '#start_index' => $variables->start_index];
     }
     // Ensure all attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:29,代码来源:BootstrapCarousel.php

示例4: form

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);

    $form['#title'] = $this->t('Edit subqueue %label', ['%label' => $this->entity->label()]);

    // Since the form has ajax buttons, the $wrapper_id will change each time
    // one of those buttons is clicked. Therefore the whole form has to be
    // replaced, otherwise the buttons will have the old $wrapper_id and will
    // only work on the first click.
    if ($form_state->has('subqueue_form_wrapper_id')) {
      $wrapper_id = $form_state->get('subqueue_form_wrapper_id');
    }
    else {
      $wrapper_id = Html::getUniqueId($this->getFormId() . '-wrapper');
    }

    $form_state->set('subqueue_form_wrapper_id', $wrapper_id);
    $form['#prefix'] = '<div id="' . $wrapper_id . '">';
    $form['#suffix'] = '</div>';

    // @todo Consider creating a 'Machine name' field widget.
    $form['name'] = [
      '#type' => 'machine_name',
      '#default_value' => $this->entity->id(),
      '#machine_name' => array(
        'exists' => '\Drupal\entityqueue\Entity\EntitySubqueue::load',
        'source' => ['title', 'widget', 0, 'value'],
      ),
      '#disabled' => !$this->entity->isNew(),
      '#weight' => -5,
      '#access' => !$this->entity->getQueue()->getHandlerPlugin()->hasAutomatedSubqueues(),
    ];

    return $form;
  }
开发者ID:jkyto,项目名称:agolf,代码行数:38,代码来源:EntitySubqueueForm.php

示例5: preprocessVariables

 /**
  * {@inheritdoc}
  */
 protected function preprocessVariables(Variables $variables, $hook, array $info)
 {
     // Retrieve the ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'bootstrap-panel')));
     unset($variables['id']);
     // Handle collapsible state.
     if ($variables['heading'] && $variables['collapsible']) {
         // Retrieve the body ID attribute.
         if ($body_id = $variables->getAttribute('id', "{$id}--content", 'body_attributes')) {
             // Ensure the target is set.
             if ($variables['target'] = $variables->offsetGet('target', "#{$body_id}")) {
                 // Set additional necessary attributes to the heading.
                 $variables->setAttributes(['aria-controls' => preg_replace('/^#/', '', $variables['target']), 'aria-expanded' => !$variables['collapsed'] ? 'true' : 'false', 'aria-pressed' => !$variables['collapsed'] ? 'true' : 'false', 'data-toggle' => 'collapse', 'role' => 'button'], 'heading_attributes');
             }
         }
     }
     // Ensure there is a valid panel state.
     if (!$variables->offsetGet('panel_type')) {
         $variables->offsetSet('panel_type', 'default');
     }
     // Convert the description variable.
     $this->preprocessDescription($variables, $hook, $info);
     // Ensure all attributes are proper objects.
     $this->preprocessAttributes($variables, $hook, $info);
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:28,代码来源:BootstrapPanel.php

示例6: at_core_submit_mobile_blocks

/**
 * Submit Mobile Blocks settings.
 * @param $values
 * @param $theme
 * @param $generated_files_path
 */
function at_core_submit_mobile_blocks($values, $theme, $generated_files_path)
{
    $mobile_blocks_css = array();
    // TODO entityManager() is deprecated, but how to replace?
    $theme_blocks = \Drupal::entityManager()->getStorage('block')->loadByProperties(['theme' => $theme]);
    if (!empty($theme_blocks)) {
        foreach ($theme_blocks as $block_key => $block_values) {
            $block_id = $block_values->id();
            if (isset($values['settings_mobile_block_show_' . $block_id]) && $values['settings_mobile_block_show_' . $block_id] == 1) {
                $block_selector = '#' . Html::getUniqueId('block-' . $block_id);
                $mobile_blocks_css[] = $block_selector . ' {display:none}' . "\n";
                $mobile_blocks_css[] = '.is-mobile ' . $block_selector . ' {display:block}' . "\n";
            }
            if (isset($values['settings_mobile_block_hide_' . $block_id]) && $values['settings_mobile_block_hide_' . $block_id] == 1) {
                $block_selector = '#' . Html::getUniqueId('block-' . $block_id);
                $mobile_blocks_css[] = '.is-mobile ' . $block_selector . ' {display:none}' . "\n";
                $mobile_blocks_css[] = $block_selector . ' {display:block}' . "\n";
            }
        }
    }
    if (!empty($mobile_blocks_css)) {
        $file_name = 'mobile-blocks.css';
        $filepath = $generated_files_path . '/' . $file_name;
        file_unmanaged_save_data($mobile_blocks_css, $filepath, FILE_EXISTS_REPLACE);
    }
}
开发者ID:neetumorwani,项目名称:blogging,代码行数:32,代码来源:mobile_blocks_submit.php

示例7: at_core_submit_mobile_blocks

/**
 * @file
 * Save Breadcrumb CSS to file
 */
function at_core_submit_mobile_blocks($values, $theme, $generated_files_path) {
  $mobile_blocks_css = array();
  $theme_blocks = entity_load_multiple_by_properties('block', ['theme' => $theme]);

  if (!empty($theme_blocks)) {
    foreach ($theme_blocks as $block_key => $block_values) {
      $block_id = $block_values->id();
      if (isset($values['settings_mobile_block_show_' . $block_id]) && $values['settings_mobile_block_show_' . $block_id] == 1) {
        $block_selector = '#' . Html::getUniqueId('block-' . $block_id);
        $mobile_blocks_css[] = $block_selector . ' {display:none}' . "\n";
        $mobile_blocks_css[] = '.is-mobile ' . $block_selector . ' {display:block}' . "\n";
      }
      if (isset($values['settings_mobile_block_hide_' . $block_id]) && $values['settings_mobile_block_hide_' . $block_id] == 1) {
        $block_selector = '#' . Html::getUniqueId('block-' . $block_id);
        $mobile_blocks_css[] = '.is-mobile ' . $block_selector . ' {display:none}' . "\n";
        $mobile_blocks_css[] = $block_selector . ' {display:block}' . "\n";
      }
    }
  }

  if (!empty($mobile_blocks_css)) {
    $file_name = 'mobile-blocks.css';
    $filepath = $generated_files_path . '/' . $file_name;
    file_unmanaged_save_data($mobile_blocks_css, $filepath, FILE_EXISTS_REPLACE);
  }
}
开发者ID:jno84,项目名称:drupal8,代码行数:30,代码来源:mobile_blocks_submit.php

示例8: getFormId

 /**
  * {@inheritdoc}
  */
 public function getFormId()
 {
     /* @var $transition WorkflowTransitionInterface */
     $transition = $this->entity;
     $field_name = $transition->getFieldName();
     /* @var $entity EntityInterface */
     // Entity may be empty on VBO bulk form.
     // $entity = $transition->getTargetEntity();
     // Compose Form Id from string + Entity Id + Field name.
     // Field ID contains entity_type, bundle, field_name.
     // The Form Id is unique, to allow for multiple forms per page.
     // $workflow_type_id = $transition->getWorkflowId();
     // Field name contains implicit entity_type & bundle (since 1 field per entity)
     // $entity_type = $transition->getTargetEntityTypeId();
     // $entity_id = $transition->getTargetEntityId();;
     // Emulate nodeForm convention.
     if ($transition->id()) {
         $suffix = 'edit_form';
     } else {
         $suffix = 'form';
     }
     $form_id = implode('_', array('workflow_transition', $field_name, $suffix));
     $form_id = Html::getUniqueId($form_id);
     return $form_id;
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:28,代码来源:WorkflowTransitionForm.php

示例9: render

 /**
  * Overrides \Drupal\views\Plugin\views\display\PathPluginBase::render().
  */
 public function render()
 {
     if (!empty($this->options['geolocation_field'])) {
         $geo_field = $this->options['geolocation_field'];
         $this->view->field[$geo_field]->options['exclude'] = TRUE;
     } else {
         // TODO: Throw some exception here, we're done.
         return [];
     }
     if (!empty($this->options['title_field'])) {
         $title_field = $this->options['title_field'];
         $this->view->field[$title_field]->options['exclude'] = TRUE;
     }
     $id = \Drupal\Component\Utility\Html::getUniqueId($this->pluginId);
     $build = ['#theme' => 'geolocation_common_map_display', '#id' => $id, '#attached' => ['library' => ['geolocation/geolocation.commonmap'], 'drupalSettings' => ['geolocation' => ['commonMap' => ['id' => $id]]]]];
     foreach ($this->view->result as $row) {
         if (!empty($title_field)) {
             $title_field_handler = $this->view->field[$title_field];
             $title_build = array('#theme' => $title_field_handler->themeFunctions(), '#view' => $title_field_handler->view, '#field' => $title_field_handler, '#row' => $row);
         }
         $geo_items = $this->view->field[$geo_field]->getItems($row);
         foreach ($geo_items as $delta => $item) {
             $geolocation = $item['raw'];
             $position = ['lat' => $geolocation->lat, 'lng' => $geolocation->lng];
             $build['#locations'][] = ['#theme' => 'geolocation_common_map_location', '#content' => $this->view->rowPlugin->render($row), '#title' => empty($title_build) ? '' : $title_build, '#position' => $position];
         }
     }
     $centre = NULL;
     foreach ($this->options['centre'] as $id => $option) {
         if (empty($option['enable'])) {
             continue;
         }
         switch ($id) {
             case 'fixed_value':
                 $centre = ['lat' => (double) $option['settings']['latitude'], 'lng' => (double) $option['settings']['longitude']];
                 break;
             case preg_match('/proximity_filter_*/', $id) ? true : false:
                 $filter_id = substr($id, 17);
                 $handler = $this->displayHandler->getHandler('filter', $filter_id);
                 if ($handler->value['lat'] && $handler->value['lng']) {
                     $centre = ['lat' => (double) $handler->value['lat'], 'lng' => (double) $handler->value['lng']];
                 }
                 break;
             case 'first_row':
                 if (!empty($build['#locations'][0]['#position'])) {
                     $centre = $build['#locations'][0]['#position'];
                 }
                 break;
         }
         if (!empty($centre['lat']) || !empty($centre['lng']) || !empty($centre['locate'])) {
             // We're done, no need for further options.
             break;
         }
     }
     if (!empty($centre)) {
         $build['#centre'] = $centre;
     }
     return $build;
 }
开发者ID:blakefrederick,项目名称:sas-backend,代码行数:62,代码来源:CommonMap.php

示例10: 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'] = HtmlUtility::getUniqueId(implode('-', $element['#parents']) . '-wrapper');
     }
     return $element;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:Container.php

示例11: 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 = Html::getUniqueId($this->get('id'));
     }
     return $id;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:14,代码来源:TipPluginText.php

示例12: preprocessVariables

 /**
  * {@inheritdoc}
  */
 public function preprocessVariables(Variables $variables)
 {
     // Ensure a unique ID, generating one if needed.
     $id = $variables->getAttribute('id', Html::getUniqueId($variables->offsetGet('id', 'progress-bar')));
     $variables->setAttribute('id', $id);
     unset($variables['id']);
     // Preprocess attributes.
     $this->preprocessAttributes();
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:12,代码来源:ProgressBar.php

示例13: bootstrap_preprocess_bootstrap_panel

/**
 * Pre-processes variables for the "bootstrap_panel" theme hook.
 *
 * See template for list of available variables.
 *
 * @see bootstrap-panel.html.twig
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_bootstrap_panel(&$variables)
{
    $element = $variables['element'];
    Element::setAttributes($element, array('id'));
    Element\RenderElement::setAttributes($element);
    $variables['attributes'] = $element['#attributes'];
    $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
    $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
    $variables['title_display'] = isset($element['#title_display']) ? $element['#title_display'] : NULL;
    $variables['children'] = $element['#children'];
    $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
    $variables['legend']['title'] = !empty($element['#title']) ? Xss::filterAdmin($element['#title']) : '';
    $variables['legend']['attributes'] = new Attribute();
    $variables['legend_span']['attributes'] = new Attribute();
    if (!empty($element['#description'])) {
        $description_id = $element['#attributes']['id'] . '--description';
        $description_attributes['id'] = $description_id;
        $variables['description']['attributes'] = new Attribute($description_attributes);
        $variables['description']['content'] = $element['#description'];
        // Add the description's id to the fieldset aria attributes.
        $variables['attributes']['aria-describedby'] = $description_id;
    }
    $variables['collapsible'] = FALSE;
    if (isset($element['#collapsible'])) {
        $variables['collapsible'] = $element['#collapsible'];
        $variables['attributes']['class'][] = '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\Component\Utility\Html::getUniqueId('bootstrap-panel');
    }
    $variables['target'] = NULL;
    if (isset($element['#id'])) {
        if (!isset($variables['attributes']['id'])) {
            $variables['attributes']['id'] = $element['#id'];
        }
        $variables['target'] = '#' . $element['#id'] . ' > .collapse';
    }
    // Iterate over optional variables.
    $keys = array('description', 'prefix', 'suffix', 'title', 'value');
    foreach ($keys as $key) {
        $variables[$key] = !empty($element["#{$key}"]) ? $element["#{$key}"] : FALSE;
    }
}
开发者ID:sathishRio,项目名称:themes,代码行数:61,代码来源:bootstrap-panel.vars.php

示例14: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('payment_form.payment_type');
     $form['plugin_selector'] = $this->getPluginSelector($form_state)->buildSelectorForm([], $form_state);
     $limit_allowed_plugins_id = Html::getUniqueId('limit_allowed_plugins');
     $form['limit_allowed_plugins'] = ['#default_value' => $config->get('limit_allowed_plugins'), '#id' => $limit_allowed_plugins_id, '#title' => $this->t('Limit allowed payment methods'), '#type' => 'checkbox'];
     $allowed_plugin_ids = $config->get('allowed_plugin_ids');
     $options = [];
     foreach ($this->paymentMethodManager->getDefinitions() as $definition) {
         $options[$definition['id']] = $definition['label'];
     }
     $form['allowed_plugin_ids'] = ['#default_value' => $allowed_plugin_ids, '#multiple' => TRUE, '#options' => $options, '#states' => ['visible' => ['#' . $limit_allowed_plugins_id => ['checked' => TRUE]]], '#title' => $this->t('Allowed payment methods'), '#type' => 'select'];
     return $form + parent::buildForm($form, $form_state);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:17,代码来源:PaymentFormConfigurationForm.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' . Html::getClass($edit['id']) . '-block-1', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_1', 'theme' => 'classy')), ':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 = Html::getUniqueId('edit-category-' . SafeMarkup::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' . Html::getClass($edit['id']) . '-block-2', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_2', 'theme' => 'classy')), ':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' . Html::getClass($edit['id']) . '-block-3', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_3', 'theme' => 'classy')), ':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:brstde,项目名称:gap1,代码行数:49,代码来源:DisplayBlockTest.php


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