function initialize() { $services = ['facebook' => ['name' => 'Facebook', 'icon' => 'fa-facebook-square'], 'twitter' => ['name' => 'Twitter', 'icon' => 'fa-twitter-square'], 'youtube' => ['name' => 'Youtube', 'icon' => 'fa-youtube-play'], 'instagram' => ['name' => 'Instagram', 'icon' => 'fa-instagram']]; $serviceOptions = []; foreach ($services as $key => $service) { $serviceOptions[$key] = $service['name']; } $social = Core\getSocialData(); $accountOptions = []; if (!empty($social)) { $this->settings += ['restrict_accounts' => ['#type' => 'checkbox', '#title' => 'Limit visible social accounts?', '#description' => 'Limit visible social accounts?', '#return_value' => '1', '#label_above' => true, '#replace_title' => 'Yes', '#default_value' => false]]; foreach ($social as $value) { $account = Core\extractSocialData($value); $accountOptions[$value] = $account['account'] . sprintf(' (<a href="%s" target="_blank">%s</a>)', $account['url'], $account['service']); } } $this->settings += ['accounts' => ['#type' => 'radios', '#title' => 'Social accounts', '#default_value' => 'all', '#options' => ['all' => 'All (city-wide)', 'custom' => 'Specific accounts']], 'custom' => ['#title' => 'Accounts to display', '#type' => 'checkboxes', '#options' => $accountOptions, '#default_value' => array_keys($accountOptions), '#description' => 'Choose the social acounts that should display', '#to_js_settings' => true, '#states' => ['visible' => ['accounts' => ['operator' => '==', 'value' => ['custom'], 'glue' => '||']]]], 'services' => ['#type' => 'checkboxes', '#title' => 'Services', '#default_value' => array_keys($serviceOptions), '#description' => 'What social services should appear?', '#options' => $serviceOptions, '#to_js_settings' => true, '#states' => ['hidden' => ['accounts' => ['operator' => '==', 'value' => ['custom'], 'glue' => '||']]]], 'hide_controls' => ['#type' => 'checkbox', '#title' => 'Hide Controls?', '#description' => 'Hide the service switcher toolbar?.', '#return_value' => '1', '#label_above' => true, '#replace_title' => 'Yes', '#default_value' => false, '#to_js_settings' => true], 'widget_type' => ['#type' => 'radios', '#title' => 'Widget type', '#description' => 'Choose between a static feed, animated social wall, and a timeline.', '#default_value' => 'static', '#options' => ['static' => 'Feed', 'wall' => 'Social wall', 'timeline' => 'Timeline']], 'post_count' => ['#type' => 'text', '#title' => 'Count', '#description' => 'How many items to show', '#default_value' => '20']]; }
/** * Determines if content empty, show widget, title ect? * * @see self::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function hasContent($args, &$instance) { $social = []; if (!empty($instance['restrict_accounts']) && !empty($instance['social_accounts'])) { $social = $instance['social_accounts']; } else { $social = Core\getSocialData(); // needs array( MEANINGFUL => ) $social = array_combine($social, $social); } // We have values, go ahead if (!empty($social)) { foreach ($social as $key => $value) { if ($value) { $instance['social_accounts'][$key] = Core\extractSocialData($value); } } return true; } return false; }