I have made a simple example to practice using the configuration API in Drupal 8. I created the twitter_pull.credentials.yml file in the config/install folder with the following content and flushed the cache.
oauth_access_token: "12345"
oauth_access_token_secret: "67890"
consumer_key: "54321"
consumer_secret: "09876"
In a custom block, I use the following code to retrieve the configuration object.
namespace Drupal\twitter_pull\Plugin\Block;
use Drupal\block\BlockBase;
/**
* Provides a block for executing PHP code.
*
* @Block(
* id = "twitter_pull_tweets_block",
* admin_label = @Translation("Twitter Tweets")
* )
*/
class TweetsBlock extends BlockBase {
/**
* Builds and returns the renderable array for this block plugin.
*
* @return array
* A renderable array representing the content of the block.
*
* @see \Drupal\block\BlockViewBuilder
*/
public function build() {
$config = \Drupal::config('twitter_pull.credentials');
$enabled = \Drupal::config('system.maintenance')->get('enabled');
dpm($enabled);
dpm($config);
drupal_set_message($enabled);
return 'this is a block: ' . $config->get('consumer_key');
}
}
I don't get any value from \Drupal::config('system.maintenance')->get('enabled')
nor $config->get('consumer_key')
.
What am I missing here?