Beispiel #1
0
 /**
  * Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm().
  */
 public function buildForm(array $form, array &$form_state, $pid = NULL)
 {
     $this->pathAlias = $this->aliasStorage->load(array('pid' => $pid));
     $form = parent::buildForm($form, $form_state);
     // @todo Convert to getCancelRoute() after http://drupal.org/node/1987802.
     $form['actions']['cancel']['#href'] = 'admin/config/search/path';
     return $form;
 }
Beispiel #2
0
 /**
  * {@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)));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function loadBySource($source, $language = LanguageInterface::LANGCODE_NOT_SPECIFIED)
 {
     $alias = $this->aliasStorage->load(['source' => $source, 'langcode' => $language]);
     // If no alias was fetched and if a language was specified, fallbacks to
     // undefined language.
     if (!$alias && $language !== LanguageInterface::LANGCODE_NOT_SPECIFIED) {
         $alias = $this->aliasStorage->load(['source' => $source, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     }
     return $alias;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL)
 {
     $this->pathAlias = $this->aliasStorage->load(array('pid' => $pid));
     $form = parent::buildForm($form, $form_state);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function loadBySource($source, $language = LanguageInterface::LANGCODE_NOT_SPECIFIED)
 {
     // @todo convert this to be a query on alias storage.
     $pid = $this->database->queryRange("SELECT pid FROM {url_alias} WHERE source = :source AND langcode IN (:language, :language_none) ORDER BY langcode DESC, pid DESC", 0, 1, array(':source' => $source, ':language' => $language, ':language_none' => LanguageInterface::LANGCODE_NOT_SPECIFIED))->fetchField();
     return $this->aliasStorage->load(array('pid' => $pid));
 }