<?php

/**
 * Implements hook_init().
 */
function mkbh_social_share_init()
{
    $module_path = drupal_get_path('module', 'mkbh_social_share');

    sharethis_include_js();
    drupal_add_js($module_path . '/assets/js/mkbh-social-share.js');
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mkbh_social_share_form_sharethis_configuration_form_alter(&$form, &$form_state)
{
    foreach (element_children($form['options']) as $key) {
        hide($form['options'][$key]); // hide all "Display" configuration options
    }

    $form['options']['explanation'] = [
        '#markup' => t('Configuration has been disabled by "MKBH Social Share" module, because it will be handled programmatically.'),
    ];

    $form['context']['sharethis_location']['#default_value'] = 'block';
    $form['context']['sharethis_location']['#disabled'] = TRUE;
    $form['context']['sharethis_weight']['#disabled'] = TRUE;
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function mkbh_social_share_ctools_plugin_directory($owner, $plugin_type)
{
    if ($owner == 'ctools' && in_array($plugin_type, ['content_types'])) {
        return 'ctools/plugins/' . $plugin_type;
    }
}

/**
 * Implements hook_theme().
 */
function mkbh_social_share_theme($existing, $type, $theme, $path)
{
    return [
        'mkbh_social_share_share_widget' => [
            'variables' => ['node' => NULL],
            'file' => 'mkbh_social_share.theme.inc',
            'template' => 'templates/mkbh-social-share-share-widget',
        ],
    ];
}
