本文整理汇总了PHP中URL::fromRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP URL::fromRoute方法的具体用法?PHP URL::fromRoute怎么用?PHP URL::fromRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类URL
的用法示例。
在下文中一共展示了URL::fromRoute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDrupalRenderFormElements
/**
* Tests rendering form elements without passing through
* \Drupal::formBuilder()->doBuildForm().
*/
function testDrupalRenderFormElements()
{
// Define a series of form elements.
$element = array('#type' => 'button', '#value' => $this->randomMachineName());
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'submit'));
$element = array('#type' => 'textfield', '#title' => $this->randomMachineName(), '#value' => $this->randomMachineName());
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'text'));
$element = array('#type' => 'password', '#title' => $this->randomMachineName());
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'password'));
$element = array('#type' => 'textarea', '#title' => $this->randomMachineName(), '#value' => $this->randomMachineName());
$this->assertRenderedElement($element, '//textarea');
$element = array('#type' => 'radio', '#title' => $this->randomMachineName(), '#value' => FALSE);
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'radio'));
$element = array('#type' => 'checkbox', '#title' => $this->randomMachineName());
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'checkbox'));
$element = array('#type' => 'select', '#title' => $this->randomMachineName(), '#options' => array(0 => $this->randomMachineName(), 1 => $this->randomMachineName()));
$this->assertRenderedElement($element, '//select');
$element = array('#type' => 'file', '#title' => $this->randomMachineName());
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'file'));
$element = array('#type' => 'item', '#title' => $this->randomMachineName(), '#markup' => $this->randomMachineName());
$this->assertRenderedElement($element, '//div[contains(@class, :class) and contains(., :markup)]/label[contains(., :label)]', array(':class' => 'js-form-type-item', ':markup' => $element['#markup'], ':label' => $element['#title']));
$element = array('#type' => 'hidden', '#title' => $this->randomMachineName(), '#value' => $this->randomMachineName());
$this->assertRenderedElement($element, '//input[@type=:type]', array(':type' => 'hidden'));
$element = array('#type' => 'link', '#title' => $this->randomMachineName(), '#url' => Url::fromRoute('common_test.destination'), '#options' => array('absolute' => TRUE));
$this->assertRenderedElement($element, '//a[@href=:href and contains(., :title)]', array(':href' => URL::fromRoute('common_test.destination')->setAbsolute()->toString(), ':title' => $element['#title']));
$element = array('#type' => 'details', '#open' => TRUE, '#title' => $this->randomMachineName());
$this->assertRenderedElement($element, '//details/summary[contains(., :title)]', array(':title' => $element['#title']));
$element = array('#type' => 'details', '#open' => TRUE, '#title' => $this->randomMachineName());
$this->assertRenderedElement($element, '//details');
$element['item'] = array('#type' => 'item', '#title' => $this->randomMachineName(), '#markup' => $this->randomMachineName());
$this->assertRenderedElement($element, '//details/div/div[contains(@class, :class) and contains(., :markup)]', array(':class' => 'js-form-type-item', ':markup' => $element['item']['#markup']));
}
示例2: getWorkspaceSwitchLinks
/**
* {@inheritdoc}
*/
public function getWorkspaceSwitchLinks(Request $request, Url $url)
{
$links = array();
$active_workspace_id = $this->workspaceManager->getActiveWorkspace($request)->id();
$query = array();
parse_str($request->getQueryString(), $query);
// If we have an error on the requested page, set links URL to be <front>.
if (!empty($query['_exception_statuscode'])) {
if (isset($query['workspace'])) {
$query = array('workspace' => $query['workspace']);
}
$url = URL::fromRoute('<front>');
}
$workspaces = $this->workspaceManager->loadMultiple();
ksort($workspaces);
foreach ($workspaces as $workspace) {
// @todo {@link https://www.drupal.org/node/2600382 Access check.}
$workspace_id = $workspace->id();
$links[$workspace_id] = array('url' => $url, 'title' => $workspace->label(), 'query' => $query);
$links[$workspace_id]['query']['workspace'] = $workspace_id;
if ($workspace_id == $active_workspace_id) {
$links[$workspace_id]['attributes']['class'][] = 'session-active';
}
}
return $links;
}
示例3: getAction
public function getAction()
{
$controller = $this->getAttribute('controller', NULL);
$action = $this->getAttribute('action', NULL);
if (!empty($controller) && !empty($action)) {
return \URL::fromRoute($controller, $action);
}
return NULL;
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
parent::buildForm($form, $form_state);
$roles = tmgmt_local_translator_roles();
if (empty($roles)) {
drupal_set_message(t('No user role has the "provide translation services" permission. <a href="@url">Configure permissions</a> for the Drupal user module.', array('@url' => URL::fromRoute('user.admin_permissions'))), 'warning');
}
$form['tuid'] = array('#title' => t('Assign to'), '#type' => 'select', '#empty_option' => t('- Select user -'), '#options' => tmgmt_local_get_assignees_for_tasks([$this->getEntity()->id()]), '#required' => TRUE);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Assign tasks'));
return $form;
}
示例5: redirect
public function redirect($controller = NULL, $action = NULL, $item = NULL, $module = NULL)
{
if ($controller === NULL) {
$url = \Biome\Biome::getService('request')->headers->get('referer');
} else {
$url = \URL::fromRoute($controller, $action, $item, $module);
}
Logger::info('Redirect to ' . $url);
$this->headers->set('Location', $url);
$this->setStatusCode(302);
return $this;
}
示例6: getAction
public function getAction()
{
$action = $this->getAttribute('action');
$actions = $this->fetchVariables($action);
if (empty($actions)) {
return $this->getURL();
}
$var = reset($actions);
$raw = explode('.', $var);
$controller = $raw[0];
$action = $raw[1];
return \URL::fromRoute($controller, $action);
}
示例7: getURL
public function getURL()
{
$controller = $this->getAttribute('controller', NULL);
$action = $this->getAttribute('action', NULL);
$item = $this->getAttribute('item', NULL);
$module = $this->getAttribute('module', NULL);
$page = $this->getAttribute('page', NULL);
if ($item) {
$item = $this->fetchValue($item);
}
if ($page) {
$page = $this->fetchValue($page);
}
return \URL::fromRoute($controller, $action, $item, $module, $page);
}
示例8: testConsiderFieldSequences
/**
* Test consider field sequences.
*/
public function testConsiderFieldSequences()
{
$this->createNodeType('article1', 'Article 1', TRUE, FALSE);
for ($i = 0; $i <= 5; $i++) {
// Create a field.
$field_storage = FieldStorageConfig::create(array('field_name' => 'field_' . $i, 'entity_type' => 'node', 'type' => 'text', 'cardinality' => mt_rand(1, 5), 'translatable' => TRUE));
$field_storage->save();
// Create an instance of the previously created field.
$field = FieldConfig::create(array('field_name' => 'field_' . $i, 'entity_type' => 'node', 'bundle' => 'article1', 'label' => 'Field' . $i, 'description' => $this->randomString(30), 'widget' => array('type' => 'text', 'label' => $this->randomString(10))));
$field->save();
$this->field_names['node']['article1'][] = 'field_' . $i;
}
$node = $this->createTranslatableNode('article1', 'en');
entity_get_form_display('node', 'article1', 'default')->setComponent('body', array('type' => 'text_textarea_with_summary', 'weight' => 0))->setComponent('title', array('type' => 'string_textfield', 'weight' => 1))->setComponent('field_1', array('type' => 'string_textfield', 'weight' => 2))->setComponent('field_2', array('type' => 'string_textfield', 'weight' => 5))->setComponent('field_0', array('type' => 'string_textfield', 'weight' => 6))->setComponent('field_4', array('type' => 'string_textfield', 'weight' => 7))->save();
$job = $this->createJob('en', 'de');
$job->translator = $this->default_translator->id();
$job->addItem('content', $node->getEntityTypeId(), $node->id());
$job->save();
$job->requestTranslation();
// Visit job item review page.
$this->drupalGet(URL::fromRoute('entity.tmgmt_job_item.canonical', ['tmgmt_job_item' => $node->id()]));
$review_elements = $this->xpath('//*[@id="edit-review"]/div');
$ids = [];
foreach ($review_elements as $review_element) {
$ids[] = (string) $review_element['id'];
}
// Check are fields showing on page in desired order. Field 3 and 5 have
// no weight set and are expected to be ordered alphabetically, at the end.
$this->assertEqual($ids[0], 'tmgmt-ui-element-body-wrapper');
$this->assertEqual($ids[1], 'tmgmt-ui-element-title-wrapper');
$this->assertEqual($ids[2], 'tmgmt-ui-element-field-1-wrapper');
$this->assertEqual($ids[3], 'tmgmt-ui-element-field-2-wrapper');
$this->assertEqual($ids[4], 'tmgmt-ui-element-field-0-wrapper');
$this->assertEqual($ids[5], 'tmgmt-ui-element-field-4-wrapper');
$this->assertEqual($ids[6], 'tmgmt-ui-element-field-3-wrapper');
$this->assertEqual($ids[7], 'tmgmt-ui-element-field-5-wrapper');
}
示例9: getSettingsLink
/**
* {@inheritdoc}
*/
public function getSettingsLink()
{
$url = URL::fromRoute('ckeditor_media_embed.ckeditor_media_embed_settings_form', array('destination' => \Drupal::service('path.current')->getPath()));
return Markup::create(\Drupal::l($this->t('CKEditor Media Embed plugin settings page'), $url));
}
示例10:
<nav class="navbar navbar-default navbar-fixed-top <?php
echo $this->getClasses();
?>
" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-ex1-collapse" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php
echo URL::fromRoute();
?>
"><?php
$logo = $this->getLogo();
if (!empty($logo)) {
echo '<img src="', URL::getAsset($logo), '" width="100%" height="100%"/>';
} else {
echo $view->getTitle();
}
?>
</a>
</div>
<?php
echo $this->getContent();
?>
</div>