本文整理汇总了PHP中Drupal\Core\Url::fromUserInput方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::fromUserInput方法的具体用法?PHP Url::fromUserInput怎么用?PHP Url::fromUserInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Url
的用法示例。
在下文中一共展示了Url::fromUserInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: transform
/**
* {@inheritdoc}
*
* Find the parent link GUID.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
$parent_id = array_shift($value);
if (!$parent_id) {
// Top level item.
return '';
}
try {
$already_migrated_id = $this->migrationPlugin->transform($parent_id, $migrate_executable, $row, $destination_property);
if ($already_migrated_id && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
return $link->getPluginId();
}
} catch (MigrateSkipRowException $e) {
}
if (isset($value[1])) {
list($menu_name, $parent_link_path) = $value;
$url = Url::fromUserInput("/{$parent_link_path}");
if ($url->isRouted()) {
$links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name);
if (count($links) == 1) {
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = reset($links);
return $link->getPluginId();
}
}
}
throw new MigrateSkipRowException();
}
示例3: get_custom_links
public function get_custom_links($custom_paths, $language)
{
$links = array();
foreach ($custom_paths as $custom_path) {
if ($custom_path['index']) {
$links[] = SitemapGenerator::add_xml_link_markup(Url::fromUserInput($custom_path['path'], array('language' => $language, 'absolute' => TRUE))->toString(), $custom_path['priority']);
}
}
return $links;
}
示例4: render
/**
* {@inheritdoc}
*/
public function render(ResultRow $values)
{
$value = $this->getValue($values);
if (!empty($this->options['display_as_link'])) {
// @todo Views should expect and store a leading /. See:
// https://www.drupal.org/node/2423913
return \Drupal::l($this->sanitizeValue($value), CoreUrl::fromUserInput('/' . $value));
} else {
return $this->sanitizeValue($value, 'url');
}
}
示例5: getPath
/**
* Gets the displayable path of a page entity.
*
* @param \Drupal\page_manager\PageInterface $entity
* The page entity.
*
* @return array|string
* The value of the path.
*/
protected function getPath(PageInterface $entity)
{
// If the page is enabled and not dynamic, show the path as a link,
// otherwise as plain text.
$path = $entity->getPath();
if ($entity->status() && strpos($path, '%') === FALSE) {
return ['data' => ['#type' => 'link', '#url' => Url::fromUserInput(rtrim($path, '/')), '#title' => $path]];
} else {
return $path;
}
}
示例6: testLinkXSS
/**
* Confirms that invalid URLs are filtered in link generating functions.
*/
function testLinkXSS()
{
// Test \Drupal::l().
$text = $this->randomMachineName();
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
$encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E";
$link = \Drupal::l($text, Url::fromUserInput('/' . $path));
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, format_string('XSS attack @path was filtered by \\Drupal\\Core\\Utility\\LinkGeneratorInterface::generate().', array('@path' => $path)));
// Test \Drupal\Core\Url.
$link = Url::fromUri('base:' . $path)->toString();
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, format_string('XSS attack @path was filtered by #theme', ['@path' => $path]));
}
示例7: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (!$form_state->isValueEmpty('redirection')) {
if (!$form_state->isValueEmpty('destination')) {
// The destination is a random URL, so we can't use routed URLs.
// @todo Revist this in https://www.drupal.org/node/2418219.
$form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination')));
}
} else {
$form_state->disableRedirect();
}
}
示例8: testLinkXSS
/**
* Confirms that invalid URLs are filtered in link generating functions.
*/
function testLinkXSS()
{
// Test \Drupal::l().
$text = $this->randomMachineName();
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
$link = \Drupal::l($text, Url::fromUserInput('/' . $path));
$sanitized_path = check_url(Url::fromUri('base:' . $path)->toString());
$this->assertTrue(strpos($link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by _l().', array('@path' => $path)));
// Test \Drupal\Core\Url.
$link = Url::fromUri('base:' . $path)->toString();
$sanitized_path = check_url(Url::fromUri('base:' . $path)->toString());
$this->assertTrue(strpos($link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by #theme', ['@path' => $path]));
}
示例9: buildCancelLink
/**
* Builds the cancel link for a confirmation form.
*
* @param \Drupal\Core\Form\ConfirmFormInterface $form
* The confirmation form.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return array
* The link render array for the cancel form.
*/
public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
{
// Prepare cancel link.
$query = $request->query;
// If a destination is specified, that serves as the cancel link.
if ($query->has('destination')) {
$options = UrlHelper::parse($query->get('destination'));
// @todo Revisit this in https://www.drupal.org/node/2418219.
$url = Url::fromUserInput('/' . $options['path'], $options);
} else {
$url = $form->getCancelUrl();
}
return ['#type' => 'link', '#title' => $form->getCancelText(), '#attributes' => ['class' => ['button']], '#url' => $url];
}
示例10: getUrlObject
/**
* {@inheritdoc}
*/
public function getUrlObject($title_attribute = TRUE)
{
if ($this->getEntity()->getUrlObject()) {
$options = $this->getOptions();
if ($title_attribute && ($description = $this->getDescription())) {
$options['attributes']['title'] = $description;
}
if (empty($this->pluginDefinition['url'])) {
return new Url($this->pluginDefinition['route_name'], $this->pluginDefinition['route_parameters'], $options);
} else {
return Url::fromUri($this->pluginDefinition['url'], $options);
}
} else {
// Because the edit link has custom access control we need to return a link the anon user has access to.
return Url::fromUserInput('/');
}
}
示例11: preprocessVariables
/**
* {@inheritdoc}
*/
public function preprocessVariables(Variables $variables, $hook, array $info)
{
if (!empty($variables['description'])) {
$variables['description'] = FieldFilteredMarkup::create($variables['description']);
}
$descriptions = [];
$cardinality = $variables['cardinality'];
if (isset($cardinality)) {
if ($cardinality == -1) {
$descriptions[] = t('Unlimited number of files can be uploaded to this field.');
} else {
$descriptions[] = \Drupal::translation()->formatPlural($cardinality, 'One file only.', 'Maximum @count files.');
}
}
$upload_validators = $variables['upload_validators'];
if (isset($upload_validators['file_validate_size'])) {
$descriptions[] = t('@size limit.', ['@size' => format_size($upload_validators['file_validate_size'][0])]);
}
if (isset($upload_validators['file_validate_extensions'])) {
$extensions = new FormattableMarkup('<code>@extensions</code>', ['@extensions' => implode(', ', explode(' ', $upload_validators['file_validate_extensions'][0]))]);
$descriptions[] = t('Allowed types: @extensions.', ['@extensions' => $extensions]);
}
if (isset($upload_validators['file_validate_image_resolution'])) {
$max = $upload_validators['file_validate_image_resolution'][0];
$min = $upload_validators['file_validate_image_resolution'][1];
if ($min && $max && $min == $max) {
$descriptions[] = t('Images must be exactly <strong>@size</strong> pixels.', ['@size' => $max]);
} elseif ($min && $max) {
$descriptions[] = t('Images must be larger than <strong>@min</strong> pixels. Images larger than <strong>@max</strong> pixels will be resized.', ['@min' => $min, '@max' => $max]);
} elseif ($min) {
$descriptions[] = t('Images must be larger than <strong>@min</strong> pixels.', ['@min' => $min]);
} elseif ($max) {
$descriptions[] = t('Images larger than <strong>@max</strong> pixels will be resized.', ['@max' => $max]);
}
}
$variables['descriptions'] = $descriptions;
if ($descriptions) {
$build = array();
$id = Html::getUniqueId('upload-instructions');
$build['toggle'] = ['#type' => 'link', '#title' => t('Upload requirements'), '#url' => Url::fromUserInput("#{$id}"), '#icon' => Bootstrap::glyphicon('question-sign'), '#attributes' => ['class' => ['icon-before'], 'data-toggle' => 'popover', 'data-html' => 'true', 'data-placement' => 'bottom', 'data-title' => t('Upload requirements')]];
$build['requirements'] = ['#type' => 'container', '#theme_wrappers' => ['container__file_upload_help'], '#attributes' => ['id' => $id, 'class' => ['hidden', 'help-block'], 'aria-hidden' => 'true']];
$build['requirements']['descriptions'] = ['#theme' => 'item_list__file_upload_help', '#items' => $descriptions];
$variables['popover'] = $build;
}
}
示例12: getNextDestination
/**
* Returns the next redirect path in a multipage sequence.
*
* @param array $destinations
* An array of destinations to redirect to.
*
* @return \Drupal\Core\Url
* The next destination to redirect to.
*/
public static function getNextDestination(array $destinations)
{
$next_destination = array_shift($destinations);
if (is_array($next_destination)) {
$next_destination['options']['query']['destinations'] = $destinations;
$next_destination += array('route_parameters' => array());
$next_destination = Url::fromRoute($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
} else {
$options = UrlHelper::parse($next_destination);
if ($destinations) {
$options['query']['destinations'] = $destinations;
}
// Redirect to any given path within the same domain.
// @todo Revisit this in https://www.drupal.org/node/2418219.
$next_destination = Url::fromUserInput('/' . $options['path']);
}
return $next_destination;
}
示例13: index
/**
* Index.
* @param \Drupal\user\UserInterface $user
* @return array
* @throws \Exception
* @internal param string $uid
*/
public function index(UserInterface $user)
{
// See if the user already has an API key.
$q = $this->database->select('api_keys', 'a')->fields('a');
$q->condition('a.uid', $user->id());
$user_key_object = $q->execute()->fetchObject();
if (!$user_key_object) {
// The user does not have a key. Generate one for them.
$user_key = sha1(uniqid());
// Insert it to the database.
$this->database->insert('api_keys')->fields(array('uid' => $user->id(), 'user_key' => $user_key))->execute();
} else {
$user_key = $user_key_object->user_key;
}
// Generate the URL which we should use in the CURL explaination.
// @todo
return ['#theme' => 'api-keys-user-keys', '#api_key' => $user_key, '#post_url' => 'example.com/entity/log', '#base_url' => Url::fromUserInput('/')->setOption('absolute', TRUE), '#markup' => $this->t('URL : !url and key: !key', ['!url' => $post_url, '!key' => $user_key])];
}
示例14: adminOverview
/**
* Displays the path administration overview page.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @return array
* A render array as expected by drupal_render().
*/
public function adminOverview(Request $request)
{
$keys = $request->query->get('search');
// Add the filter form above the overview table.
$build['path_admin_filter_form'] = $this->formBuilder()->getForm('Drupal\\path\\Form\\PathFilterForm', $keys);
// Enable language column if language.module is enabled or if we have any
// alias with a language.
$multilanguage = $this->moduleHandler()->moduleExists('language') || $this->aliasStorage->languageAliasExists();
$header = array();
$header[] = array('data' => $this->t('Alias'), 'field' => 'alias', 'sort' => 'asc');
$header[] = array('data' => $this->t('System'), 'field' => 'source');
if ($multilanguage) {
$header[] = array('data' => $this->t('Language'), 'field' => 'langcode');
}
$header[] = $this->t('Operations');
$rows = array();
$destination = $this->getDestinationArray();
foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
$row = array();
// @todo Should Path module store leading slashes? See
// https://www.drupal.org/node/2430593.
$row['data']['alias'] = $this->l(Unicode::truncate($data->alias, 50, FALSE, TRUE), Url::fromUserInput($data->source, array('attributes' => array('title' => $data->alias))));
$row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUserInput($data->source, array('alias' => TRUE, 'attributes' => array('title' => $data->source))));
if ($multilanguage) {
$row['data']['language_name'] = $this->languageManager()->getLanguageName($data->langcode);
}
$operations = array();
$operations['edit'] = array('title' => $this->t('Edit'), 'url' => Url::fromRoute('path.admin_edit', ['pid' => $data->pid], ['query' => $destination]));
$operations['delete'] = array('title' => $this->t('Delete'), 'url' => Url::fromRoute('path.delete', ['pid' => $data->pid], ['query' => $destination]));
$row['data']['operations'] = array('data' => array('#type' => 'operations', '#links' => $operations));
// If the system path maps to a different URL alias, highlight this table
// row to let the user know of old aliases.
if ($data->alias != $this->aliasManager->getAliasByPath($data->source, $data->langcode)) {
$row['class'] = array('warning');
}
$rows[] = $row;
}
$build['path_table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => $this->t('No URL aliases available. <a href=":link">Add URL alias</a>.', array(':link' => $this->url('path.admin_add'))));
$build['path_pager'] = array('#type' => 'pager');
return $build;
}
示例15: submitForm
public function submitForm(array &$form, FormStateInterface $form_state)
{
try {
if (!empty($form_state->getBuildInfo()['args'][0]) && !empty($form_state->getBuildInfo()['args'][1])) {
$smfSessionId = $form_state->getBuildInfo()['args'][0];
/**
* @var \Drupal\smfbridge\Smf\Member $smfMember
*/
$smfMember = \Drupal::service('smfbridge.smfmember');
if ($smfMember->setAdminTime($smfSessionId)) {
$form_state->setRedirectUrl(Url::fromUserInput($form_state->getBuildInfo()['args'][1]));
} else {
throw new \Exception($this->t('Failed to get access to SMF admin area.'));
}
} else {
throw new \Exception($this->t('Failed to get access to SMF admin area.'));
}
} catch (\Exception $e) {
drupal_set_message($e->getMessage(), 'error');
}
}