Skip to content

Instantly share code, notes, and snippets.

@cyberlex404
Created November 19, 2019 20:26
Show Gist options
  • Save cyberlex404/2912d22ac3ea6a8bd5ba6ceda03395fd to your computer and use it in GitHub Desktop.
Save cyberlex404/2912d22ac3ea6a8bd5ba6ceda03395fd to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\arti_custom\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a 'ContactsBlock' block.
*
* @Block(
* id = "arti_contacts",
* admin_label = @Translation("Contacts"),
* )
*/
class ContactsBlock extends BlockBase implements ContainerFactoryPluginInterface {
const INSTITUTE_SETTINGS = 'arti_custom.institute';
/**
* Drupal\Core\Config\ConfigFactoryInterface definition.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Drupal\Core\Render\RendererInterface definition.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition);
$instance->configFactory = $container->get('config.factory');
$instance->renderer = $container->get('renderer');
return $instance;
}
/**
* {@inheritdoc}
*/
public function build() {
$instituteConfig = $this->configFactory->get(static::INSTITUTE_SETTINGS);
$build = [];
$build['#attributes']['class'] = ['check-class--arti_contacts'];
$build['content']['#theme'] = 'arti_contacts';
$build['content']['#address'] = $instituteConfig->get('address');
$build['content']['#email'] = $instituteConfig->get('email');
$build['content']['#global_tel'] = $instituteConfig->get('telephones.global');
$build['content']['#fax_tel'] = $instituteConfig->get('telephones.fax');
$build['#contextual_links']['arti'] = [
'route_parameters' => [],
];
$this->renderer->addCacheableDependency($build['content'], $instituteConfig);
return $build;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment