/**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     if (!$this->pathValidator->isValid($form_state->getValue('path'))) {
         $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
     }
     parent::validate($form, $form_state);
 }
Пример #2
0
 /**
  * {@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);
 }
Пример #3
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)));
     }
 }
Пример #4
0
 /**
  * Creates a new link in the provided shortcut set.
  *
  * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
  *   The shortcut set to add a link to.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect response to the front page, or the previous location.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  */
 public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Request $request)
 {
     $link = $request->query->get('link');
     $name = $request->query->get('name');
     if (parse_url($link, PHP_URL_SCHEME) === NULL && $this->pathValidator->isValid($link)) {
         $shortcut = $this->entityManager()->getStorage('shortcut')->create(array('title' => $name, 'shortcut_set' => $shortcut_set->id(), 'link' => array('uri' => 'internal:/' . $link)));
         try {
             $shortcut->save();
             drupal_set_message($this->t('Added a shortcut for %title.', array('%title' => $shortcut->label())));
         } catch (\Exception $e) {
             drupal_set_message($this->t('Unable to add a shortcut for %title.', array('%title' => $shortcut->label())), 'error');
         }
         return $this->redirect('<front>');
     }
     throw new AccessDeniedHttpException();
 }
 /**
  * {@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)));
     }
 }
Пример #6
0
 /**
  * @param array $form
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $sitemap = \Drupal::service('custom_sitemap.sitemap');
     $custom_links = $sitemap->get_custom_links();
     $name =& $form_state->getValue('name');
     $path =& $form_state->getValue('path');
     if ($form_state->getFormObject()->getFormId() == 'custom_sitemap_add_link_form' && array_key_exists($name, $custom_links)) {
         $form_state->setErrorByName('name', $this->t('The machine name must be unique, \'%name\' allready exists.', array('%name' => $name)));
     }
     if (!preg_match('/^[a-z0-9_]+$/', $name)) {
         $form_state->setErrorByName('name', $this->t('The machine name must only contain lowercase letters, numbers, and underscores.'));
     }
     if ($path[0] !== '/') {
         $form_state->setErrorByName('path', 'The path has to start with a slash.');
     }
     if (!$this->path_validator->isValid(trim($path, '/'))) {
         $form_state->setErrorByName('path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $path)));
     }
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Validate and each email recipient.
     $recipients = explode(',', $form_state->getValue('recipients'));
     foreach ($recipients as &$recipient) {
         $recipient = trim($recipient);
         if (!$this->emailValidator->isValid($recipient)) {
             $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
         }
     }
     $form_state->setValue('recipients', $recipients);
     $redirect_url = $form_state->getValue('redirect');
     if ($redirect_url && $this->pathValidator->isValid($redirect_url)) {
         if (Unicode::substr($redirect_url, 0, 1) !== '/') {
             $form_state->setErrorByName('redirect', $this->t('The path should start with /.'));
         }
     }
 }
Пример #8
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)));
     }
 }