Commit babc1f58 authored by git's avatar git Committed by Maksym Yemets
Browse files

Issue #3271375 by omkar-pd, Ruturaj Chaubey, jcnventura: Show the banner in a block

parent 47ee4b8f
Loading
Loading
Loading
Loading
+50 −0
Changes for src/Plugin/Block/StandWithUkraine.php: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\stand_with_ukraine\Plugin\Block;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Provides a block with a Stand with Ukrain Banner.
 *
 * @Block(
 *   id = "stand_with_ukraine_block",
 *   admin_label = @Translation("Stand With Ukraine block"),
 * )
 */
class StandWithUkraine extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    return [
      '#markup' => $this->t('<div id="stand_with_ukraine_overlay"><a title="Stand With Ukraine" target="_blank" href="https://war.ukraine.ua/">#StandWithUkraine</a></div>'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function blockAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermission($account, 'access content');
  }

  /**
   * {@inheritdoc}
   */
  public function blockForm($form, FormStateInterface $form_state) {
    $config = $this->getConfiguration();

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function blockSubmit($form, FormStateInterface $form_state) {
    $this->configuration['stand_with_ukraine_settings'] = $form_state->getValue('stand_with_ukraine_settings');
  }
}
+5 −2
Changes for stand_with_ukraine.libraries.yml: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,8 +2,11 @@ swu_behaviors:
  version: 1.x
  js:
    js/stand_with_ukraine.js: { }
  dependencies:
    - core/drupal

styling:
  version: 1.x
  css:
    theme:
      css/stand_with_ukraine.css: { }
  dependencies:
    - core/drupal
+5 −0
Changes for stand_with_ukraine.module: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,11 @@ function stand_with_ukraine_page_attachments(array &$attachments) {
      'hashtag' => '#StandWithUkraine',
      'url' => 'https://war.ukraine.ua/'
    ];
    $attachments['#attached']['library'][] = "stand_with_ukraine/styling";
    $block = Drupal\block\Entity\Block::load('standwithukraineblock');
    $status = $block ? $block->status() : NULL;
    if (empty($status)) {
      $attachments['#attached']['library'][] = "stand_with_ukraine/swu_behaviors";
    }
  }
}