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


PHP UrlHelper::isValid方法代码示例

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


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

示例1: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Validate video URL.
     if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
         $form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
     }
 }
开发者ID:shawnmmatthews,项目名称:gerber8,代码行数:10,代码来源:ContributeForm.php

示例2: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (isset($value)) {
         $url_is_valid = TRUE;
         /** @var $link_item \Drupal\link\LinkItemInterface */
         $link_item = $value;
         $link_type = $link_item->getFieldDefinition()->getSetting('link_type');
         $url_string = $link_item->url;
         // Validate the url property.
         if ($url_string !== '') {
             try {
                 // @todo This shouldn't be needed, but massageFormValues() may not
                 //   run.
                 $parsed_url = UrlHelper::parse($url_string);
                 $url = Url::createFromPath($parsed_url['path']);
                 if ($url->isExternal() && !UrlHelper::isValid($url_string, TRUE)) {
                     $url_is_valid = FALSE;
                 } elseif ($url->isExternal() && !($link_type & LinkItemInterface::LINK_EXTERNAL)) {
                     $url_is_valid = FALSE;
                 }
             } catch (NotFoundHttpException $e) {
                 $url_is_valid = FALSE;
             } catch (MatchingRouteNotFoundException $e) {
                 $url_is_valid = FALSE;
             } catch (ParamNotConvertedException $e) {
                 $url_is_valid = FALSE;
             }
         }
         if (!$url_is_valid) {
             $this->context->addViolation($this->message, array('%url' => $url_string));
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:36,代码来源:LinkTypeConstraint.php

示例3: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     $values['uri'] = trim($values['uri']);
     if (!UrlHelper::isValid($values['uri'], TRUE)) {
         $values['uri'] = '';
     }
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:10,代码来源:Link.php

示例4: blockValidate

 /**
  * {@inheritdoc}
  */
 public function blockValidate($form, FormStateInterface $form_state)
 {
     // Instantiate UrlHelper object to validate the URL's.
     $url_helper = new UrlHelper();
     // Build an array of the links that need validating. If more fields are
     // added later, add another entry to the links array.
     $links = [];
     $links['pantheon_url'] = $form_state->getValue('pantheon_url');
     // Create an error variable to prevent setting the error message repeatedly.
     $error_set = FALSE;
     // Validate and set errors where appropriate.
     foreach ($links as $key => $link) {
         if ($link == '') {
             break;
         }
         $validity = $url_helper->isValid($link, TRUE);
         if ($validity != TRUE) {
             $form_state->setErrorByName($key, "The value must be a full URL similar to http://www.example.com.");
             // Using drupal_set_message because of a bug with setError that is
             // causing the form to not submit correctly, but isn't displaying
             // messages.
             if ($error_set == FALSE) {
                 drupal_set_message('All values must be full URLs of format: http://www.example.com.', 'error');
                 // Prevent the error from outputting multiple times.
                 $error_set = TRUE;
             }
         }
     }
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:32,代码来源:PantheonLinkBlock.php

示例5: validateUrl

 /**
  * Form element validation handler for #type 'url'.
  *
  * Note that #maxlength and #required is validated by _form_validate() already.
  */
 public static function validateUrl(&$element, FormStateInterface $form_state, &$complete_form)
 {
     $value = trim($element['#value']);
     $form_state->setValueForElement($element, $value);
     if ($value !== '' && !UrlHelper::isValid($value, TRUE)) {
         $form_state->setError($element, t('The URL %url is not valid.', array('%url' => $value)));
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:13,代码来源:Url.php

示例6: validateValue

 /**
  * {@inheritdoc}
  */
 public static function validateValue(array &$element, FormStateInterface $form_state, array $form)
 {
     if (!empty($element['#value'])) {
         if (!UrlHelper::isValid($element['#value'], TRUE)) {
             $form_state->setError($element, t('The entered Tumblr URI is not valid.'));
         }
     }
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:11,代码来源:Tumblr.php

示例7: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (strlen($form_state->getValue('title')) < 3) {
         $form_state->setErrorByName('title', $this->t('Your name is too short.'));
     }
     if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
         $form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
     }
 }
开发者ID:krabhay,项目名称:Learning-Drupal-8,代码行数:9,代码来源:ContributeForm.php

示例8: render

 /**
  * Response for the xmlsitemap_engines_test.ping route.
  *
  * @throws NotFoundHttpException
  *   Throw a NotFoundHttpException if query url is not valid.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   A response with 200 code if the url query is valid.
  */
 public function render()
 {
     $query = \Drupal::request()->query->get('sitemap');
     if (empty($query) || !UrlHelper::isValid($query)) {
         watchdog('xmlsitemap', 'No valid sitemap parameter provided.', array(), WATCHDOG_WARNING);
         // @todo Remove this? Causes an extra watchdog error to be handled.
         throw new NotFoundHttpException();
     } else {
         watchdog('xmlsitemap', 'Recieved ping for @sitemap.', array('@sitemap' => $query));
     }
     return new Response('', 200);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:21,代码来源:XmlSitemapEnginesTestController.php

示例9: validateForm

 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $routing_path = $form_state->getValue('routing_path');
     if ($routing_path) {
         $form_state->setValueForElement($form['routing']['routing_path'], $routing_path);
     } else {
         $form_state->setValueForElement($form['routing']['routing_path'], '/headless');
     }
     if ($routing_path[0] == '/') {
         $form_state->setErrorByName('routing_path', $this->t("The path '%path' cannot start with a slash.", array('%path' => $routing_path)));
     }
     if (!UrlHelper::isValid($routing_path)) {
         $form_state->setErrorByName('routing_path', $this->t("The path '%path' is invalid or you do not have access to it.", array('%path' => $routing_path)));
     }
 }
开发者ID:nuxy,项目名称:headless,代码行数:18,代码来源:HeadlessConfigForm.php

示例10: testInvalidRelative

 /**
  * Tests invalid relative URLs.
  *
  * @dataProvider providerTestInvalidRelativeData
  * @covers ::isValid
  *
  * @param string $url
  *   The url to test.
  * @param string $prefix
  *   The prefix to test.
  */
 public function testInvalidRelative($url, $prefix)
 {
     $test_url = $prefix . $url;
     $valid_url = UrlHelper::isValid($test_url);
     $this->assertFalse($valid_url, SafeMarkup::format('@url is NOT a valid URL.', array('@url' => $test_url)));
 }
开发者ID:brstde,项目名称:gap1,代码行数:17,代码来源:UrlHelperTest.php

示例11: testDrupalParseUrl

 /**
  * Tests UrlHelper::parse().
  */
 function testDrupalParseUrl()
 {
     // Relative, absolute, and external URLs, without/with explicit script path,
     // without/with Drupal path.
     foreach (array('', '/', 'http://drupal.org/') as $absolute) {
         foreach (array('', 'index.php/') as $script) {
             foreach (array('', 'foo/bar') as $path) {
                 $url = $absolute . $script . $path . '?foo=bar&bar=baz&baz#foo';
                 $expected = array('path' => $absolute . $script . $path, 'query' => array('foo' => 'bar', 'bar' => 'baz', 'baz' => ''), 'fragment' => 'foo');
                 $this->assertEqual(UrlHelper::parse($url), $expected, 'URL parsed correctly.');
             }
         }
     }
     // Relative URL that is known to confuse parse_url().
     $url = 'foo/bar:1';
     $result = array('path' => 'foo/bar:1', 'query' => array(), 'fragment' => '');
     $this->assertEqual(UrlHelper::parse($url), $result, 'Relative URL parsed correctly.');
     // Test that drupal can recognize an absolute URL. Used to prevent attack vectors.
     $url = 'http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo';
     $this->assertTrue(UrlHelper::isExternal($url), 'Correctly identified an external URL.');
     // Test that UrlHelper::parse() does not allow spoofing a URL to force a malicious redirect.
     $parts = UrlHelper::parse('forged:http://cwe.mitre.org/data/definitions/601.html');
     $this->assertFalse(UrlHelper::isValid($parts['path'], TRUE), '\\Drupal\\Component\\Utility\\UrlHelper::isValid() correctly parsed a forged URL.');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:27,代码来源:UrlTest.php

示例12: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $validators = array('file_validate_extensions' => array('opml xml'));
     if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
         $data = file_get_contents($file->getFileUri());
     } else {
         // @todo Move this to a fetcher implementation.
         try {
             $response = $this->httpClient->get($form_state->getValue('remote'));
             $data = (string) $response->getBody();
         } catch (RequestException $e) {
             $this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()));
             drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
             return;
         }
     }
     $feeds = $this->parseOpml($data);
     if (empty($feeds)) {
         drupal_set_message($this->t('No new feed has been added.'));
         return;
     }
     // @todo Move this functionality to a processor.
     foreach ($feeds as $feed) {
         // Ensure URL is valid.
         if (!UrlHelper::isValid($feed['url'], TRUE)) {
             drupal_set_message($this->t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
             continue;
         }
         // Check for duplicate titles or URLs.
         $query = $this->feedStorage->getQuery();
         $condition = $query->orConditionGroup()->condition('title', $feed['title'])->condition('url', $feed['url']);
         $ids = $query->condition($condition)->execute();
         $result = $this->feedStorage->loadMultiple($ids);
         foreach ($result as $old) {
             if (strcasecmp($old->label(), $feed['title']) == 0) {
                 drupal_set_message($this->t('A feed named %title already exists.', array('%title' => $old->label())), 'warning');
                 continue 2;
             }
             if (strcasecmp($old->getUrl(), $feed['url']) == 0) {
                 drupal_set_message($this->t('A feed with the URL %url already exists.', array('%url' => $old->getUrl())), 'warning');
                 continue 2;
             }
         }
         $new_feed = $this->feedStorage->create(array('title' => $feed['title'], 'url' => $feed['url'], 'refresh' => $form_state->getValue('refresh')));
         $new_feed->save();
     }
     $form_state->setRedirect('aggregator.admin_overview');
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:51,代码来源:OpmlFeedAdd.php

示例13: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Check that the chunk size will not create more than 1000 chunks.
     $chunk_size = $form_state->getValue('chunk_size');
     if ($chunk_size != 'auto' && $chunk_size != 50000 && xmlsitemap_get_link_count() / $chunk_size > 1000) {
         $form_state->setErrorByName('chunk_size', t('The sitemap page link count of @size will create more than 1,000 sitemap pages. Please increase the link count.', array('@size' => $chunk_size)));
     }
     $base_url = $form_state->getValue('xmlsitemap_base_url');
     $base_url = rtrim($base_url, '/');
     $form_state->setValue('xmlsitemap_base_url', $base_url);
     if ($base_url != '' && !UrlHelper::isValid($base_url, TRUE)) {
         $form_state->setErrorByName('xmlsitemap_base_url', t('Invalid base URL.'));
     }
     parent::validateForm($form, $form_state);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:18,代码来源:XmlSitemapSettingsForm.php

示例14: getUrl

 /**
  * Helper for getUrlIfValid() and getUrlIfValidWithoutAccessCheck().
  */
 protected function getUrl($path, $access_check)
 {
     $path = ltrim($path, '/');
     $parsed_url = UrlHelper::parse($path);
     $options = [];
     if (!empty($parsed_url['query'])) {
         $options['query'] = $parsed_url['query'];
     }
     if (!empty($parsed_url['fragment'])) {
         $options['fragment'] = $parsed_url['fragment'];
     }
     if ($parsed_url['path'] == '<front>') {
         return new Url('<front>', [], $options);
     } elseif ($parsed_url['path'] == '<none>') {
         return new Url('<none>', [], $options);
     } elseif (UrlHelper::isExternal($path) && UrlHelper::isValid($path)) {
         if (empty($parsed_url['path'])) {
             return FALSE;
         }
         return Url::fromUri($path);
     }
     $request = Request::create('/' . $path);
     $attributes = $this->getPathAttributes($path, $request, $access_check);
     if (!$attributes) {
         return FALSE;
     }
     $route_name = $attributes[RouteObjectInterface::ROUTE_NAME];
     $route_parameters = $attributes['_raw_variables']->all();
     return new Url($route_name, $route_parameters, $options + ['query' => $request->query->all()]);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:33,代码来源:PathValidator.php

示例15: testInvalidRelative

 /**
  * Tests invalid relative URLs.
  *
  * @dataProvider providerTestInvalidRelativeData
  * @covers ::isValid
  *
  * @param string $url
  *   The url to test.
  * @param string $prefix
  *   The prefix to test.
  */
 public function testInvalidRelative($url, $prefix)
 {
     $test_url = $prefix . $url;
     $valid_url = UrlHelper::isValid($test_url);
     $this->assertFalse($valid_url, $test_url . ' is NOT a valid URL.');
 }
开发者ID:scratch,项目名称:gai,代码行数:17,代码来源:UrlHelperTest.php


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