Skip to content

Instantly share code, notes, and snippets.

@edutrul
Created November 23, 2016 19:15
Show Gist options
  • Save edutrul/42d5b5d483fcd6773d45088fd916dd72 to your computer and use it in GitHub Desktop.
Save edutrul/42d5b5d483fcd6773d45088fd916dd72 to your computer and use it in GitHub Desktop.
Social links (@todo FB SHARE and Linkedin)
<?php
/**
* @file
* dies_event hooks.
*/
/**
* Implements hook_theme().
*/
function dies_event_theme() {
return array(
'dies_event_social_links' => array(
'render element' => 'elements',
'template' => 'dies-event-social-links',
'variables' => array(
'full_url' => NULL,
'node_title' => NULL,
),
),
);
}
<?php
namespace Drupal\dies_event\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* @file
* Render Social links.
*/
/**
* Provides a 'SocialBlock' block.
*
* @Block(
* id = "social_block",
* admin_label = @Translation("Social block"),
* context = {
* "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
* }
* )
*/
class SocialBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
global $base_url;
$node = $this->getContextValue('node');
$build = [];
$build['social_block'] = array(
'#theme' => 'dies_event_social_links',
'#full_url' => $base_url . $node->url(),
'#node_title' => $node->getTitle(),
);
return $build;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment