Beispiel #1
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)));
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     $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;
     if ($this->aliasStorage->aliasExists($alias, $langcode, $source)) {
         $this->setFormError('alias', $form_state, t('The alias %alias is already in use in this language.', array('%alias' => $alias)));
     }
     if (!drupal_valid_path($source)) {
         $this->setFormError('source', $form_state, t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source)));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $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);
     if ($this->aliasStorage->aliasExists($alias, $langcode, $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)));
     }
 }
Beispiel #4
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'])) {
         $form_state->setErrorByName('alias', t('The alias %alias is already in use in this language.', array('%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)));
     }
 }