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


PHP UrlHelper::encodePath方法代码示例

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


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

示例1: getExternalUrl

  /**
   * Override getExternalUrl().
   *
   * Return the HTML URI of a public file.
   */
  public function getExternalUrl() {
    $path = str_replace('\\', '/', $this->getTarget());

    return PublicStream::baseUrl() . '/' . UrlHelper::encodePath($path);
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:10,代码来源:FileFieldPathsDummyReadOnlyStreamWrapper.php

示例2: getExternalUrl

 /**
  * {@inheritdoc}
  */
 public function getExternalUrl()
 {
     $path = str_replace('\\', '/', $this->getTarget());
     return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . UrlHelper::encodePath($path);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:8,代码来源:PublicStream.php

示例3: testAlterUrl


//.........这里部分代码省略.........
         $alter['path'] = '<front>';
         $result = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
             return $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 = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $this->assertSubString($output, str_replace(' ', '-', $path));
     $id_field->options['alter']['replace_spaces'] = FALSE;
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $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 = 'www.drupal.org';
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $this->assertSubString($output, 'http://www.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 = 'www.drupal.org';
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $this->assertNotSubString($output, 'http://www.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 = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $this->assertSubString($output, $path);
     // Switch to uppercase and lowercase.
     $id_field->options['alter']['path_case'] = 'upper';
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $this->assertSubString($output, strtoupper($path));
     $id_field->options['alter']['path_case'] = 'lower';
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $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 = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $this->assertSubString($output, UrlHelper::encodePath('Drupal has a great community'));
     $id_field->options['alter']['path_case'] = 'ucwords';
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $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 actually exists in the
     // output.
     $id_field->options['alter']['link_class'] = $class = $this->randomMachineName();
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $elements = $this->xpathContent($output, '//a[contains(@class, :class)]', array(':class' => $class));
     $this->assertTrue($elements);
     // @fixme link_class, alt, rel cannot be unset, which should be fixed.
     $id_field->options['alter']['link_class'] = '';
     // Tests the alt setting.
     $id_field->options['alter']['alt'] = $rel = $this->randomMachineName();
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $elements = $this->xpathContent($output, '//a[contains(@title, :alt)]', array(':alt' => $rel));
     $this->assertTrue($elements);
     $id_field->options['alter']['alt'] = '';
     // Tests the rel setting.
     $id_field->options['alter']['rel'] = $rel = $this->randomMachineName();
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $elements = $this->xpathContent($output, '//a[contains(@rel, :rel)]', array(':rel' => $rel));
     $this->assertTrue($elements);
     $id_field->options['alter']['rel'] = '';
     // Tests the target setting.
     $id_field->options['alter']['target'] = $target = $this->randomMachineName();
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($id_field, $row) {
         return $id_field->theme($row);
     });
     $elements = $this->xpathContent($output, '//a[contains(@target, :target)]', array(':target' => $target));
     $this->assertTrue($elements);
     unset($id_field->options['alter']['target']);
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:101,代码来源:FieldWebTest.php

示例4: testEncodePath

 /**
  * Tests path encoding.
  *
  * @dataProvider providerTestEncodePath
  * @covers ::encodePath
  *
  * @param string $path
  *   A path to encode.
  * @param string $expected
  *   The expected encoded path.
  */
 public function testEncodePath($path, $expected)
 {
     $encoded = UrlHelper::encodePath($path);
     $this->assertEquals($expected, $encoded);
 }
开发者ID:scratch,项目名称:gai,代码行数:16,代码来源:UrlHelperTest.php

示例5: 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(Html::decodeEntities(strtr($path, $tokens)));
             $links[$field] = array('href' => $path, 'title' => $title);
             if (!empty($this->options['destination'])) {
                 $links[$field]['query'] = $this->getDestinationArray();
             }
         }
     }
     // 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:nstielau,项目名称:drops-8,代码行数:45,代码来源:ContextualLinks.php

示例6: 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->randomName();
     // Tests that the suffix/prefix appears on the output.
     $id_field->options['alter']['prefix'] = $prefix = $this->randomName();
     $id_field->options['alter']['suffix'] = $suffix = $this->randomName();
     $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) {
         // Get the expected start of the path string.
         $base = ($absolute ? $base_url . '/' : base_path()) . $script_path;
         $absolute_string = $absolute ? 'absolute' : NULL;
         $alter =& $id_field->options['alter'];
         $alter['path'] = 'node/123';
         $expected_result = url('node/123', array('absolute' => $absolute));
         $alter['absolute'] = $absolute;
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
         $expected_result = url('node/123', array('fragment' => 'foo', 'absolute' => $absolute));
         $alter['path'] = 'node/123#foo';
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
         $expected_result = url('node/123', array('query' => array('foo' => NULL), 'absolute' => $absolute));
         $alter['path'] = 'node/123?foo';
         $result = $id_field->theme($row);
         $this->assertSubString($result, $expected_result);
         $expected_result = url('node/123', array('query' => array('foo' => 'bar', 'bar' => 'baz'), 'absolute' => $absolute));
         $alter['path'] = 'node/123?foo=bar&bar=baz';
         $result = $id_field->theme($row);
         $this->assertSubString(decode_entities($result), decode_entities($expected_result));
         $expected_result = url('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute));
         $alter['path'] = 'node/123?foo#bar';
         $result = $id_field->theme($row);
         // @fixme: The actual result is node/123?foo#bar so views has a bug here.
         // $this->assertSubStringExists(decode_entities($result), decode_entities($expected_result));
         $expected_result = url('<front>', array('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->randomName() . ' ' . $this->randomName();
     $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->randomName();
     $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']);
//.........这里部分代码省略.........
开发者ID:alnutile,项目名称:drunatra,代码行数:101,代码来源:FieldWebTest.php


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