You are here

public function FloatingSocialIconsBlock::build in Floating Social Icons 8

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/FloatingSocialIconsBlock.php, line 22

Class

FloatingSocialIconsBlock
Provides a 'Floating Social Icon' Block.

Namespace

Drupal\floating_social_icons\Plugin\Block

Code

public function build() {

  // Load the configuration from the form.
  $config = $this
    ->getConfiguration();
  $facebook = isset($config['facebook']) ? $config['facebook'] : '';
  $google_plus = isset($config['google_plus']) ? $config['google_plus'] : '';
  $linkedIn = isset($config['linkedIn']) ? $config['linkedIn'] : '';
  $twitter = isset($config['twitter']) ? $config['twitter'] : '';
  $pinterest = isset($config['pinterest']) ? $config['pinterest'] : '';
  $instagram = isset($config['instagram']) ? $config['instagram'] : '';
  $mail = isset($config['mail']) ? $config['mail'] : '';
  $youtube = isset($config['youtube']) ? $config['youtube'] : '';
  $icons = isset($config['place']) ? $config['place'] : '';
  $count = isset($config['count']) ? $config['count'] : '';
  $target = isset($config['target']) ? $config['target'] : '';
  $hover = isset($config['hover']) ? $config['hover'] : '';

  // Check title field for empty.
  $facebook_title = $config['facebook_title'] ?: 'Facebook';
  $google_plus_title = $config['google_plus_title'] ?: 'GooglePlus';
  $linkedIn_title = $config['linkedIn_title'] ?: 'LinkedIn';
  $twitter_title = $config['twitter_title'] ?: 'Twitter';
  $pinterest_title = $config['pinterest_title'] ?: 'Pinterest';
  $instagram_title = $config['instagram_title'] ?: 'Instagram';
  $mail_title = $config['mail_title'] ?: 'Mail';
  $youtube_title = $config['youtube_title'] ?: 'Youtube';
  $social_values = [
    'facebook' => $facebook,
    'google_plus' => $google_plus,
    'linkedIn' => $linkedIn,
    'twitter' => $twitter,
    'pinterest' => $pinterest,
    'instagram' => $instagram,
    'mail' => $mail,
    'youtube' => $youtube,
    'icons' => $icons,
    'count' => $count,
    'target' => $target,
    'hover' => $hover,
  ];
  $social_titles = [
    'facebook_title' => $facebook_title,
    'google_plus_title' => $google_plus_title,
    'linkedIn_title' => $linkedIn_title,
    'twitter_title' => $twitter_title,
    'pinterest_title' => $pinterest_title,
    'instagram_title' => $instagram_title,
    'youtube_title' => $youtube_title,
    'mail_title' => $mail_title,
  ];
  return [
    '#theme' => 'floating_social_icons_display',
    '#social_values' => $social_values,
    '#social_titles' => $social_titles,
    '#attached' => [
      'library' => [
        'floating_social_icons/floating_social_icons',
      ],
    ],
  ];
}