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


PHP String::decodeEntities方法代码示例

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


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

示例1: getLinks

 /**
  * Gets the list of links used by this field.
  *
  * @return array
  *   The links which are used by the render function.
  */
 protected function getLinks()
 {
     $links = array();
     foreach ($this->options['fields'] as $field) {
         if (empty($this->view->field[$field]->last_render_text)) {
             continue;
         }
         $title = $this->view->field[$field]->last_render_text;
         $path = '';
         $url = NULL;
         if (!empty($this->view->field[$field]->options['alter']['path'])) {
             $path = $this->view->field[$field]->options['alter']['path'];
         } elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof UrlObject) {
             $url = $this->view->field[$field]->options['alter']['url'];
         }
         // Make sure that tokens are replaced for this paths as well.
         $tokens = $this->getRenderTokens(array());
         $path = strip_tags(String::decodeEntities($this->viewsTokenReplace($path, $tokens)));
         $links[$field] = array('url' => $path ? UrlObject::fromUri('internal:/' . $path) : $url, 'title' => $title);
         if (!empty($this->options['destination'])) {
             $links[$field]['query'] = drupal_get_destination();
         }
     }
     return $links;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:31,代码来源:Links.php

示例2: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     if (stristr($text, 'data-caption') !== FALSE) {
         $dom = Html::load($text);
         $xpath = new \DOMXPath($dom);
         foreach ($xpath->query('//*[@data-caption]') as $node) {
             // Read the data-caption attribute's value, then delete it.
             $caption = String::checkPlain($node->getAttribute('data-caption'));
             $node->removeAttribute('data-caption');
             // Sanitize caption: decode HTML encoding, limit allowed HTML tags; only
             // allow inline tags that are allowed by default, plus <br>.
             $caption = String::decodeEntities($caption);
             $caption = Xss::filter($caption, array('a', 'em', 'strong', 'cite', 'code', 'br'));
             // The caption must be non-empty.
             if (Unicode::strlen($caption) === 0) {
                 continue;
             }
             // Given the updated node and caption: re-render it with a caption, but
             // bubble up the value of the class attribute of the captioned element,
             // this allows it to collaborate with e.g. the filter_align filter.
             $classes = $node->getAttribute('class');
             $node->removeAttribute('class');
             $filter_caption = array('#theme' => 'filter_caption', '#node' => SafeMarkup::set($node->C14N()), '#tag' => $node->tagName, '#caption' => $caption, '#classes' => $classes);
             $altered_html = drupal_render($filter_caption);
             // Load the altered HTML into a new DOMDocument and retrieve the element.
             $updated_node = Html::load($altered_html)->getElementsByTagName('body')->item(0)->childNodes->item(0);
             // Import the updated node from the new DOMDocument into the original
             // one, importing also the child nodes of the updated node.
             $updated_node = $dom->importNode($updated_node, TRUE);
             // Finally, replace the original image node with the new image node!
             $node->parentNode->replaceChild($updated_node, $node);
         }
         $result->setProcessedText(Html::serialize($dom))->addAssets(array('library' => array('filter/caption')));
     }
     return $result;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:40,代码来源:FilterCaption.php

示例3: getMatches

 /**
  * Returns matched labels based on a given search string.
  *
  * @param string $target_type
  *   The ID of the target entity type.
  * @param string $selection_handler
  *   The plugin ID of the entity reference selection handler.
  * @param array $selection_settings
  *   An array of settings that will be passed to the selection handler.
  * @param string $string
  *   (optional) The label of the entity to query by.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *   Thrown when the current user doesn't have access to the specifies entity.
  *
  * @return array
  *   An array of matched entity labels, in the format required by the AJAX
  *   autocomplete API (e.g. array('value' => $value, 'label' => $label)).
  *
  * @see \Drupal\system\Controller\EntityAutocompleteController
  */
 public function getMatches($target_type, $selection_handler, $selection_settings, $string = '')
 {
     $matches = array();
     $options = array('target_type' => $target_type, 'handler' => $selection_handler, 'handler_settings' => $selection_settings);
     $handler = $this->selectionManager->getInstance($options);
     if (isset($string)) {
         // Get an array of matching entities.
         $match_operator = !empty($selection_settings['match_operator']) ? $selection_settings['match_operator'] : 'CONTAINS';
         $entity_labels = $handler->getReferenceableEntities($string, $match_operator, 10);
         // Loop through the entities and convert them into autocomplete output.
         foreach ($entity_labels as $values) {
             foreach ($values as $entity_id => $label) {
                 $key = "{$label} ({$entity_id})";
                 // Strip things like starting/trailing white spaces, line breaks and
                 // tags.
                 $key = preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', trim(String::decodeEntities(strip_tags($key)))));
                 // Names containing commas or quotes must be wrapped in quotes.
                 $key = Tags::encode($key);
                 $matches[] = array('value' => $key, 'label' => $label);
             }
         }
     }
     return $matches;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:45,代码来源:EntityAutocompleteMatcher.php

示例4: assertNoNormalized

 /**
  * Asserts that text transformed to lowercase with HTML entities decoded does not contain a given string.
  *
  * Otherwise fails the test with a given message, similar to all the
  * SimpleTest assert* functions.
  *
  * Note that this does not remove nulls, new lines, and other character that
  * could be used to obscure a tag or an attribute name.
  *
  * @param $haystack
  *   Text to look in.
  * @param $needle
  *   Lowercase, plain text to look for.
  * @param $message
  *   (optional) Message to display if failed. Defaults to an empty string.
  * @param $group
  *   (optional) The group this message belongs to. Defaults to 'Other'.
  * @return
  *   TRUE on pass, FALSE on fail.
  */
 function assertNoNormalized($haystack, $needle, $message = '', $group = 'Other')
 {
     return $this->assertTrue(strpos(strtolower(String::decodeEntities($haystack)), $needle) === FALSE, $message, $group);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:24,代码来源:FilterUnitTest.php

示例5: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     /** @var \Drupal\comment\CommentInterface $comment */
     $comment = $this->entity;
     // If the comment was posted by a registered user, assign the author's ID.
     // @todo Too fragile. Should be prepared and stored in comment_form()
     // already.
     $author_name = $comment->getAuthorName();
     if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
         $comment->setOwner($account);
     }
     // If the comment was posted by an anonymous user and no author name was
     // required, use "Anonymous" by default.
     if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) {
         $comment->setAuthorName($this->config('user.settings')->get('anonymous'));
     }
     // Validate the comment's subject. If not specified, extract from comment
     // body.
     if (trim($comment->getSubject()) == '') {
         // The body may be in any format, so:
         // 1) Filter it into HTML
         // 2) Strip out all HTML tags
         // 3) Convert entities back to plain-text.
         $comment_text = $comment->comment_body->processed;
         $comment->setSubject(Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE));
         // Edge cases where the comment body is populated only by HTML tags will
         // require a default subject.
         if ($comment->getSubject() == '') {
             $comment->setSubject($this->t('(No subject)'));
         }
     }
     return $comment;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:CommentForm.php

示例6: prepareFilterSelectOptions

 /**
  * Sanitizes the HTML select element's options.
  *
  * The function is recursive to support optgroups.
  */
 protected function prepareFilterSelectOptions(&$options)
 {
     foreach ($options as $value => $label) {
         // Recurse for optgroups.
         if (is_array($label)) {
             $this->prepareFilterSelectOptions($options[$value]);
         } elseif (is_object($label) && isset($label->option)) {
             $this->prepareFilterSelectOptions($options[$value]->option);
         } else {
             // Cast the label to a string since it can be an object.
             // @see \Drupal\Core\StringTranslation\TranslationWrapper
             $options[$value] = strip_tags(UtilityString::decodeEntities((string) $label));
         }
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:20,代码来源:FilterPluginBase.php

示例7: checkForMetaRefresh

 /**
  * Checks for meta refresh tag and if found call drupalGet() recursively.
  *
  * This function looks for the http-equiv attribute to be set to "Refresh" and
  * is case-sensitive.
  *
  * @return
  *   Either the new page content or FALSE.
  */
 protected function checkForMetaRefresh()
 {
     if (strpos($this->getRawContent(), '<meta ') && $this->parse()) {
         $refresh = $this->xpath('//meta[@http-equiv="Refresh"]');
         if (!empty($refresh)) {
             // Parse the content attribute of the meta tag for the format:
             // "[delay]: URL=[page_to_redirect_to]".
             if (preg_match('/\\d+;\\s*URL=(?<url>.*)/i', $refresh[0]['content'], $match)) {
                 return $this->drupalGet($this->getAbsoluteUrl(String::decodeEntities($match['url'])));
             }
         }
     }
     return FALSE;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:23,代码来源:WebTestBase.php

示例8: _buildArguments

 /**
  * Build all the arguments.
  */
 protected function _buildArguments()
 {
     // Initially, we want to build sorts and fields. This can change, though,
     // if we get a summary view.
     if (empty($this->argument)) {
         return TRUE;
     }
     // build arguments.
     $position = -1;
     $substitutions = array();
     $status = TRUE;
     // Get the title.
     $title = $this->display_handler->getOption('title');
     // Iterate through each argument and process.
     foreach ($this->argument as $id => $arg) {
         $position++;
         $argument = $this->argument[$id];
         if ($argument->broken()) {
             continue;
         }
         $argument->setRelationship();
         $arg = isset($this->args[$position]) ? $this->args[$position] : NULL;
         $argument->position = $position;
         if (isset($arg) || $argument->hasDefaultArgument()) {
             if (!isset($arg)) {
                 $arg = $argument->getDefaultArgument();
                 // make sure default args get put back.
                 if (isset($arg)) {
                     $this->args[$position] = $arg;
                 }
                 // remember that this argument was computed, not passed on the URL.
                 $argument->is_default = TRUE;
             }
             // Set the argument, which will also validate that the argument can be set.
             if (!$argument->setArgument($arg)) {
                 $status = $argument->validateFail($arg);
                 break;
             }
             if ($argument->isException()) {
                 $arg_title = $argument->exceptionTitle();
             } else {
                 $arg_title = $argument->getTitle();
                 $argument->query($this->display_handler->useGroupBy());
             }
             // Add this argument's substitution
             $substitutions['%' . ($position + 1)] = $arg_title;
             $substitutions['!' . ($position + 1)] = strip_tags(String::decodeEntities($arg));
             // Test to see if we should use this argument's title
             if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
                 $title = $argument->options['title'];
             }
         } else {
             // determine default condition and handle.
             $status = $argument->defaultAction();
             break;
         }
         // Be safe with references and loops:
         unset($argument);
     }
     // set the title in the build info.
     if (!empty($title)) {
         $this->build_info['title'] = $title;
     }
     // Store the arguments for later use.
     $this->build_info['substitutions'] = $substitutions;
     return $status;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:70,代码来源:ViewExecutable.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     if (stristr($text, 'data-caption') !== FALSE || stristr($text, 'data-align') !== FALSE) {
         $caption_found = FALSE;
         $dom = Html::load($text);
         $xpath = new \DOMXPath($dom);
         foreach ($xpath->query('//*[@data-caption or @data-align]') as $node) {
             $caption = NULL;
             $align = NULL;
             // Retrieve, then remove the data-caption and data-align attributes.
             if ($node->hasAttribute('data-caption')) {
                 $caption = String::checkPlain($node->getAttribute('data-caption'));
                 $node->removeAttribute('data-caption');
                 // Sanitize caption: decode HTML encoding, limit allowed HTML tags;
                 // only allow inline tags that are allowed by default, plus <br>.
                 $caption = String::decodeEntities($caption);
                 $caption = Xss::filter($caption, array('a', 'em', 'strong', 'cite', 'code', 'br'));
                 // The caption must be non-empty.
                 if (Unicode::strlen($caption) === 0) {
                     $caption = NULL;
                 }
             }
             if ($node->hasAttribute('data-align')) {
                 $align = $node->getAttribute('data-align');
                 $node->removeAttribute('data-align');
                 // Only allow 3 values: 'left', 'center' and 'right'.
                 if (!in_array($align, array('left', 'center', 'right'))) {
                     $align = NULL;
                 }
             }
             // Don't transform the HTML if there isn't a caption after validation.
             if ($caption === NULL) {
                 // If there is a valid alignment, then transform the data-align
                 // attribute to a corresponding alignment class.
                 if ($align !== NULL) {
                     $classes = $node->getAttribute('class');
                     $classes = strlen($classes) > 0 ? explode(' ', $classes) : array();
                     $classes[] = 'align-' . $align;
                     $node->setAttribute('class', implode(' ', $classes));
                 }
                 continue;
             } else {
                 $caption_found = TRUE;
             }
             // Given the updated node, caption and alignment: re-render it with a
             // caption.
             $filter_caption = array('#theme' => 'filter_caption', '#node' => SafeMarkup::set($node->C14N()), '#tag' => $node->tagName, '#caption' => $caption, '#align' => $align);
             $altered_html = drupal_render($filter_caption);
             // Load the altered HTML into a new DOMDocument and retrieve the element.
             $updated_node = Html::load($altered_html)->getElementsByTagName('body')->item(0)->childNodes->item(0);
             // Import the updated node from the new DOMDocument into the original
             // one, importing also the child nodes of the updated node.
             $updated_node = $dom->importNode($updated_node, TRUE);
             // Finally, replace the original image node with the new image node!
             $node->parentNode->replaceChild($updated_node, $node);
         }
         $result->setProcessedText(Html::serialize($dom));
         if ($caption_found) {
             $result->addAssets(array('library' => array('filter/caption')));
         }
     }
     return $result;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:67,代码来源:FilterCaption.php

示例10: getArgumentsTokens

 /**
  * {@inheritdoc}
  */
 public function getArgumentsTokens()
 {
     $tokens = array();
     if (!empty($this->view->build_info['substitutions'])) {
         $tokens = $this->view->build_info['substitutions'];
     }
     // Add tokens for every argument (contextual filter) and path arg.
     $handlers = count($this->view->display_handler->getHandlers('argument'));
     for ($count = 1; $count <= $handlers; $count++) {
         if (!isset($tokens["%{$count}"])) {
             $tokens["%{$count}"] = '';
         }
         // Use strip tags as there should never be HTML in the path.
         // However, we need to preserve special characters like " that
         // were removed by String::checkPlain().
         $tokens["!{$count}"] = isset($this->view->args[$count - 1]) ? strip_tags(String::decodeEntities($this->view->args[$count - 1])) : '';
     }
     return $tokens;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:22,代码来源:DisplayPluginBase.php

示例11: htmlToText


//.........这里部分代码省略.........
                     // Ensure blank new-line.
                     $chunk = '';
                     break;
                     // Quotation/list markers, non-fancy headers.
                 // Quotation/list markers, non-fancy headers.
                 case 'blockquote':
                     // Format=flowed indentation cannot be mixed with lists.
                     $indent[] = count($lists) ? ' "' : '>';
                     break;
                 case 'li':
                     $indent[] = isset($lists[0]) && is_numeric($lists[0]) ? ' ' . $lists[0]++ . ') ' : ' * ';
                     break;
                 case 'dd':
                     $indent[] = '    ';
                     break;
                 case 'h3':
                     $indent[] = '.... ';
                     break;
                 case 'h4':
                     $indent[] = '.. ';
                     break;
                 case '/blockquote':
                     if (count($lists)) {
                         // Append closing quote for inline quotes (immediately).
                         $output = rtrim($output, "> \n") . "\"\n";
                         // Ensure blank new-line.
                         $chunk = '';
                     }
                     // Fall-through.
                 // Fall-through.
                 case '/li':
                 case '/dd':
                     array_pop($indent);
                     break;
                 case '/h3':
                 case '/h4':
                     array_pop($indent);
                 case '/h5':
                 case '/h6':
                     // Ensure blank new-line.
                     $chunk = '';
                     break;
                     // Fancy headers.
                 // Fancy headers.
                 case 'h1':
                     $indent[] = '======== ';
                     $casing = '\\Drupal\\Component\\Utility\\Unicode::strtoupper';
                     break;
                 case 'h2':
                     $indent[] = '-------- ';
                     $casing = '\\Drupal\\Component\\Utility\\Unicode::strtoupper';
                     break;
                 case '/h1':
                 case '/h2':
                     $casing = NULL;
                     // Pad the line with dashes.
                     $output = static::htmlToTextPad($output, $tagname == '/h1' ? '=' : '-', ' ');
                     array_pop($indent);
                     // Ensure blank new-line.
                     $chunk = '';
                     break;
                     // Horizontal rulers.
                 // Horizontal rulers.
                 case 'hr':
                     // Insert immediately.
                     $output .= static::wrapMail('', implode('', $indent)) . "\n";
                     $output = static::htmlToTextPad($output, '-');
                     break;
                     // Paragraphs and definition lists.
                 // Paragraphs and definition lists.
                 case '/p':
                 case '/dl':
                     // Ensure blank new-line.
                     $chunk = '';
                     break;
             }
         } else {
             // Convert inline HTML text to plain text; not removing line-breaks or
             // white-space, since that breaks newlines when sanitizing plain-text.
             $value = trim(String::decodeEntities($value));
             if (Unicode::strlen($value)) {
                 $chunk = $value;
             }
         }
         // See if there is something waiting to be output.
         if (isset($chunk)) {
             // Apply any necessary case conversion.
             if (isset($casing)) {
                 $chunk = call_user_func($casing, $chunk);
             }
             $line_endings = Settings::get('mail_line_endings', PHP_EOL);
             // Format it and apply the current indentation.
             $output .= static::wrapMail($chunk, implode('', $indent)) . $line_endings;
             // Remove non-quotation markers from indentation.
             $indent = array_map('\\Drupal\\Core\\Mail\\MailFormatHelper::htmlToTextClean', $indent);
         }
         $tag = !$tag;
     }
     return $output . $footnotes;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:101,代码来源:MailFormatHelper.php

示例12: sanitizeLabel

 /**
  * {@inheritdoc}
  */
 protected function sanitizeLabel(&$label)
 {
     // Select form inputs allow unencoded HTML entities, but no HTML tags.
     $label = String::decodeEntities(strip_tags($label));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:8,代码来源:OptionsSelectWidget.php

示例13: render

 /**
  * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render().
  *
  * Renders the contextual fields.
  *
  * @param \Drupal\views\ResultRow $values
  *   The values retrieved from a single row of a view's query result.
  *
  * @see contextual_preprocess()
  * @see contextual_contextual_links_view_alter()
  */
 public function render(ResultRow $values)
 {
     $links = array();
     foreach ($this->options['fields'] as $field) {
         $rendered_field = $this->view->style_plugin->getField($values->index, $field);
         if (empty($rendered_field)) {
             continue;
         }
         $title = $this->view->field[$field]->last_render_text;
         $path = '';
         if (!empty($this->view->field[$field]->options['alter']['path'])) {
             $path = $this->view->field[$field]->options['alter']['path'];
         } elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof Url) {
             $path = $this->view->field[$field]->options['alter']['url']->toString();
         }
         if (!empty($title) && !empty($path)) {
             // Make sure that tokens are replaced for this paths as well.
             $tokens = $this->getRenderTokens(array());
             $path = strip_tags(String::decodeEntities(strtr($path, $tokens)));
             $links[$field] = array('href' => $path, 'title' => $title);
             if (!empty($this->options['destination'])) {
                 $links[$field]['query'] = drupal_get_destination();
             }
         }
     }
     // Renders a contextual links placeholder.
     if (!empty($links)) {
         $contextual_links = array('contextual' => array('', array(), array('contextual-views-field-links' => UrlHelper::encodePath(Json::encode($links)))));
         $element = array('#type' => 'contextual_links_placeholder', '#id' => _contextual_links_to_id($contextual_links));
         return drupal_render($element);
     } else {
         return '';
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:45,代码来源:ContextualLinks.php

示例14: getTokenValuesRecursive

 /**
  * Recursive function to add replacements for nested query string parameters.
  *
  * E.g. if you pass in the following array:
  *   array(
  *     'foo' => array(
  *       'a' => 'value',
  *       'b' => 'value',
  *     ),
  *     'bar' => array(
  *       'a' => 'value',
  *       'b' => array(
  *         'c' => value,
  *       ),
  *     ),
  *   );
  *
  * Would yield the following array of tokens:
  *   array(
  *     '%foo_a' => 'value'
  *     '%foo_b' => 'value'
  *     '%bar_a' => 'value'
  *     '%bar_b_c' => 'value'
  *   );
  *
  * @param $array
  *   An array of values.
  *
  * @param $parent_keys
  *   An array of parent keys. This will represent the array depth.
  *
  * @return
  *   An array of available tokens, with nested keys representative of the array structure.
  */
 protected function getTokenValuesRecursive(array $array, array $parent_keys = array())
 {
     $tokens = array();
     foreach ($array as $param => $val) {
         if (is_array($val)) {
             // Copy parent_keys array, so we don't affect other elements of this
             // iteration.
             $child_parent_keys = $parent_keys;
             $child_parent_keys[] = $param;
             // Get the child tokens.
             $child_tokens = $this->getTokenValuesRecursive($val, $child_parent_keys);
             // Add them to the current tokens array.
             $tokens += $child_tokens;
         } else {
             // Create a token key based on array element structure.
             $token_string = !empty($parent_keys) ? implode('_', $parent_keys) . '_' . $param : $param;
             $tokens['%' . $token_string] = strip_tags(String::decodeEntities($val));
         }
     }
     return $tokens;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:55,代码来源:FieldPluginBase.php

示例15: testAlterUrl

 /**
  * Tests rewriting the output to a link.
  */
 public function testAlterUrl()
 {
     $view = Views::getView('test_view');
     $view->setDisplay();
     $view->initHandlers();
     $this->executeView($view);
     $row = $view->result[0];
     $id_field = $view->field['id'];
     // Setup the general settings required to build a link.
     $id_field->options['alter']['make_link'] = TRUE;
     $id_field->options['alter']['path'] = $path = $this->randomMachineName();
     // Tests that the suffix/prefix appears on the output.
     $id_field->options['alter']['prefix'] = $prefix = $this->randomMachineName();
     $id_field->options['alter']['suffix'] = $suffix = $this->randomMachineName();
     $output = $id_field->theme($row);
     $this->assertSubString($output, $prefix);
     $this->assertSubString($output, $suffix);
     unset($id_field->options['alter']['prefix']);
     unset($id_field->options['alter']['suffix']);
     $output = $id_field->theme($row);
     $this->assertSubString($output, $path, 'Make sure that the path is part of the output');
     // Some generic test code adapted from the UrlTest class, which tests
     // mostly the different options for the path.
     global $base_url, $script_path;
     foreach (array(FALSE, TRUE) as $absolute) {
         $alter =& $id_field->options['alter'];
         $alter['path'] = 'node/123';
         $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['absolute' => $absolute]);
         $alter['absolute'] = $absolute;
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
         $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['fragment' => 'foo', 'absolute' => $absolute]);
         $alter['path'] = 'node/123#foo';
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
         $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'absolute' => $absolute]);
         $alter['path'] = 'node/123?foo';
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
         $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => 'bar', 'bar' => 'baz'], 'absolute' => $absolute]);
         $alter['path'] = 'node/123?foo=bar&bar=baz';
         $result = $id_field->theme($row);
         $this->assertSubString(String::decodeEntities($result), String::decodeEntities($expected_result));
         // @todo The route-based URL generator strips out NULL attributes.
         // $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'fragment' => 'bar', 'absolute' => $absolute]);
         $expected_result = \Drupal::urlGenerator()->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute));
         $alter['path'] = 'node/123?foo#bar';
         $result = $id_field->theme($row);
         $this->assertSubString(String::decodeEntities($result), String::decodeEntities($expected_result));
         $expected_result = \Drupal::url('<front>', [], ['absolute' => $absolute]);
         $alter['path'] = '<front>';
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
     }
     // Tests the replace spaces with dashes feature.
     $id_field->options['alter']['replace_spaces'] = TRUE;
     $id_field->options['alter']['path'] = $path = $this->randomMachineName() . ' ' . $this->randomMachineName();
     $output = $id_field->theme($row);
     $this->assertSubString($output, str_replace(' ', '-', $path));
     $id_field->options['alter']['replace_spaces'] = FALSE;
     $output = $id_field->theme($row);
     // The url has a space in it, so to check we have to decode the url output.
     $this->assertSubString(urldecode($output), $path);
     // Tests the external flag.
     // Switch on the external flag should output an external url as well.
     $id_field->options['alter']['external'] = TRUE;
     $id_field->options['alter']['path'] = $path = 'drupal.org';
     $output = $id_field->theme($row);
     $this->assertSubString($output, 'http://drupal.org');
     // Setup a not external url, which shouldn't lead to an external url.
     $id_field->options['alter']['external'] = FALSE;
     $id_field->options['alter']['path'] = $path = 'drupal.org';
     $output = $id_field->theme($row);
     $this->assertNotSubString($output, 'http://drupal.org');
     // Tests the transforming of the case setting.
     $id_field->options['alter']['path'] = $path = $this->randomMachineName();
     $id_field->options['alter']['path_case'] = 'none';
     $output = $id_field->theme($row);
     $this->assertSubString($output, $path);
     // Switch to uppercase and lowercase.
     $id_field->options['alter']['path_case'] = 'upper';
     $output = $id_field->theme($row);
     $this->assertSubString($output, strtoupper($path));
     $id_field->options['alter']['path_case'] = 'lower';
     $output = $id_field->theme($row);
     $this->assertSubString($output, strtolower($path));
     // Switch to ucfirst and ucwords.
     $id_field->options['alter']['path_case'] = 'ucfirst';
     $id_field->options['alter']['path'] = 'drupal has a great community';
     $output = $id_field->theme($row);
     $this->assertSubString($output, UrlHelper::encodePath('Drupal has a great community'));
     $id_field->options['alter']['path_case'] = 'ucwords';
     $output = $id_field->theme($row);
     $this->assertSubString($output, UrlHelper::encodePath('Drupal Has A Great Community'));
     unset($id_field->options['alter']['path_case']);
     // Tests the linkclass setting and see whether it actuall exists in the output.
     $id_field->options['alter']['link_class'] = $class = $this->randomMachineName();
//.........这里部分代码省略.........
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:101,代码来源:FieldWebTest.php


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