Created
May 25, 2018 02:47
-
-
Save jmolivas/8fe67b6e8cb25574b6382f48fb658e94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function name_theme_preprocess_page() { | |
// ... | |
$variables['social_networks'] = theme_get_setting('social_networks', 'name_theme'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for name, social_network in social_networks %} | |
<p>{{ name }}: <br/> | |
{{ social_network.url }} | |
</p> | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function name_theme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) | |
{ | |
// ... | |
$socialNetworks = theme_get_setting('social_networks', 'name_theme'); | |
if (!$socialNetworks) { | |
$socialNetworks = [ | |
'facebook' => ['url'=>''], | |
'twitter' => ['url'=>''], | |
'instagram' => ['url'=>''], | |
'youtube' => ['url'=>''], | |
'glassdoor' => ['url'=>''] | |
]; | |
} | |
$socialNetworkForm['social_networks'] = [ | |
'#type' => 'table', | |
'#id' => 'draggable-table', | |
'#caption' => t('Social Networks.'), | |
'#header' => [ | |
t('Url'), | |
], | |
'#tabledrag' => [ | |
[ | |
'table_id' => 'draggable-table', | |
'action' => 'order', | |
'relationship' => 'sibling', | |
'group' => 'table-order-weight', | |
], | |
], | |
]; | |
foreach ($socialNetworks as $name => $socialNetwork) { | |
$title = ucfirst(t($name)); | |
$url = isset($socialNetwork['url'])?$socialNetwork['url']:''; | |
$socialNetworkForm['social_networks'][$name] = [ | |
'#attributes' => ['class' => ['draggable']], | |
'url' => [ | |
'#type' => 'url', | |
'#title' => $title, | |
'#default_value' => $url, | |
'#description' => t("Please provide link of $title"), | |
], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment