Created
May 10, 2022 02:39
-
-
Save vishalbandre/e2311c61e0f0040da91001a36571226e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\vishal_default_config\Plugin\Block; | |
use Drupal\Core\Block\BlockBase; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Provides a 'Default' Block. | |
* | |
* @Block( | |
* id = "vishal_default_config", | |
* admin_label = @Translation("Default Block Plugin"), | |
* category = @Translation("Custom"), | |
* ) | |
*/ | |
class DefaultBlock extends BlockBase implements ContainerFactoryPluginInterface { | |
/** | |
* Stores the configuration factory. | |
* | |
* @var \Drupal\Core\Config\ConfigFactoryInterface | |
*/ | |
protected $configFactory; | |
/** | |
* Creates a SystemBrandingBlock instance. | |
* | |
* @param array $configuration | |
* A configuration array containing information about the plugin instance. | |
* @param string $plugin_id | |
* The plugin_id for the plugin instance. | |
* @param mixed $plugin_definition | |
* The plugin implementation definition. | |
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory | |
* The factory for configuration objects. | |
*/ | |
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) { | |
parent::__construct($configuration, $plugin_id, $plugin_definition); | |
$this->configFactory = $config_factory; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
return new static( | |
$configuration, | |
$plugin_id, | |
$plugin_definition, | |
$container->get('config.factory') | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function defaultConfiguration() { | |
// var_dump($this->configFactory); | |
if($this->configFactory->get('vishal_default_config.settings')->get('vishal_default_config.name')) { | |
} | |
$conf = [ | |
'default_name' => 'Default Block Name', | |
]; | |
//$default_config = $this->configFactory->get('vishal_default_config'); | |
// $name = $default_config->get('vishal_default_config.name'); | |
// return [ | |
// 'vishal_default_config_block_name' => $default_config, | |
// ]; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function build() { | |
return [ | |
'#markup' => $this->t('Default Config Plugin!'), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment