Example #1
0
 /**
  * {@inheritdoc}
  */
 public function evaluate()
 {
     $path = $this->getContextValue('path');
     $language = $this->getContext('language')->getContextData() ? $this->getContextValue('language')->getId() : NULL;
     $alias = $this->aliasManager->getAliasByPath($path, $language);
     return $alias != $path;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if (empty($options['alias'])) {
         $langcode = isset($options['language']) ? $options['language']->getId() : NULL;
         $path = $this->aliasManager->getAliasByPath($path, $langcode);
     }
     return $path;
 }
Example #3
0
 public function getArgument()
 {
     $path = trim($this->currentPath->getPath($this->view->getRequest()), '/');
     if ($this->options['use_alias']) {
         $path = $this->aliasManager->getAliasByPath($path);
     }
     $args = explode('/', $path);
     if (isset($args[$this->options['index']])) {
         return $args[$this->options['index']];
     }
 }
Example #4
0
 public function getArgument()
 {
     // @todo Remove dependency on the internal _system_path attribute:
     //   https://www.drupal.org/node/2293581.
     $path = $this->view->getRequest()->attributes->get('_system_path');
     if ($this->options['use_alias']) {
         $path = $this->aliasManager->getAliasByPath($path);
     }
     $args = explode('/', $path);
     if (isset($args[$this->options['index']])) {
         return $args[$this->options['index']];
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $site_config = $this->config('system.site');
     $site_mail = $site_config->get('mail');
     if (empty($site_mail)) {
         $site_mail = ini_get('sendmail_from');
     }
     $form['site_information'] = array('#type' => 'details', '#title' => t('Site details'), '#open' => TRUE);
     $form['site_information']['site_name'] = array('#type' => 'textfield', '#title' => t('Site name'), '#default_value' => $site_config->get('name'), '#required' => TRUE);
     $form['site_information']['site_slogan'] = array('#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => $site_config->get('slogan'), '#description' => t("How this is used depends on your site's theme."));
     $form['site_information']['site_mail'] = array('#type' => 'email', '#title' => t('Email address'), '#default_value' => $site_mail, '#description' => t("The <em>From</em> address in automated emails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this email being flagged as spam.)"), '#required' => TRUE);
     $form['front_page'] = array('#type' => 'details', '#title' => t('Front page'), '#open' => TRUE);
     $front_page = $site_config->get('page.front') != 'user/login' ? $this->aliasManager->getAliasByPath($site_config->get('page.front')) : '';
     $form['front_page']['site_frontpage'] = array('#type' => 'textfield', '#title' => t('Default front page'), '#default_value' => $front_page, '#size' => 40, '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'), '#field_prefix' => $this->url('<none>', [], ['absolute' => TRUE]));
     $form['error_page'] = array('#type' => 'details', '#title' => t('Error pages'), '#open' => TRUE);
     $form['error_page']['site_403'] = array('#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), '#default_value' => $site_config->get('page.403'), '#size' => 40, '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'), '#field_prefix' => $this->url('<none>', [], ['absolute' => TRUE]));
     $form['error_page']['site_404'] = array('#type' => 'textfield', '#title' => t('Default 404 (not found) page'), '#default_value' => $site_config->get('page.404'), '#size' => 40, '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'), '#field_prefix' => $this->url('<none>', [], ['absolute' => TRUE]));
     return parent::buildForm($form, $form_state);
 }
Example #6
0
 public function adminOverview($keys)
 {
     // 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 = drupal_get_destination();
     foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
         $row = array();
         $row['data']['alias'] = l(truncate_utf8($data->alias, 50, FALSE, TRUE), $data->source, array('attributes' => array('title' => $data->alias)));
         $row['data']['source'] = l(truncate_utf8($data->source, 50, FALSE, TRUE), $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'), 'route_name' => 'path.admin_edit', 'route_parameters' => array('pid' => $data->pid), 'query' => $destination);
         $operations['delete'] = array('title' => $this->t('Delete'), 'route_name' => 'path.delete', 'route_parameters' => array('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('#theme' => 'pager');
     return $build;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function evaluate()
 {
     // Convert path to lowercase. This allows comparison of the same path
     // with different case. Ex: /Page, /page, /PAGE.
     $pages = Unicode::strtolower($this->configuration['pages']);
     if (!$pages) {
         return TRUE;
     }
     $request = $this->requestStack->getCurrentRequest();
     // Compare the lowercase path alias (if any) and internal path.
     $path = rtrim($this->currentPath->getPath($request), '/');
     $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path));
     return $this->pathMatcher->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher->matchPath($path, $pages);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function getArgument()
 {
     // Don't trim the leading slash since getAliasByPath() requires it.
     $path = rtrim($this->currentPath->getPath($this->view->getRequest()), '/');
     if ($this->options['use_alias']) {
         $path = $this->aliasManager->getAliasByPath($path);
     }
     $args = explode('/', $path);
     // Drop the empty first element created by the leading slash since the path
     // component index doesn't take it into account.
     array_shift($args);
     if (isset($args[$this->options['index']])) {
         return $args[$this->options['index']];
     }
 }
 public function testNormalBahvior()
 {
     // When providing no language, default is used, but trying to lookup a
     // non existing language should yield the same result
     foreach ([null, 'martian'] as $langcode) {
         $alias = $this->aliasManager->getAliasByPath('duplicate-alias-1', $langcode);
         $this->assertSame('duplicate-alias', $alias);
         $source = $this->aliasManager->getPathByAlias('duplicate-alias', $langcode);
         $this->assertSame('duplicate-alias-1', $source);
         $alias = $this->aliasManager->getAliasByPath('normal-source', $langcode);
         $this->assertSame('normal-alias', $alias);
         $source = $this->aliasManager->getPathByAlias('normal-alias', $langcode);
         $this->assertSame('normal-source', $source);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function evaluate()
 {
     // Convert path to lowercase. This allows comparison of the same path
     // with different case. Ex: /Page, /page, /PAGE.
     $pages = Unicode::strtolower($this->configuration['pages']);
     if (!$pages) {
         return TRUE;
     }
     $request = $this->requestStack->getCurrentRequest();
     // Compare the lowercase path alias (if any) and internal path.
     // @todo Remove dependency on the internal _system_path attribute:
     //   https://www.drupal.org/node/2293581.
     $path = $request->attributes->get('_system_path');
     $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path));
     return $this->pathMatcher->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher->matchPath($path, $pages);
 }
Example #11
0
 /**
  * Checks whether a give path matches the ng-lightbox path rules.
  * This function checks both internal paths and aliased paths.
  *
  * @param \Drupal\Core\Url $url
  *   The Url object.
  *
  * @return bool
  *   TRUE if it matches the given rules.
  */
 public function isNgLightboxEnabledPath(Url $url)
 {
     // No lightbox on external Urls.
     if ($url->isExternal()) {
         return FALSE;
     }
     // If we don't want to enable the Lightbox on admin pages.
     if ($this->config->get('skip_admin_paths') && $this->adminContext->isAdminRoute()) {
         return FALSE;
     }
     // @TODO, decide whether we want to try and support paths or to adopt routes
     // like core is trying to force us into.
     $path = strtolower($url->toString());
     // We filter out empty paths because some modules (such as Media) use
     // theme_link() to generate links with empty paths.
     if (empty($path)) {
         return FALSE;
     }
     // Remove the base path.
     if ($base_path = \Drupal::request()->getBasePath()) {
         $path = substr($path, strlen($base_path));
     }
     // Check the cache, see if we've handled this before.
     if (isset($this->matches[$path])) {
         return $this->matches[$path];
     }
     // Normalise the patterns as well so they match the normalised paths.
     $patterns = strtolower($this->config->get('patterns'));
     // Check for internal paths first which is much quicker than the alias lookup.
     if ($this->pathMatcher->matchPath($path, $patterns)) {
         $this->matches[$path] = TRUE;
     } else {
         // Now check for aliases paths.
         $aliased_path = strtolower($this->aliasManager->getAliasByPath($path));
         if ($path != $aliased_path && $this->pathMatcher->matchPath($aliased_path, $patterns)) {
             $this->matches[$path] = TRUE;
         } else {
             // No match.
             $this->matches[$path] = FALSE;
         }
     }
     return $this->matches[$path];
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
 /**
  * Check if a URL path has a URL alias.
  *
  * @param string $path
  *   The path to check.
  * @param \Drupal\Core\Language\LanguageInterface|null $language
  *   An optional language to look up the path in.
  *
  * @return bool
  *   TRUE if the path has an alias in the given language.
  */
 protected function doEvaluate($path, LanguageInterface $language = NULL)
 {
     $langcode = is_null($language) ? NULL : $language->getId();
     $alias = $this->aliasManager->getAliasByPath($path, $langcode);
     return $alias != $path;
 }