/**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     if ($this->translation instanceof TranslationManagerWrapper) {
         /** \Drupal\webprofiler\StringTranslation\TranslationManagerWrapper $this->translation */
         $this->data['translations']['translated'] = $this->translation->getTranslated();
         $this->data['translations']['untranslated'] = $this->translation->getUntranslated();
     }
     $data['user_interface_translations_path'] = $this->urlGenerator->generateFromRoute('locale.translate_page');
 }
 /**
  * Tests the output process.
  */
 public function testProcessOutbound()
 {
     $expected_cacheability = (new BubbleableMetadata())->addCacheContexts(['route'])->setCacheMaxAge(Cache::PERMANENT);
     $request_stack = \Drupal::requestStack();
     /** @var \Symfony\Component\Routing\RequestContext $request_context */
     $request_context = \Drupal::service('router.request_context');
     // Test request with subdir on homepage.
     $server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/subdir/', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/subdir/');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request with subdir on other page.
     $server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/subdir/node/add');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request without subdir on the homepage.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request without subdir on other page.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/node/add', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/node/add');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request without a found route. This happens for example on an
     // not found exception page.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/invalid-path', 'GET', [], [], [], $server);
     $request_stack->push($request);
     $request_context->fromRequest($request);
     // In case we have no routing, the current route should point to the front,
     // and the cacheability does not depend on the 'route' cache context, since
     // no route was involved at all: this is fallback behavior.
     $url = GeneratedUrl::createFromObject((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT))->setGeneratedUrl('/');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('ckeditor_media_embed.settings');
     $form['embed_provider'] = array('#type' => 'textfield', '#title' => $this->t('Provider URL'), '#default_value' => $config->get('embed_provider'), '#description' => $this->t('A template for the URL of the provider endpoint.
     This URL will be queried for each resource to be embedded. By default CKEditor uses the Iframely service.<br />
     <strong>Example</strong> <code>//example.com/api/oembed-proxy?resource-url={url}&callback={callback}</code><br />
     <strong>Default</strong> <code>//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}</code><br />
   '));
     if ($this->moduleHandler->moduleExists('help')) {
         $form['embed_provider']['#description'] .= $this->t('Check out the <a href=":help">help</a> page for more information.<br />', array(':help' => $this->urlGenerator->generateFromRoute('help.page', array('name' => 'ckeditor_media_embed'))));
     }
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function get()
 {
     if (!isset($this->destination)) {
         $query = $this->requestStack->getCurrentRequest()->query;
         if (UrlHelper::isExternal($query->get('destination'))) {
             $this->destination = '/';
         } elseif ($query->has('destination')) {
             $this->destination = $query->get('destination');
         } else {
             $this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()))]);
         }
     }
     return $this->destination;
 }
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $bundles = $this->mediaBundleStorage->loadMultiple();
     if (empty($bundles)) {
         $create_url = $this->urlGenerator->generateFromRoute('media.bundle_add');
         $this->setMessage($this->t('You do not have any media bundles that can be generated. <a href="@create-bundle">Go create a new media bundle</a>', ['@create-bundle' => $create_url]), 'error', FALSE);
         return [];
     }
     $options = [];
     foreach ($bundles as $bundle) {
         $options[$bundle->id()] = ['bundle' => ['#markup' => $bundle->label()]];
     }
     $form['media_bundles'] = ['#type' => 'tableselect', '#header' => ['bundle' => $this->t('Media bundle')], '#options' => $options];
     $form['kill'] = ['#type' => 'checkbox', '#title' => $this->t('<strong>Delete all media</strong> in these bundles before generating new media.'), '#default_value' => $this->getSetting('kill')];
     $form['num'] = ['#type' => 'number', '#title' => $this->t('How many media items would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0];
     $options = [1 => $this->t('Now')];
     foreach ([3600, 86400, 604800, 2592000, 31536000] as $interval) {
         $options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = ['#type' => 'select', '#title' => $this->t('How far back in time should the media be dated?'), '#description' => $this->t('Media creation dates will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800];
     $form['name_length'] = ['#type' => 'number', '#title' => $this->t('Maximum number of words in names'), '#default_value' => $this->getSetting('name_length'), '#required' => TRUE, '#min' => 1, '#max' => 255];
     $options = [];
     // We always need a language.
     $languages = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
     foreach ($languages as $langcode => $language) {
         $options[$langcode] = $language->getName();
     }
     $form['add_language'] = ['#type' => 'select', '#title' => $this->t('Set language on media'), '#multiple' => TRUE, '#description' => $this->t('Requires locale.module'), '#options' => $options, '#default_value' => [$this->languageManager->getDefaultLanguage()->getId()]];
     $form['#redirect'] = FALSE;
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function render() {
   $build = parent::render();
   $build['#empty'] = t('No eform types available. <a href="@link">Add EForm type</a>.', array(
     '@link' => $this->urlGenerator->generateFromRoute('eform.type_add'),
   ));
   return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function forbiddenMessage(EntityInterface $entity, $field_name)
 {
     if (!isset($this->authenticatedCanPostComments)) {
         // We only output a link if we are certain that users will get the
         // permission to post comments by logging in.
         $this->authenticatedCanPostComments = $this->entityManager->getStorage('user_role')->load(DRUPAL_AUTHENTICATED_RID)->hasPermission('post comments');
     }
     if ($this->authenticatedCanPostComments) {
         // We cannot use drupal_get_destination() because these links
         // sometimes appear on /node and taxonomy listing pages.
         if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) {
             $destination = array('destination' => 'comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name . '#comment-form');
         } else {
             $destination = array('destination' => $entity->getSystemPath() . '#comment-form');
         }
         if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
             // Users can register themselves.
             return $this->t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)), '@register' => $this->urlGenerator->generateFromRoute('user.register', array(), array('query' => $destination))));
         } else {
             // Only admins can add new users, no public registration.
             return $this->t('<a href="@login">Log in</a> to post comments', array('@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination))));
         }
     }
     return '';
 }
 /**
  * {@inheritdoc}
  */
 public function render() {
   $build = parent::render();
   $build['#empty'] = $this->t('There are currently no blocktabs. <a href=":url">Add a new one</a>.', array(
     ':url' => $this->urlGenerator->generateFromRoute('blocktabs.add'),
   ));
   return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function render() {
   $build = parent::render();
   $build['table']['#empty'] = t('No crop types available. <a href="@link">Add crop type</a>.', [
     '@link' => $this->urlGenerator->generateFromRoute('crop.type_add'),
   ]);
   return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE)
 {
     $generated_url = $this->urlGenerator->generateFromRoute($name, $parameters, $options, TRUE);
     if (!$collect_bubbleable_metadata) {
         $this->bubble($generated_url, $options);
     }
     return $collect_bubbleable_metadata ? $generated_url : $generated_url->getGeneratedUrl();
 }
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $types = $this->nodeTypeStorage->loadMultiple();
     if (empty($types)) {
         $create_url = $this->urlGenerator->generateFromRoute('node.type_add');
         $this->setMessage($this->t('You do not have any content types that can be generated. <a href=":create-type">Go create a new content type</a>', array(':create-type' => $create_url)), 'error', FALSE);
         return;
     }
     $options = array();
     foreach ($types as $type) {
         $options[$type->id()] = array('type' => array('#markup' => $type->label()));
         if ($this->commentManager) {
             $comment_fields = $this->commentManager->getFields('node');
             $map = array($this->t('Hidden'), $this->t('Closed'), $this->t('Open'));
             $fields = array();
             foreach ($comment_fields as $field_name => $info) {
                 // Find all comment fields for the bundle.
                 if (in_array($type->id(), $info['bundles'])) {
                     $instance = FieldConfig::loadByName('node', $type->id(), $field_name);
                     $default_value = $instance->getDefaultValueLiteral();
                     $default_mode = reset($default_value);
                     $fields[] = new FormattableMarkup('@field: @state', array('@field' => $instance->label(), '@state' => $map[$default_mode['status']]));
                 }
             }
             // @todo Refactor display of comment fields.
             if (!empty($fields)) {
                 $options[$type->id()]['comments'] = array('data' => array('#theme' => 'item_list', '#items' => $fields));
             } else {
                 $options[$type->id()]['comments'] = $this->t('No comment fields');
             }
         }
     }
     $header = array('type' => $this->t('Content type'));
     if ($this->commentManager) {
         $header['comments'] = array('data' => $this->t('Comments'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM));
     }
     $form['node_types'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options);
     $form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('<strong>Delete all content</strong> in these content types before generating new content.'), '#default_value' => $this->getSetting('kill'));
     $form['num'] = array('#type' => 'number', '#title' => $this->t('How many nodes would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0);
     $options = array(1 => $this->t('Now'));
     foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
         $options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
     }
     $form['time_range'] = array('#type' => 'select', '#title' => $this->t('How far back in time should the nodes be dated?'), '#description' => $this->t('Node creation dates will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
     $form['max_comments'] = array('#type' => $this->moduleHandler->moduleExists('comment') ? 'number' : 'value', '#title' => $this->t('Maximum number of comments per node.'), '#description' => $this->t('You must also enable comments for the content types you are generating. Note that some nodes will randomly receive zero comments. Some will receive the max.'), '#default_value' => $this->getSetting('max_comments'), '#min' => 0, '#access' => $this->moduleHandler->moduleExists('comment'));
     $form['title_length'] = array('#type' => 'number', '#title' => $this->t('Maximum number of words in titles'), '#default_value' => $this->getSetting('title_length'), '#required' => TRUE, '#min' => 1, '#max' => 255);
     $form['add_alias'] = array('#type' => 'checkbox', '#disabled' => !$this->moduleHandler->moduleExists('path'), '#description' => $this->t('Requires path.module'), '#title' => $this->t('Add an url alias for each node.'), '#default_value' => FALSE);
     $form['add_statistics'] = array('#type' => 'checkbox', '#title' => $this->t('Add statistics for each node (node_counter table).'), '#default_value' => TRUE, '#access' => $this->moduleHandler->moduleExists('statistics'));
     $options = array();
     // We always need a language.
     $languages = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
     foreach ($languages as $langcode => $language) {
         $options[$langcode] = $language->getName();
     }
     $form['add_language'] = array('#type' => 'select', '#title' => $this->t('Set language on nodes'), '#multiple' => TRUE, '#description' => $this->t('Requires locale.module'), '#options' => $options, '#default_value' => array($this->languageManager->getDefaultLanguage()->getId()));
     $form['#redirect'] = FALSE;
     return $form;
 }
Exemple #12
0
 /**
  * @param string|\Symfony\Component\Routing\Route $name
  * @param array $parameters
  * @param array $options
  * @param bool $collect_bubbleable_metadata
  * @return \Drupal\Core\GeneratedUrl|string
  */
 public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE)
 {
     $hostOverride = null;
     $originalHost = null;
     $action = array_key_exists('purl_context', $options) && $options['purl_context'] == false ? Context::EXIT_CONTEXT : Context::ENTER_CONTEXT;
     $this->contextHelper->preGenerate($this->matchedModifiers->createContexts($action), $name, $parameters, $options, $collect_bubbleable_metadata);
     if (isset($options['host']) && strlen((string) $options['host']) > 0) {
         $hostOverride = $options['host'];
         $originalHost = $this->getContext()->getHost();
         $this->getContext()->setHost($hostOverride);
     }
     $result = $this->urlGenerator->generateFromRoute($name, $parameters, $options, $collect_bubbleable_metadata);
     // Reset the original host in request context.
     if ($hostOverride) {
         $this->getContext()->setHost($originalHost);
     }
     return $result;
 }
 /**
  * Generates an absolute URL given a route name and parameters.
  *
  * @param $name
  *   The name of the route.
  * @param array $parameters
  *   An associative array of route parameter names and values.
  * @param array $options
  *   (optional) An associative array of additional options. The 'absolute'
  *   option is forced to be TRUE.
  *
  * @return string
  *   The generated absolute URL for the given route.
  *
  * @todo Add an option for scheme-relative URLs.
  */
 public function getUrl($name, $parameters = array(), $options = array())
 {
     // Generate URL.
     $options['absolute'] = TRUE;
     $generated_url = $this->urlGenerator->generateFromRoute($name, $parameters, $options, TRUE);
     // Return as render array, so we can bubble the bubbleable metadata.
     $build = ['#markup' => $generated_url->getGeneratedUrl()];
     $generated_url->applyTo($build);
     return $build;
 }
 /**
  * Initializes devel module requirements.
  */
 public function onRequest(GetResponseEvent $event)
 {
     if (!devel_silent()) {
         if ($this->account->hasPermission('access devel information')) {
             devel_set_handler(devel_get_handlers());
             // We want to include the class early so that anyone may call krumo()
             // as needed. See http://krumo.sourceforge.net/
             has_krumo();
             // See http://www.firephp.org/HQ/Install.htm
             $path = NULL;
             if (@(include_once 'fb.php') || @(include_once 'FirePHPCore/fb.php')) {
                 // FirePHPCore is in include_path. Probably a PEAR installation.
                 $path = '';
             } elseif ($this->moduleHandler->moduleExists('libraries')) {
                 // Support Libraries API - http://drupal.org/project/libraries
                 $firephp_path = libraries_get_path('FirePHPCore');
                 $firephp_path = $firephp_path ? $firephp_path . '/lib/FirePHPCore/' : '';
                 $chromephp_path = libraries_get_path('chromephp');
             } else {
                 $firephp_path = DRUPAL_ROOT . '/libraries/FirePHPCore/lib/FirePHPCore/';
                 $chromephp_path = './' . drupal_get_path('module', 'devel') . '/chromephp';
             }
             // Include FirePHP if it exists.
             if (!empty($firephp_path) && file_exists($firephp_path . 'fb.php')) {
                 include_once $firephp_path . 'fb.php';
                 include_once $firephp_path . 'FirePHP.class.php';
             }
             // Include ChromePHP if it exists.
             if (!empty($chromephp_path) && file_exists($chromephp_path .= '/ChromePhp.php')) {
                 include_once $chromephp_path;
             }
         }
     }
     if ($this->config->get('rebuild_theme')) {
         drupal_theme_rebuild();
         // Ensure that the active theme object is cleared.
         $theme_name = \Drupal::theme()->getActiveTheme()->getName();
         \Drupal::state()->delete('theme.active_theme.' . $theme_name);
         \Drupal::theme()->resetActiveTheme();
         /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler*/
         $theme_handler = \Drupal::service('theme_handler');
         $theme_handler->refreshInfo();
         // @todo This is not needed after https://www.drupal.org/node/2330755
         $list = $theme_handler->listInfo();
         $theme_handler->addTheme($list[$theme_name]);
         if (\Drupal::service('flood')->isAllowed('devel.rebuild_theme_warning', 1)) {
             \Drupal::service('flood')->register('devel.rebuild_theme_warning');
             if (!devel_silent() && $this->account->hasPermission('access devel information')) {
                 drupal_set_message(t('The theme information is being rebuilt on every request. Remember to <a href="@url">turn off</a> this feature on production websites.', array('@url' => $this->urlGenerator->generateFromRoute('devel.admin_settings'))));
             }
         }
     }
     drupal_register_shutdown_function('devel_shutdown');
 }
 /**
  * Initializes devel module requirements.
  */
 public function onRequest(GetResponseEvent $event)
 {
     if ($this->config->get('rebuild_theme')) {
         drupal_theme_rebuild();
         // Ensure that the active theme object is cleared.
         $theme_name = \Drupal::theme()->getActiveTheme()->getName();
         \Drupal::state()->delete('theme.active_theme.' . $theme_name);
         \Drupal::theme()->resetActiveTheme();
         /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler*/
         $theme_handler = \Drupal::service('theme_handler');
         $theme_handler->refreshInfo();
         // @todo This is not needed after https://www.drupal.org/node/2330755
         $list = $theme_handler->listInfo();
         $theme_handler->addTheme($list[$theme_name]);
         if (\Drupal::service('flood')->isAllowed('devel.rebuild_theme_warning', 1)) {
             \Drupal::service('flood')->register('devel.rebuild_theme_warning');
             if ($this->account->hasPermission('access devel information')) {
                 drupal_set_message(t('The theme information is being rebuilt on every request. Remember to <a href=":url">turn off</a> this feature on production websites.', array(':url' => $this->urlGenerator->generateFromRoute('devel.admin_settings'))));
             }
         }
     }
 }
Exemple #16
0
 /**
  * Tests the output process.
  */
 public function testProcessOutbound()
 {
     $expected_cacheability = (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT);
     $request_stack = \Drupal::requestStack();
     /** @var \Symfony\Component\Routing\RequestContext $request_context */
     $request_context = \Drupal::service('router.request_context');
     // Test request with subdir on homepage.
     $server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/subdir', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], [], TRUE, TRUE));
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('#test-fragment');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], ['fragment' => 'test-fragment'], TRUE));
     // Test request with subdir on other page.
     $server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], [], TRUE, TRUE));
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('#test-fragment');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], ['fragment' => 'test-fragment'], TRUE));
     // Test request without subdir on the homepage.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], [], TRUE, TRUE));
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('#test-fragment');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], ['fragment' => 'test-fragment'], TRUE));
     // Test request without subdir on other page.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/node/add', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], [], TRUE, TRUE));
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('#test-fragment');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<none>', [], ['fragment' => 'test-fragment'], TRUE));
 }
Exemple #17
0
 /**
  * {@inheritdoc}
  */
 public function buildEmbed(JuiceboxGalleryInterface $gallery, $settings, $xml_route_info, $add_js = TRUE, $add_xml = FALSE, $contextual = array())
 {
     // Merge all settings.
     $settings = $settings + $this->getGlobalSettings();
     // Set some defaults for the route info.
     $xml_route_info += array('route_name' => '', 'route_parameters' => array(), 'options' => array());
     // Prep the ids that may be used.
     $embed_id = $gallery->getId();
     $embed_xml_id = 'xml--' . $embed_id;
     // Construct the base render array for the gallery.
     $output = array('#gallery' => $gallery, '#theme' => 'juicebox_embed_markup', '#settings' => $settings, '#attached' => array(), '#contextual_links' => $contextual + array('juicebox_conf_global' => array('route_parameters' => array())), '#cache' => array('tags' => array('juicebox_gallery')), '#suffix' => '');
     // Process JS additions.
     if ($add_js) {
         // If we are also embedding the XML we want to set some query string
         // values on the XML URL that will allow the XML build methods to fetch
         // it later.
         $embed_query_additions = array();
         if ($add_xml) {
             $embed_query_additions['xml-source-path'] = trim($this->current_path_stack->getPath(), '/');
             $embed_query_additions['xml-source-id'] = $embed_xml_id;
         }
         // Add some query params that apply to all types of Juicebox galleries and
         // generate the final XML URL.
         $xml_query_additions = array_merge(array('checksum' => $gallery->getChecksum()), $embed_query_additions);
         $xml_options = array_merge_recursive(array('query' => $xml_query_additions), $xml_route_info['options']);
         $xml_url = $this->urlGenerator->generateFromRoute($xml_route_info['route_name'], $xml_route_info['route_parameters'], $xml_options);
         // Add the main library.
         $output['#attached']['library'][] = 'juicebox/juicebox';
         // Add the JS gallery details as Drupal.settings.
         $output['#attached']['drupalSettings']['juicebox'] = array($embed_id => $gallery->getJavascriptVars($xml_url));
         // Add some local JS (implementing Drupal.behaviors) that will process
         // the Drupal.settings above into a new client-side juicebox object.
         $output['#attached']['library'][] = 'juicebox/juicebox.local';
     }
     if ($add_xml) {
         $output['#suffix'] .= $gallery->renderXml($embed_xml_id);
     }
     // Ensure that our suffix is not further sanitized.
     $output['#suffix'] = SafeMarkup::format($output['#suffix'], array());
     return $output;
 }
 /**
  * Views the configured fixed rates.
  *
  * @return array
  *   A renderable array.
  */
 public function overview()
 {
     /** @var \Drupal\currency\Plugin\Currency\ExchangeRateProvider\FixedRates $plugin */
     $plugin = $this->currencyExchangeRateProviderManager->createInstance('currency_fixed_rates');
     $rates = $plugin->loadALl();
     $form['rates'] = array('#empty' => $this->t('There are no exchange rates yet. <a href="@path">Add an exchange rate</a>.', array('@path' => $this->urlGenerator->generateFromRoute('currency.exchange_rate_provider.fixed_rates.add'))), '#header' => array($this->t('From'), $this->t('To'), $this->t('Exchange rate'), $this->t('Operations')), '#type' => 'table');
     foreach ($rates as $currency_code_from => $currency_codes_to) {
         foreach ($currency_codes_to as $currency_code_to => $rate) {
             $currency_from = $this->currencyStorage->load($currency_code_from);
             $currency_to = $this->currencyStorage->load($currency_code_to);
             if ($currency_from && $currency_to) {
                 $row['currency_from'] = array('#markup' => $currency_from->label(), '#type' => 'item');
                 $row['currency_to'] = array('#markup' => $currency_to->label(), '#type' => 'item');
                 $row['rate'] = array('#markup' => $this->currencyAmountFormatterManager->getDefaultPlugin()->formatAmount($currency_to, $rate), '#type' => 'item');
                 $row['operations'] = array('#links' => array(array('title' => $this->t('edit'), 'route_name' => 'currency.exchange_rate_provider.fixed_rates.edit', 'route_parameters' => array('currency_code_from' => $currency_code_from, 'currency_code_to' => $currency_code_to))), '#type' => 'operations');
                 $form['rates'][] = $row;
             }
         }
     }
     return $form;
 }
Exemple #19
0
 /**
  * {@inheritdoc}
  */
 public function redirectForm(FormStateInterface $form_state)
 {
     $redirect = $form_state->getRedirect();
     // Allow using redirect responses directly if needed.
     if ($redirect instanceof RedirectResponse) {
         return $redirect;
     }
     $url = NULL;
     // Check for a route-based redirection.
     if ($redirect instanceof Url) {
         $url = $redirect->setAbsolute()->toString();
     } elseif ($redirect === NULL) {
         $request = $this->requestStack->getCurrentRequest();
         $url = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => $request->query->all(), 'absolute' => TRUE]);
     }
     if ($url) {
         // According to RFC 7231, 303 See Other status code must be used to redirect
         // user agent (and not default 302 Found).
         // @see http://tools.ietf.org/html/rfc7231#section-6.4.4
         return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function blockForm($form, FormStateInterface $form_state)
 {
     // Get the theme.
     $theme = $form_state['block_theme'];
     // Get permissions.
     $administer_themes_access = $this->currentUser->hasPermission('administer themes');
     $administer_site_configuration_access = $this->currentUser->hasPermission('administer site configuration');
     if ($administer_themes_access) {
         // Get paths to theme settings pages.
         $appearance_settings_url = $this->urlGenerator->generateFromRoute('system.theme_settings');
         $theme_settings_url = $this->urlGenerator->generateFromRoute('system.theme_settings_theme', array('theme' => $theme));
         // Provide links to the Appearance Settings and Theme Settings pages
         // if the user has access to administer themes.
         $site_logo_description = $this->t('Defined on the <a href="@appearance">Appearance Settings</a> or <a href="@theme">Theme Settings</a> page.', array('@appearance' => $appearance_settings_url, '@theme' => $theme_settings_url));
     } else {
         // Explain that the user does not have access to the Appearance and Theme
         // Settings pages.
         $site_logo_description = $this->t('Defined on the Appearance or Theme Settings page. You do not have the appropriate permissions to change the site logo.');
     }
     if ($administer_site_configuration_access) {
         // Get paths to settings pages.
         $site_information_url = $this->urlGenerator->generateFromRoute('system.site_information_settings');
         // Provide link to Site Information page if the user has access to
         // administer site configuration.
         $site_name_description = $this->t('Defined on the <a href="@information">Site Information</a> page.', array('@information' => $site_information_url));
         $site_slogan_description = $this->t('Defined on the <a href="@information">Site Information</a> page.', array('@information' => $site_information_url));
     } else {
         // Explain that the user does not have access to the Site Information
         // page.
         $site_name_description = $this->t('Defined on the Site Information page. You do not have the appropriate permissions to change the site logo.');
         $site_slogan_description = $this->t('Defined on the Site Information page. You do not have the appropriate permissions to change the site logo.');
     }
     $form['block_branding'] = array('#type' => 'fieldset', '#title' => $this->t('Toggle branding elements'), '#description' => $this->t('Choose which branding elements you want to show in this block instance.'));
     $form['block_branding']['use_site_logo'] = array('#type' => 'checkbox', '#title' => $this->t('Site logo'), '#description' => $site_logo_description, '#default_value' => $this->configuration['use_site_logo']);
     $form['block_branding']['use_site_name'] = array('#type' => 'checkbox', '#title' => $this->t('Site name'), '#description' => $site_name_description, '#default_value' => $this->configuration['use_site_name']);
     $form['block_branding']['use_site_slogan'] = array('#type' => 'checkbox', '#title' => $this->t('Site slogan'), '#description' => $site_slogan_description, '#default_value' => $this->configuration['use_site_slogan']);
     return $form;
 }
Exemple #21
0
 /**
  * {@inheritdoc}
  *
  * We override ::render() so that we can add our own content above the table.
  * parent::render() is where EntityListBuilder creates the table using our
  * buildHeader() and buildRow() implementations.
  */
 public function render()
 {
     $build['description'] = array('#markup' => $this->t('Content Entity Example implements a Contacts model. These contacts are fieldable entities. You can manage the fields on the <a href="@adminlink">Contacts admin page</a>.', array('@adminlink' => $this->urlGenerator->generateFromRoute('content_entity_example.contact_settings'))));
     $build['table'] = parent::render();
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $build = parent::render();
     $build['table']['#empty'] = $this->t('There are currently no styles. <a href=":url">Add a new one</a>.', [':url' => $this->urlGenerator->generateFromRoute('image.style_add')]);
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $this->data['version'] = Drupal::VERSION;
     $this->data['profile'] = drupal_get_profile();
     $this->data['config_url'] = $this->urlGenerator->generateFromRoute('webprofiler.settings', [], ['query' => $this->redirectDestination->getAsArray()]);
 }
Exemple #24
0
 /**
  * Format the pgtCallbackURL parameter for use with proxying.
  *
  * We have to do a str_replace to force https for the proxy callback URL,
  * because it must use https, and setting the option 'https => TRUE' in the
  * options array won't force https if the user accessed the login route over
  * http and mixed-mode sessions aren't allowed.
  *
  * @return string
  *   The pgtCallbackURL, fully formatted.
  */
 private function formatProxyCallbackURL()
 {
     return str_replace('http://', 'https://', $this->urlGenerator->generateFromRoute('cas.proxyCallback', array(), array('absolute' => TRUE)));
 }
 /**
  * Generates an absolute URL given a route name and parameters.
  *
  * @param $name
  *   The name of the route.
  * @param array $parameters
  *   An associative array of route parameter names and values.
  * @param array $options
  *   (optional) An associative array of additional options. The 'absolute'
  *   option is forced to be TRUE.
  *
  * @return string
  *   The generated absolute URL for the given route.
  *
  * @todo Add an option for scheme-relative URLs.
  */
 public function getUrl($name, $parameters = array(), $options = array())
 {
     $options['absolute'] = TRUE;
     return $this->urlGenerator->generateFromRoute($name, $parameters, $options);
 }