You are here

linkit_picker.module in Linkit Picker 7.3

Same filename and directory in other branches
  1. 6 linkit_picker.module
  2. 7 linkit_picker.module
  3. 7.2 linkit_picker.module

Main file for linkit_pikcer module.

File

linkit_picker.module
View source
<?php

/**
 * @file
 * Main file for linkit_pikcer module.
 */

/**
 * Implements hook_menu().
 */
function linkit_picker_menu() {
  $items = array();

  // Linkit picker configuration page
  $items['admin/config/content/linkit_picker'] = array(
    'title' => 'Linkit picker',
    'description' => 'Linkit picker configuration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'linkit_picker_config_form',
    ),
    'access arguments' => array(
      'edit linkit picker settings',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'linkit_picker.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function linkit_picker_permission() {
  return array(
    'edit linkit picker settings' => array(
      'title' => t('Edit linkit picker settings'),
    ),
  );
}

/**
 * Implements hook_form_alter().
 */
function linkit_picker_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "linkit_dashboard_form") {
    if (isset($form['#suffix'])) {
      $form['#suffix'] .= linkit_picker_dashboard_filter();
    }
    else {
      $form['#suffix'] = linkit_picker_dashboard_filter();
    }
  }
}
function linkit_picker_dashboard_filter() {
  $profile = linkit_get_active_profile();
  if (!$profile) {
    return '';
  }
  return _linkit_picker_render_container(linkit_picker_get_profile_views($profile->name));
}

/**
 * Return all the views that should be used in the container.
 */
function _linkit_picker_render_container($views) {
  $container = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'linkit-picker-container',
      ),
      'id' => 'linkit-picker-container',
    ),
  );
  drupal_add_css(drupal_get_path('module', 'linkit_picker') . '/linkit_picker.css');
  drupal_add_js(drupal_get_path('module', 'linkit_picker') . '/linkit_picker.js');
  foreach ($views as $viewname) {
    $view = _linkit_picker_get_view($viewname);
    if (empty($view)) {
      continue;
    }
    $container['browser_wrapper'][$viewname] = array(
      '#type' => 'link',
      '#href' => '',
      '#title' => $view
        ->get_title(),
      '#attributes' => array(
        'class' => array(
          'linkit-picker-button',
        ),
        'data-viewname' => $viewname,
      ),
    );
    $container[$viewname] = array(
      '#type' => 'container',
      '#attributes' => array(
        'class' => array(
          'view-container',
          'view-linkit-picker-' . $viewname,
        ),
      ),
    );
    $container[$viewname]['view'] = array(
      '#markup' => $view
        ->preview('default'),
    );
  }
  return drupal_render($container);
}

/**
 * Implements hook_views_api().
 */
function linkit_picker_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'linkit_picker') . '/includes',
  );
}

/**
 *
 * Get a view if the current user has access to it
 */
function _linkit_picker_get_view($viewname) {
  $view = views_get_view($viewname);
  if ($view && $view
    ->access('default')) {
    return $view;
  }
  else {
    return NULL;
  }
}

/**
 *
 * Return all enabled views per profile
 * @param string $profile_name
 */
function linkit_picker_get_profile_views($profile_name) {
  $linkit_picker_views = variable_get('linkit_picker_views', array());
  if (empty($linkit_picker_views)) {
    return array(
      'linkit_picker_node',
    );
  }
  if (isset($linkit_picker_views[$profile_name]) && linkit_profile_load($profile_name)) {
    return $linkit_picker_views[$profile_name]['views'];
  }
  else {
    return array();
  }
}

/**
 *
 * Set the active profile if it's not set.
 */
function _linkit_picker_set_active_profile() {
  if (!linkit_get_active_profile()) {
    $profile = linkit_profile_load(arg(2));
    if ($profile) {
      linkit_set_active_profile($profile);
    }
  }
}
function _linkit_picker_get_insert_plugin_processed_path($path) {
  $profile = linkit_get_active_profile();
  if ($profile) {
    return linkit_get_insert_plugin_processed_path(linkit_get_active_profile(), $path);
  }
  else {
    return $path;
  }
}

Functions

Namesort descending Description
linkit_picker_dashboard_filter
linkit_picker_form_alter Implements hook_form_alter().
linkit_picker_get_profile_views Return all enabled views per profile
linkit_picker_menu Implements hook_menu().
linkit_picker_permission Implements hook_permission().
linkit_picker_views_api Implements hook_views_api().
_linkit_picker_get_insert_plugin_processed_path
_linkit_picker_get_view Get a view if the current user has access to it
_linkit_picker_render_container Return all the views that should be used in the container.
_linkit_picker_set_active_profile Set the active profile if it's not set.