Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

make social bar URLs configurable #12

Open
wants to merge 2 commits into
base: 8.x-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/infinite_blocks/infinite_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function infinite_blocks_theme() {
'variables' => array(
'use_parent_container' => NULL,
'follow' => NULL,
'facebook_url' => NULL,
'instagram_url' => NULL,
'pinterest_url' => NULL,
'twitter_url' => NULL,
)
),
];
Expand Down
40 changes: 40 additions & 0 deletions modules/infinite_blocks/src/Plugin/Block/InfiniteSocialsBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
*/

class InfiniteSocialsBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'follow' => FALSE,
'facebook_url' => '',
'instagram_url' => '',
'pinterest_url' => '',
'twitter_url' => ''
];
}

/**
* {@inheritdoc}
Expand All @@ -30,6 +42,10 @@ public function build() {
return array(
'#theme' => 'socials_bar',
'#follow' => !empty($config['follow']) ? true : false,
'#facebook_url' => $config['facebook_url'],
'#instagram_url' => $config['instagram_url'],
'#pinterest_url' => $config['pinterest_url'],
'#twitter_url' => $config['twitter_url'],
'variables' => [],
);
}
Expand All @@ -44,6 +60,26 @@ public function blockForm($form, FormStateInterface $form_state) {
'#title' => $this->t('Link Attribute - Follow'),
'#default_value' => $config['follow'],
];
$form['facebook_url'] = [
'#type' => 'textfield',
'#title'=> $this->t('Facebook URL'),
'#default_value' => $config['facebook_url']
];
$form['instagram_url'] = [
'#type' => 'textfield',
'#title'=> $this->t('Instagram URL'),
'#default_value' => $config['instagram_url']
];
$form['pinterest_url'] = [
'#type' => 'textfield',
'#title'=> $this->t('Pinterest URL'),
'#default_value' => $config['pinterest_url']
];
$form['twitter_url'] = [
'#type' => 'textfield',
'#title'=> $this->t('Twitter URL'),
'#default_value' => $config['twitter_url']
];
return $form;
}

Expand All @@ -52,6 +88,10 @@ public function blockForm($form, FormStateInterface $form_state) {
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['follow'] = $form_state->getValue('follow');
$this->configuration['facebook_url'] = $form_state->getValue('facebook_url');
$this->configuration['instagram_url'] = $form_state->getValue('instagram_url');
$this->configuration['pinterest_url'] = $form_state->getValue('pinterest_url');
$this->configuration['twitter_url'] = $form_state->getValue('twitter_url');
}

}
24 changes: 16 additions & 8 deletions modules/infinite_blocks/templates/socials-bar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
{% set rel_follow = 'nofollow' %}
{% if follow %} {% set rel_follow = 'follow' %} {% endif %}

<a class="item-social icon-facebook" href="https://www.facebook.com/InStyleGermany" target="_blank"
data-social-type="facebook" rel="{{ rel_follow }}"></a>
<a class="item-social icon-instagram" href="https://instagram.com/InStyleGermany/" target="_blank"
data-social-type="instagram" rel="{{ rel_follow }}"></a>
<a class="item-social icon-pinterest" href="https://www.pinterest.com/instylegermany/" target="_blank"
data-social-type="pinterest" rel="{{ rel_follow }}"></a>
<a class="item-social icon-twitter" href="https://twitter.com/InStyleGermany" target="_blank"
data-social-type="twitter" rel="{{ rel_follow }}"></a>
{% if facebook_url %}
<a class="item-social icon-facebook" href="{{ facebook_url }}" target="_blank"
data-social-type="facebook" rel="{{ rel_follow }}"></a>
{% endif %}
{% if instagram_url %}
<a class="item-social icon-instagram" href="{{ instagram_url }}" target="_blank"
data-social-type="instagram" rel="{{ rel_follow }}"></a>
{% endif %}
{% if pinterest_url %}
<a class="item-social icon-pinterest" href="{{ pinterest_url }}" target="_blank"
data-social-type="pinterest" rel="{{ rel_follow }}"></a>
{% endif %}
{% if twitter_url %}
<a class="item-social icon-twitter" href="{{ twitter_url }}" target="_blank"
data-social-type="twitter" rel="{{ rel_follow }}"></a>
{% endif %}

<a class="item-social icon-email" href="/newsletter" data-social-type="email"></a>

Expand Down