class FloatingSocialIconsBlock in Floating Social Icons 8
Provides a 'Floating Social Icon' Block.
Plugin annotation
@Block(
id = "floating_icons",
admin_label = @Translation("Floating Social Block"),
category = @Translation("social icon"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait
- class \Drupal\floating_social_icons\Plugin\Block\FloatingSocialIconsBlock
- class \Drupal\Core\Block\BlockBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewFallbackInterface uses BlockPluginTrait, ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
Expanded class hierarchy of FloatingSocialIconsBlock
File
- src/
Plugin/ Block/ FloatingSocialIconsBlock.php, line 17
Namespace
Drupal\floating_social_icons\Plugin\BlockView source
class FloatingSocialIconsBlock extends BlockBase {
/**
* {@inheritdoc}
*/
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',
],
],
];
}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
// Facebook details.
$form['floating_facebook'] = [
'#type' => 'details',
'#title' => $this
->t('Facebook settings'),
'#collapsible' => TRUE,
'#open' => TRUE,
'#description' => '',
];
$form['floating_facebook']['facebook_link'] = [
'#type' => 'url',
'#title' => $this
->t('Facebook Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['facebook']) ? $this->configuration['facebook'] : '',
];
$form['floating_facebook']['facebook_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Facebook title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['facebook_title']) ? $this->configuration['facebook_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// Twitter details.
$form['floating_twitter'] = [
'#type' => 'details',
'#title' => $this
->t('Twitter settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => '',
];
$form['floating_twitter']['twitter_link'] = [
'#type' => 'url',
'#title' => $this
->t('Twitter Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['twitter']) ? $this->configuration['twitter'] : '',
];
$form['floating_twitter']['twitter_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Twitter title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['twitter_title']) ? $this->configuration['twitter_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// Google Plus details.
$form['floating_google_plus'] = [
'#type' => 'details',
'#title' => $this
->t('Google Plus settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => '',
];
$form['floating_google_plus']['google_plus_link'] = [
'#type' => 'url',
'#title' => $this
->t('Google Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['google_plus']) ? $this->configuration['google_plus'] : '',
];
$form['floating_google_plus']['google_plus_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('GooglePlus title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['google_plus_title']) ? $this->configuration['google_plus_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// LinkedIn details.
$form['floating_linkedIn'] = [
'#type' => 'details',
'#title' => $this
->t('LinkedIn settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => '',
];
$form['floating_linkedIn']['linkedIn_link'] = [
'#type' => 'url',
'#title' => $this
->t('LinkedIn Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['linkedIn']) ? $this->configuration['linkedIn'] : '',
];
$form['floating_linkedIn']['linkedIn_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('LinkedIn title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['linkedIn_title']) ? $this->configuration['linkedIn_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// Pinterest details.
$form['floating_pinterest'] = [
'#type' => 'details',
'#title' => $this
->t('Pinterest settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => '',
];
$form['floating_pinterest']['pinterest_link'] = [
'#type' => 'url',
'#title' => $this
->t('Pinterest Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['pinterest']) ? $this->configuration['pinterest'] : '',
];
$form['floating_pinterest']['pinterest_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Pinterest title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['pinterest_title']) ? $this->configuration['pinterest_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// Instagram details.
$form['floating_instagram'] = [
'#type' => 'details',
'#title' => $this
->t('Instagram settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => '',
];
$form['floating_instagram']['instagram_link'] = [
'#type' => 'url',
'#title' => $this
->t('Instagram Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['instagram']) ? $this->configuration['instagram'] : '',
];
$form['floating_instagram']['instagram_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Instagram title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['instagram_title']) ? $this->configuration['instagram_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// YouTube details.
$form['floating_youtube'] = [
'#type' => 'details',
'#title' => $this
->t('Youtube settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => '',
];
$form['floating_youtube']['youtube_link'] = [
'#type' => 'url',
'#title' => $this
->t('Youtube Link'),
'#size' => 60,
'#default_value' => isset($this->configuration['youtube']) ? $this->configuration['youtube'] : '',
];
$form['floating_youtube']['youtube_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Youtube title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['youtube_title']) ? $this->configuration['youtube_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// Mail details.
$form['floating_mail'] = [
'#type' => 'details',
'#title' => $this
->t('mail settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => '',
];
$form['floating_mail']['mail_link'] = [
'#type' => 'email',
'#title' => $this
->t('Mail Link'),
'#size' => 60,
'#description' => $this
->t('Please type only the e-mail id'),
'#default_value' => isset($this->configuration['mail']) ? $this->configuration['mail'] : '',
];
$form['floating_mail']['mail_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Mail title'),
'#description' => $this
->t('Text to display when in active or hover state'),
'#default_value' => isset($this->configuration['mail_title']) ? $this->configuration['mail_title'] : '',
'#size' => 60,
'#maxlength' => 128,
];
// Block details.
$form['floating_icons'] = [
'#type' => 'details',
'#title' => $this
->t('Display Icons'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => '',
];
$form['floating_icons']['hover'] = [
'#type' => 'radios',
'#title' => $this
->t('Select the Hover Effects'),
'#required' => TRUE,
'#attributes' => array(
'class' => array(
'floating-block',
),
),
'#default_value' => isset($this->configuration['hover']) ? $this->configuration['hover'] : 'grow',
'#options' => [
'grow' => $this
->t('Grow'),
'shrink' => $this
->t('Shrink'),
'black-white' => $this
->t('Black and white'),
'white-black' => $this
->t('White and black'),
'rotate' => $this
->t('Rotate 360'),
],
];
$form['floating_icons']['place'] = [
'#type' => 'radios',
'#title' => $this
->t('Where do you want to display the icons?'),
'#required' => TRUE,
'#default_value' => isset($this->configuration['place']) ? $this->configuration['place'] : 4,
'#options' => [
1 => $this
->t('Top'),
2 => $this
->t('Right'),
3 => $this
->t('Bottom'),
4 => $this
->t('Left'),
],
];
$form['floating_icons']['target'] = [
'#type' => 'select',
'#title' => $this
->t('Target Attribute'),
'#default_value' => isset($this->configuration['target']) ? $this->configuration['target'] : '_self',
'#options' => [
'_self' => $this
->t('_Self'),
'_blank' => $this
->t('_Blank'),
],
];
$form['floating_icons']['count'] = [
'#title' => $this
->t('Count'),
'#value' => isset($this->configuration['count']) ? $this->configuration['count'] : 0,
'#type' => 'hidden',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function blockValidate($form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$links = [];
$links[] = $values['floating_facebook']['facebook_link'];
$links[] = $values['floating_twitter']['twitter_link'];
$links[] = $values['floating_google_plus']['google_plus_link'];
$links[] = $values['floating_linkedIn']['linkedIn_link'];
$links[] = $values['floating_pinterest']['pinterest_link'];
$links[] = $values['floating_instagram']['instagram_link'];
$links[] = $values['floating_mail']['mail_link'];
$links[] = $values['floating_youtube']['youtube_link'];
$count = 0;
if ($links) {
foreach ($links as $link) {
if (!empty($link)) {
$count = $count + 1;
}
}
}
if ($count < 2) {
$form_state
->setErrorByName('floatingsocialblock', $this
->t('At least two fields should be filled.'));
}
// Setting count value.
$this->configuration['count'] = $count;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
$values = $form_state
->getValues();
$this->configuration['facebook'] = $values['floating_facebook']['facebook_link'];
$this->configuration['google_plus'] = $values['floating_google_plus']['google_plus_link'];
$this->configuration['linkedIn'] = $values['floating_linkedIn']['linkedIn_link'];
$this->configuration['twitter'] = $values['floating_twitter']['twitter_link'];
$this->configuration['pinterest'] = $values['floating_pinterest']['pinterest_link'];
$this->configuration['instagram'] = $values['floating_instagram']['instagram_link'];
$this->configuration['mail'] = $values['floating_mail']['mail_link'];
$this->configuration['youtube'] = $values['floating_youtube']['youtube_link'];
$this->configuration['place'] = $values['floating_icons']['place'];
$this->configuration['target'] = $values['floating_icons']['target'];
$this->configuration['hover'] = $values['floating_icons']['hover'];
// Setting Config for Titles.
$this->configuration['facebook_title'] = $values['floating_facebook']['facebook_title'];
$this->configuration['google_plus_title'] = $values['floating_google_plus']['google_plus_title'];
$this->configuration['linkedIn_title'] = $values['floating_linkedIn']['linkedIn_title'];
$this->configuration['twitter_title'] = $values['floating_twitter']['twitter_title'];
$this->configuration['pinterest_title'] = $values['floating_pinterest']['pinterest_title'];
$this->configuration['instagram_title'] = $values['floating_instagram']['instagram_title'];
$this->configuration['mail_title'] = $values['floating_mail']['mail_title'];
$this->configuration['youtube_title'] = $values['floating_youtube']['youtube_title'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockPluginInterface:: |
constant | Indicates the block label (title) should be displayed to end users. | ||
BlockPluginTrait:: |
protected | property | The transliteration service. | |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
protected | function | Returns generic default configuration for block plugins. | |
BlockPluginTrait:: |
protected | function | Indicates whether the block should be shown. | 16 |
BlockPluginTrait:: |
public | function | Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements. | 2 |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | 19 | |
BlockPluginTrait:: |
public | function | 1 | |
BlockPluginTrait:: |
public | function | 1 | |
BlockPluginTrait:: |
public | function | 3 | |
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | ||
BlockPluginTrait:: |
public | function | Sets the transliteration service. | |
BlockPluginTrait:: |
public | function | Most block plugins should not override this method. To add submission handling for a specific block type, override BlockBase::blockSubmit(). | |
BlockPluginTrait:: |
protected | function | Wraps the transliteration service. | |
BlockPluginTrait:: |
public | function | Most block plugins should not override this method. To add validation for a specific block type, override BlockBase::blockValidate(). | 1 |
BlockPluginTrait:: |
public | function | 22 | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Builds a form element for assigning a context to a given slot. | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginBase:: |
protected | property | The data objects representing the context of this plugin. | |
ContextAwarePluginBase:: |
private | property | Data objects representing the contexts passed in the plugin configuration. | |
ContextAwarePluginBase:: |
protected | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
9 |
ContextAwarePluginBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
7 |
ContextAwarePluginBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
4 |
ContextAwarePluginBase:: |
public | function |
This code is identical to the Component in order to pick up a different
Context class. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Gets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the value for a defined context. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the values for all defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Set a context on this plugin. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Sets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Sets the value for a defined context. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Validates the set values for the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function | Implements magic __get() method. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FloatingSocialIconsBlock:: |
public | function |
Overrides BlockPluginTrait:: |
|
FloatingSocialIconsBlock:: |
public | function |
Overrides BlockPluginTrait:: |
|
FloatingSocialIconsBlock:: |
public | function |
Overrides BlockPluginTrait:: |
|
FloatingSocialIconsBlock:: |
public | function |
Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginWithFormsTrait:: |
public | function | ||
PluginWithFormsTrait:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |