/** * {@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; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // Check for empty front page path. if (empty($form_state['values']['site_frontpage'])) { // Set to default "user". form_set_value($form['front_page']['site_frontpage'], 'user', $form_state); } else { // Get the normal path of the front page. form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state['values']['site_frontpage']), $form_state); } // Validate front page path. if (!drupal_valid_path($form_state['values']['site_frontpage'])) { $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); } // Get the normal paths of both error pages. if (!empty($form_state['values']['site_403'])) { form_set_value($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state['values']['site_403']), $form_state); } if (!empty($form_state['values']['site_404'])) { form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state['values']['site_404']), $form_state); } // Validate 403 error path. if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); } // Validate 404 error path. if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) { $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); } parent::validateForm($form, $form_state); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $map = array(); $map[] = array('view.frontpage.page_1', array(), array(), FALSE, '/node'); $map[] = array('node_view', array('node' => '1'), array(), FALSE, '/node/1'); $map[] = array('node_edit', array('node' => '2'), array(), FALSE, '/node/2/edit'); $this->map = $map; $alias_map = array(array('node-alias-test', NULL, FALSE, 'node'), array('node', NULL, FALSE, 'node'), array('node/1', NULL, FALSE, 'node/1'), array('node/2/edit', NULL, FALSE, 'node/2/edit'), array('non-existent', NULL, FALSE, 'non-existent')); // $this->map has $collect_bubbleable_metadata = FALSE; also generate the // $collect_bubbleable_metadata = TRUE case for ::generateFromRoute(). $generate_from_route_map = []; foreach ($this->map as $values) { $generate_from_route_map[] = $values; $generate_from_route_map[] = [$values[0], $values[1], $values[2], TRUE, (new GeneratedUrl())->setGeneratedUrl($values[4])]; } $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface'); $this->urlGenerator->expects($this->any())->method('generateFromRoute')->will($this->returnValueMap($generate_from_route_map)); $this->pathAliasManager = $this->getMock('Drupal\\Core\\Path\\AliasManagerInterface'); $this->pathAliasManager->expects($this->any())->method('getPathByAlias')->will($this->returnValueMap($alias_map)); $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface'); $this->pathValidator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface'); $this->container = new ContainerBuilder(); $this->container->set('router.no_access_checks', $this->router); $this->container->set('url_generator', $this->urlGenerator); $this->container->set('path.alias_manager', $this->pathAliasManager); $this->container->set('path.validator', $this->pathValidator); \Drupal::setContainer($this->container); }
/** * {@inheritdoc} */ public function evaluate() { $alias = $this->getContextValue('alias'); $language = $this->getContext('language')->getContextData() ? $this->getContextValue('language')->getId() : NULL; $path = $this->aliasManager->getPathByAlias($alias, $language); return $path != $alias; }
/** * {@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; }
/** * Tests the processOutbound method. * * @see \Drupal\Core\PathProcessor\PathProcessorAlias::processOutbound */ public function testProcessOutbound() { $this->aliasManager->expects($this->exactly(2))->method('getAliasByPath')->will($this->returnValueMap(array(array('internal-url', NULL, 'urlalias'), array('url', NULL, 'url')))); $this->assertEquals('urlalias', $this->pathProcessor->processOutbound('internal-url')); $options = array('alias' => TRUE); $this->assertEquals('internal-url', $this->pathProcessor->processOutbound('internal-url', $options)); $this->assertEquals('url', $this->pathProcessor->processOutbound('url')); }
/** * @covers ::processOutbound * * @dataProvider providerTestProcessOutbound */ public function testProcessOutbound($path, array $options, $expected_path) { $this->aliasManager->expects($this->any())->method('getAliasByPath')->will($this->returnValueMap(array(array('internal-url', NULL, 'urlalias'), array('url', NULL, 'url')))); $bubbleable_metadata = new BubbleableMetadata(); $this->assertEquals($expected_path, $this->pathProcessor->processOutbound($path, $options, NULL, $bubbleable_metadata)); // Cacheability of paths replaced with path aliases is permanent. // @todo https://www.drupal.org/node/2480077 $this->assertEquals((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT), $bubbleable_metadata); }
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']]; } }
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']]; } }
/** * Builds the response object to be returned. This will be a node. * @param $request * @return \Symfony\Component\HttpFoundation\Response */ public function buildResponseObject($request) { $alias = $request->query->get('path'); $path = $this->aliasManager->getPathByAlias($alias); // If $path does not contain /node/ it's a result of no alias existing // for any nodes in Drupal. if (!strstr("/node/", $path)) { throw new HttpException(404); } $parts = explode("/", $path); $this->entity = Node::load($parts[2]); return true; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $link = $form_state->getValues(); // Make sure we trim and normalize the path first. $link['loc'] = trim($link['loc']); $link['loc'] = $this->aliasManager->getPathByAlias($link['loc'], $link['language']); $form_state->setValue('loc', $link['loc']); $query = db_select('xmlsitemap'); $query->fields('xmlsitemap'); $query->condition('type', 'custom'); $query->condition('loc', $link['loc']); $query->condition('status', 1); $query->condition('access', 1); $query->condition('language', $link['language']); $result = $query->execute()->fetchAssoc(); if ($result != FALSE) { $form_state->setErrorByName('loc', t('There is already an existing link in the sitemap with the path %link.', array('%link' => $link['loc']))); } try { $client = new Client(); $res = $client->get(Url::fromRoute('<front>', [], array('absolute' => TRUE)) . $link['loc']); } catch (ClientException $e) { $form_state->setErrorByName('loc', t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $link['loc']))); } parent::validateForm($form, $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // Check for empty front page path. if ($form_state->isValueEmpty('site_frontpage')) { // Set to default "user/login". $form_state->setValueForElement($form['front_page']['site_frontpage'], 'user/login'); } else { // Get the normal path of the front page. $form_state->setValueForElement($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage'))); } // Validate front page path. if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) { $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_frontpage')))); } // Get the normal paths of both error pages. if (!$form_state->isValueEmpty('site_403')) { $form_state->setValueForElement($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state->getValue('site_403'))); } if (!$form_state->isValueEmpty('site_404')) { $form_state->setValueForElement($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404'))); } // Validate 403 error path. if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) { $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_403')))); } // Validate 404 error path. if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator->isValid($form_state->getValue('site_404'))) { $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_404')))); } parent::validateForm($form, $form_state); }
/** * {@inheritdoc} */ public function isReserved($alias, $source, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED) { // Check if this alias already exists. if ($existing_source = $this->aliasManager->getPathByAlias($alias, $langcode)) { if ($existing_source != $alias) { // If it is an alias for the provided source, it is allowed to keep using // it. If not, then it is reserved. return $existing_source != $source; } } // Then check if there is a route with the same path. if ($this->isRoute($alias)) { return TRUE; } // Finally check if any other modules have reserved the alias. $args = array($alias, $source, $langcode); $implementations = $this->moduleHandler->getImplementations('pathauto_is_alias_reserved'); foreach ($implementations as $module) { $result = $this->moduleHandler->invoke($module, 'pathauto_is_alias_reserved', $args); if (!empty($result)) { // As soon as the first module says that an alias is in fact reserved, // then there is no point in checking the rest of the modules. return TRUE; } } return FALSE; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $source =& $form_state->getValue('source'); $source = $this->aliasManager->getPathByAlias($source); $alias =& $form_state->getValue('alias'); // Trim the submitted value of whitespace and slashes. Ensure to not trim // the slash on the left side. $alias = rtrim(trim(trim($alias), ''), "\\/"); if ($source[0] !== '/') { $form_state->setErrorByName('source', 'The source path has to start with a slash.'); } if ($alias[0] !== '/') { $form_state->setErrorByName('alias', 'The alias path has to start with a slash.'); } // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); if ($this->aliasStorage->aliasExists($alias, $langcode, $this->path['source'])) { $stored_alias = $this->aliasStorage->load(['alias' => $alias, 'langcode' => $langcode]); if ($stored_alias['alias'] !== $alias) { // The alias already exists with different capitalization as the default // implementation of AliasStorageInterface::aliasExists is // case-insensitive. $form_state->setErrorByName('alias', t('The alias %alias could not be added because it is already in use in this language with different capitalization: %stored_alias.', ['%alias' => $alias, '%stored_alias' => $stored_alias['alias']])); } else { $form_state->setErrorByName('alias', t('The alias %alias is already in use in this language.', ['%alias' => $alias])); } } if (!$this->pathValidator->isValid(trim($source, '/'))) { $form_state->setErrorByName('source', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source))); } }
/** * Overrides EntityForm::validate(). */ public function validate(array $form, array &$form_state) { $menu_link = $this->buildEntity($form, $form_state); $normal_path = $this->pathAliasManager->getPathByAlias($menu_link->link_path); if ($menu_link->link_path != $normal_path) { drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $menu_link->link_path, '%normal_path' => $normal_path))); $menu_link->link_path = $normal_path; $form_state['values']['link_path'] = $normal_path; } if (!UrlHelper::isExternal($menu_link->link_path)) { $parsed_link = parse_url($menu_link->link_path); if (isset($parsed_link['query'])) { $menu_link->options['query'] = array(); parse_str($parsed_link['query'], $menu_link->options['query']); } else { // Use unset() rather than setting to empty string // to avoid redundant serialized data being stored. unset($menu_link->options['query']); } if (isset($parsed_link['fragment'])) { $menu_link->options['fragment'] = $parsed_link['fragment']; } else { unset($menu_link->options['fragment']); } if (isset($parsed_link['path']) && $menu_link->link_path != $parsed_link['path']) { $menu_link->link_path = $parsed_link['path']; } } if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) { $this->setFormError('link_path', $form_state, $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path))); } parent::validate($form, $form_state); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $map = array(); $map[] = array('view.frontpage.page_1', array(), array(), '/node'); $map[] = array('node_view', array('node' => '1'), array(), '/node/1'); $map[] = array('node_edit', array('node' => '2'), array(), '/node/2/edit'); $this->map = $map; $alias_map = array(array('node-alias-test', NULL, 'node'), array('node', NULL, 'node'), array('node/1', NULL, 'node/1'), array('node/2/edit', NULL, 'node/2/edit'), array('non-existent', NULL, 'non-existent')); $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface'); $this->urlGenerator->expects($this->any())->method('generateFromRoute')->will($this->returnValueMap($this->map)); $this->pathAliasManager = $this->getMock('Drupal\\Core\\Path\\AliasManagerInterface'); $this->pathAliasManager->expects($this->any())->method('getPathByAlias')->will($this->returnValueMap($alias_map)); $this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface'); $this->pathValidator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface'); $this->container = new ContainerBuilder(); $this->container->set('router.no_access_checks', $this->router); $this->container->set('url_generator', $this->urlGenerator); $this->container->set('path.alias_manager', $this->pathAliasManager); $this->container->set('path.validator', $this->pathValidator); \Drupal::setContainer($this->container); }
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; }
/** * {@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); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $link = $form_state->getValues(); $link['loc'] = trim($link['loc']); $link['loc'] = $this->aliasManager->getPathByAlias($link['loc'], $link['language']); $form_state->setValue('loc', $link['loc']); try { $client = new Client(); $res = $client->get(Url::fromRoute('<front>', [], array('absolute' => TRUE)) . $link['loc']); } catch (ClientException $e) { $form_state->setErrorByName('loc', t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $link['loc']))); } parent::validateForm($form, $form_state); }
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 submitForm(array &$form, FormStateInterface $form_state) { // Remove unnecessary values. $form_state->cleanValues(); $pid = $form_state->getValue('pid', 0); $source =& $form_state->getValue('source'); $source = $this->aliasManager->getPathByAlias($source); $alias = $form_state->getValue('alias'); // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->aliasStorage->save($source, $alias, $langcode, $pid); drupal_set_message($this->t('The alias has been saved.')); $form_state->setRedirect('path.admin_overview'); }
/** * {@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']]; } }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { // Remove unnecessary values. form_state_values_clean($form_state); $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; $source =& $form_state['values']['source']; $source = $this->aliasManager->getPathByAlias($source); $alias = $form_state['values']['alias']; // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LanguageInterface::LANGCODE_NOT_SPECIFIED; $this->aliasStorage->save($source, $alias, $langcode, $pid); drupal_set_message($this->t('The alias has been saved.')); $form_state['redirect_route'] = new Url('path.admin_overview'); }
/** * {@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); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { $source =& $form_state->getValue('source'); $source = $this->aliasManager->getPathByAlias($source); $alias =& $form_state->getValue('alias'); // Trim the submitted value of whitespace and slashes. $alias = trim(trim($alias), " \\/"); // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); if ($this->aliasStorage->aliasExists($alias, $langcode, $this->path['source'])) { $form_state->setErrorByName('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias))); } if (!$this->pathValidator->isValid($source)) { $form_state->setErrorByName('source', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source))); } }
/** * 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]; }
/** * 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; }
/** * Sets up an alias manager that does nothing. */ protected function setupStubAliasManager() { $this->aliasManager->expects($this->any())->method('getPathByAlias')->willReturnArgument(0); }
/** * Ensures system paths for the request get cached. */ public function onKernelTerminate(PostResponseEvent $event) { $this->aliasManager->writeCache(); }
/** * {@inheritdoc} */ public function on404(GetResponseForExceptionEvent $event) { $path = $this->aliasManager->getPathByAlias($this->configFactory->get('system.site')->get('page.404')); $this->makeSubrequest($event, $path, Response::HTTP_NOT_FOUND); }