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.
<?php
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.