easy_social-8.x-3.x-dev/contrib/easy_social_example/easy_social_example.module
contrib/easy_social_example/easy_social_example.module
<?php /** * @file * Easy Social Example module. */ use Drupal\Core\Url; use Drupal\Core\Link; /** * Implements hook_easy_social_widget(). */ function easy_social_example_easy_social_widget() { $widgets = []; // The key is going to be the widget's machine_name. $widgets['example'] = [ 'name' => t('Example'), // If we wanted to add some additional css or js for our widet, we can do // so here. Refer to easy_social.api.php for more information on how to // implement hook_easy_social_widget(). // 'js' => [], // 'css' => [], ]; return $widgets; } /** * Implements hook_theme(). */ function easy_social_example_theme() { $return = []; // The theme function should be named "easy_social_$WIDGET", where $WIDGET is // the widget's machine_name. $return['easy_social_example'] = [ 'variables' => [], ]; return $return; } /** * Implements hook_preprocess_HOOK() for easy_social_example theme. * * @see easy_social_theme() * @see theme_easy_social_example() */ function easy_social_example_preprocess_easy_social_example(&$variables) { // You can still pre-process this as usual. // Notice that the config settings have been automatically added. $options = []; $options['attributes']['class'] = [ 'class' => 'example-share-button', ]; $url = Url::fromUri('http://www.example.com/share', $options); $example_share_link = Link::fromTextAndUrl(t('Example share'), $url); $variables['example_share_link'] = $example_share_link; } /** * Implements hook_process_HOOK() for easy_social_example theme. * * @see easy_social_theme() * @see theme_easy_social_example() */ function easy_social_example_process_easy_social_example(&$variables) { // You can still process this as usual. }