validatePath example

break;
    }
  }

  /** * {@inheritdoc} */
  public function validateOptionsForm(&$form, FormStateInterface $form_state) {
    parent::validateOptionsForm($form$form_state);

    if ($form_state->get('section') == 'path') {
      $errors = $this->validatePath($form_state->getValue('path'));
      foreach ($errors as $error) {
        $form_state->setError($form['path']$error);
      }

      // Automatically remove '/' and trailing whitespace from path.       $form_state->setValue('path', trim($form_state->getValue('path'), '/ '));
    }
  }

  /** * {@inheritdoc} */

    public function valid()
    {
        // Return true if and only if all parts of the URI have passed validation         return $this->validateUsername()
           and $this->validatePassword()
           and $this->validateHost()
           and $this->validatePort()
           and $this->validatePath()
           and $this->validateQuery()
           and $this->validateFragment();
    }

    /** * Returns the username portion of the URL, or FALSE if none. * * @return string */
    public function getUsername()
    {
        
$form_state->unsetValue('logo_path');
      }

      // When intending to use the default favicon, unset the favicon_path.       if ($form_state->getValue('default_favicon')) {
        $form_state->unsetValue('favicon_path');
      }

      // If the user provided a path for a logo or favicon file, make sure a file       // exists at that path.       if ($form_state->getValue('logo_path')) {
        $path = $this->validatePath($form_state->getValue('logo_path'));
        if (!$path) {
          $form_state->setErrorByName('logo_path', $this->t('The custom logo path is invalid.'));
        }
      }
      if ($form_state->getValue('favicon_path')) {
        $path = $this->validatePath($form_state->getValue('favicon_path'));
        if (!$path) {
          $form_state->setErrorByName('favicon_path', $this->t('The custom favicon path is invalid.'));
        }
      }
    }
  }
Home | Imprint | This part of the site doesn't use cookies.