You are here

FooterMessageBlock.php in Footer Message 8

File

src/Plugin/Block/FooterMessageBlock.php
View source
<?php

namespace Drupal\footer_message\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a 'Footer Message' block.
 *
 * @Block(
 *   id = "footer_message_block",
 *   admin_label = @Translation("Footer Message"),
 * )
 */
class FooterMessageBlock extends BlockBase implements ContainerFactoryPluginInterface {

  /**
   * The configuration object factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * Constructs a FooterMessageBlock object.
   *
   * @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\ConfigFactory $config_factory
   *   The configuration object factory.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactory $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 build() {
    $config = $this->configFactory
      ->get('footer_message.settings');
    $message = $config
      ->get('footer_message_msg');
    $format = $config
      ->get('footer_message_format');
    return array(
      '#type' => 'markup',
      '#markup' => check_markup(isset($message) ? $message : '', $format),
      '#cache' => [
        'tags' => [
          'block:footer_message',
        ],
      ],
    );
  }

}

Classes

Namesort descending Description
FooterMessageBlock Provides a 'Footer Message' block.