本文整理汇总了PHP中Drupal\Core\Url::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::setOption方法的具体用法?PHP Url::setOption怎么用?PHP Url::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Url
的用法示例。
在下文中一共展示了Url::setOption方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteSubmit
/**
* Submits the delete form.
*/
public function deleteSubmit(array &$form, FormStateInterface $form_state)
{
$url = new Url('path.delete', array('pid' => $form_state->getValue('pid')));
if ($this->getRequest()->query->has('destination')) {
$url->setOption('query', $this->getDestinationArray());
$this->getRequest()->query->remove('destination');
}
$form_state->setRedirectUrl($url);
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL)
{
$form = parent::buildForm($form, $form_state, $pid);
$form['#title'] = $this->path['alias'];
$form['pid'] = array('#type' => 'hidden', '#value' => $this->path['pid']);
$url = new Url('path.delete', array('pid' => $this->path['pid']));
if ($this->getRequest()->query->has('destination')) {
$url->setOption('query', $this->getDestinationArray());
}
$form['actions']['delete'] = array('#type' => 'link', '#title' => $this->t('Delete'), '#url' => $url, '#attributes' => array('class' => array('button', 'button--danger')));
return $form;
}
示例3: actions
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state)
{
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->t('Save settings');
if (!$this->entity->isNew()) {
$target_entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
$route_parameters = ['field_config' => $this->entity->id()] + FieldUI::getRouteBundleParameter($target_entity_type, $this->entity->bundle);
$url = new Url('entity.field_config.' . $target_entity_type->id() . '_field_delete_form', $route_parameters);
if ($this->getRequest()->query->has('destination')) {
$query = $url->getOption('query');
$query['destination'] = $this->getRequest()->query->get('destination');
$url->setOption('query', $query);
}
$actions['delete'] = array('#type' => 'link', '#title' => $this->t('Delete'), '#url' => $url, '#access' => $this->entity->access('delete'), '#attributes' => array('class' => array('button', 'button--danger')));
}
return $actions;
}
示例4: setResponse
/**
* Prior to set the response it check if we can redirect.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event object.
* @param \Drupal\Core\Url $url
* The Url where we want to redirect.
*/
protected function setResponse(GetResponseEvent $event, Url $url)
{
$request = $event->getRequest();
$this->context->fromRequest($request);
parse_str($request->getQueryString(), $query);
$url->setOption('query', $query);
$url->setAbsolute(TRUE);
// We can only check access for routed URLs.
if (!$url->isRouted() || $this->redirectChecker->canRedirect($url->getRouteName(), $request)) {
// Add the 'rendered' cache tag, so that we can invalidate all responses
// when settings are changed.
$headers = ['X-Drupal-Cache-Tags' => 'rendered'];
$event->setResponse(new RedirectResponse($url->toString(), 301, $headers));
}
}
示例5: setResponse
/**
* Prior to set the response it check if we can redirect.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event object.
* @param \Drupal\Core\Url $url
* The Url where we want to redirect.
*/
protected function setResponse(GetResponseEvent $event, Url $url)
{
$request = $event->getRequest();
$this->context->fromRequest($request);
parse_str($request->getQueryString(), $query);
$url->setOption('query', $query);
$url->setAbsolute(TRUE);
// We can only check access for routed URLs.
if (!$url->isRouted() || $this->checker->canRedirect($request, $url->getRouteName())) {
// Add the 'rendered' cache tag, so that we can invalidate all responses
// when settings are changed.
$response = new TrustedRedirectResponse($url->toString(), 301);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray([])->addCacheTags(['rendered']));
$event->setResponse($response);
}
}
示例6: viewTopic
//.........这里部分代码省略.........
'!module' => $this->l($this->t('Markdown filter'),
Url::fromUri('https://www.drupal.org/project/markdown'),
['attributes' => ['title' => $this->t('Link to project.')]])
]) . '</p>';
}
$readme .=
'<div class="advanced-help-topic"><pre class="readme">' . SafeMarkup::checkPlain($build['#markup']) . '</pre></div>';
$build['#markup'] = $readme;
}
return $build['#markup'];
}
// Change 'topic:' to the URL for another help topic.
preg_match('/&topic:([^"]+)&/', $build['#markup'], $matches);
if (isset($matches[1]) && preg_match('/[\w\-]\/[\w\-]+/', $matches[1])) {
list($umodule, $utopic) = explode('/', $matches[1]);
$path = new Url('advanced_help.help', ['module' => $umodule, 'topic' => $utopic]);
$build['#markup'] = preg_replace('/&topic:([^"]+)&/', $path->toString(), $build['#markup']);
}
global $base_path;
// Change 'path:' to the URL to the base help directory.
$build['#markup'] = str_replace('&path&', $base_path . $info['path'] . '/', $build['#markup']);
// Change 'trans_path:' to the URL to the actual help directory.
$build['#markup'] = str_replace('&trans_path&', $base_path . $file_info['path'] . '/', $build['#markup']);
// Change 'base_url:' to the URL to the site.
$build['#markup'] = preg_replace('/&base_url&([^"]+)"/', $base_path . '$1' . '"', $build['#markup']);
// Run the line break filter if requested.
if (!empty($info['line break'])) {
// Remove the header since it adds an extra <br /> to the filter.
$build['#markup'] = preg_replace('/^<!--[^\n]*-->\n/', '', $build['#markup']);
$build['#markup'] = _filter_autop($build['#markup']);
}
if (!empty($info['navigation']) && !$is_modal) {
$topics = $this->advanced_help->getTopics();
$topics = $this->getTopicHierarchy($topics);
if (!empty($topics[$module][$topic]['children'])) {
$items = $this->getTree($topics, $topics[$module][$topic]['children']);
$links = [
'#theme' => 'item_list',
'#items' => $items
];
$build['#markup'] .= \Drupal::service('renderer')->render($links, FALSE);
}
list($parent_module, $parent_topic) = $topics[$module][$topic]['_parent'];
if ($parent_topic) {
$parent = $topics[$module][$topic]['_parent'];
$up = new Url('advanced_help.help', ['module' => $parent[0], 'topic' => $parent[1]]);
}
else {
$up = new Url('advanced_help.module_index', ['module' => $module]);
}
$siblings = $topics[$parent_module][$parent_topic]['children'];
uasort($siblings, [$this, 'helpUasort']);
$prev = $next = NULL;
$found = FALSE;
foreach ($siblings as $sibling) {
list($sibling_module, $sibling_topic) = $sibling;
if ($found) {
$next = $sibling;
break;
}
if ($sibling_module == $module && $sibling_topic == $topic) {
$found = TRUE;
continue;
}
$prev = $sibling;
}
if ($prev || $up || $next) {
$navigation = '<div class="help-navigation clear-block">';
if ($prev) {
$navigation .= $this->l('«« ' . $topics[$prev[0]][$prev[1]]['title'], new Url('advanced_help.help', ['module' => $prev[0], 'topic' => $prev[1]], ['attributes' => ['class' => 'help-left']]));
}
if ($up) {
$navigation .= $this->l($this->t('Up'), $up->setOption('attributes', ['class' => ($prev) ? 'help-up' : 'help-up-noleft']));
}
if ($next) {
$navigation .= $this->l($topics[$next[0]][$next[1]]['title'] . ' »»', new Url('advanced_help.help', ['module' => $next[0], 'topic' => $next[1]], ['attributes' => ['class' => 'help-right']]));
}
$navigation .= '</div>';
$build['#markup'] .= $navigation;
}
}
$build['#markup'] = '<div class="advanced-help-topic">' . $build['#markup'] . '</div>';
// drupal_alter('advanced_help_topic', $output, $popup);
return $build;
}
}