In the settings.php file, there are (for example) $base_url, $settings['hash_salt'].

I defined $settings['external_url'] = "google.com";

In my custom module, I want to get the $settings['external_url'] value.


namespace Drupal\my_custom_module\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Site\Settings;
use Drupal\Core\Form\FormStateInterface;

* Contribute form.
class MyCustomClass extends FormBase {

   private $base_url;
   public function __construct(){
       $this->base_url = Settings::get('external_url') . '/maps';


   public function validateForm(array &$form, FormStateInterface $form_state) {
      $pb= $form_state->getValue('pb');
      $url = $this->base_url . '?timeline' . $pb;

Then I got this error:

Notice: Trying to get property of non-object

I am using Drupal 8 and PHP 7.

1 Answer 1


Trying using the full path of the class:


In Drupal 8, an ideal place for custom variables is in config files. Create a yml file in the config directory and import the configuration.


external_url: 'url-string-here'

Then to fetch the values, it's:




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.