Skip to content
Snippets Groups Projects

Configure the Darkmode switcher block.

Merged Sahana N requested to merge issue/darkmode-3397545:3397545-add-the-ability into 1.0.x
6 unresolved threads

Closes #3397545

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
32 32 })
33 33 }
34 34 }
35 })(Drupal, once);
35 })(Drupal, once,drupalSettings);
  • 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 /**
  • 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 /**
  • 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');
  • 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'=> [
  • Sahana N added 1 commit

    added 1 commit

    • d1db7d42 - Created a Darkmode configuration Form.

    Compare with previous version

  • added 1 commit

    • 02c2e01e - Issue #3397545 by bobi-mel: Add the ability to configure the Darkmode Switcher...

    Compare with previous version

  • Bohdan Melnychuk added 4 commits

    added 4 commits

    • 68354d70 - 1 commit from branch project:1.0.x
    • f3639b6e - Configure the Darkmode switcher block.
    • 236236a0 - Created a Darkmode configuration Form.
    • 2856afc4 - Issue #3397545 by bobi-mel: Add the ability to configure the Darkmode Switcher...

    Compare with previous version

  • Please register or sign in to reply
    Loading