Configure the Darkmode switcher block.
6 unresolved threads
6 unresolved threads
Closes #3397545
Merge request reports
Activity
Filter activity
32 32 }) 33 33 } 34 34 } 35 })(Drupal, once); 35 })(Drupal, once,drupalSettings); changed this line in version 2 of the diff
12 18 * admin_label = @Translation("Darkmode Switcher"), 13 19 * ) 14 20 */ 15 class DarkmodeSwitcherBlock extends BlockBase { 21 class DarkmodeSwitcherBlock extends BlockBase implements ContainerFactoryPluginInterface { 22 23 24 public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) { 22 23 24 public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) { 25 parent::__construct($configuration, $plugin_id, $plugin_definition); 26 $this->config = $config_factory; 27 } 28 29 /** 30 * {@inheritdoc} 31 */ 32 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { 33 return new static($configuration, $plugin_id, $plugin_definition, 34 $container->get('config.factory') 35 ); 36 } 37 /** Fix CS 1 blank line after function
Edited by Bohdan Melnychukchanged this line in version 2 of the diff
51 $config = $this->config->get('darkmode.config'); 52 $attributes = $config->get('attributes'); 53 $conf = ['attributes' => $attributes]; 54 $config_text = Yaml::encode($conf); 55 $form['darkmode'] = [ 56 '#type' => 'textarea', 57 '#title' => $this->t('Dark Mode Styling'), 58 '#description' => $this->t('Provide css for styling.'), 59 '#default_value' => $config_text, 60 '#rows' => 15, 61 '#attributes' => ['data-yaml-editor' => 'true'], 62 63 ]; 64 return $form; 65 } 66 /** changed this line in version 2 of the diff
71 try { 72 $form_state->set('darkmode', Yaml::decode($config_text)); 73 } 74 catch (InvalidDataTypeException $e) { 75 $form_state->setErrorByName('darkmode', $e->getMessage()); 76 } 77 78 } 79 80 /** 81 * {@inheritdoc} 82 */ 83 public function blockSubmit($form, FormStateInterface $form_state) { 84 parent::blockSubmit($form, $form_state); 85 $values = $form_state->get('darkmode'); 86 $config = $this->config->getEditable('darkmode.config'); changed this line in version 2 of the diff
85 $values = $form_state->get('darkmode'); 86 $config = $this->config->getEditable('darkmode.config'); 87 $config->setData($values ); 88 $config->save(); 89 } 16 90 17 91 /** 18 92 * {@inheritdoc} 19 93 */ 20 94 public function build() { 95 $config = $this->config->get('darkmode.config'); 96 $attributes = $config->get('attributes'); 21 97 $build['content'] = [ 22 98 '#attached' => [ 99 'drupalSettings' => [ 100 'darkmode'=> [ changed this line in version 2 of the diff
added 1 commit
Please register or sign in to reply