Skip to content

Instantly share code, notes, and snippets.

@jmolivas
Created May 25, 2018 02:47
Show Gist options
  • Save jmolivas/8fe67b6e8cb25574b6382f48fb658e94 to your computer and use it in GitHub Desktop.
Save jmolivas/8fe67b6e8cb25574b6382f48fb658e94 to your computer and use it in GitHub Desktop.
<?php
function name_theme_preprocess_page() {
// ...
$variables['social_networks'] = theme_get_setting('social_networks', 'name_theme');
}
{% for name, social_network in social_networks %}
<p>{{ name }}: <br/>
{{ social_network.url }}
</p>
{% endfor %}
<?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