You are here

linkit_picker.module in Linkit Picker 7.2

Same filename and directory in other branches
  1. 6 linkit_picker.module
  2. 7.3 linkit_picker.module
  3. 7 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_form_alter().
 */
function linkit_picker_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "linkit_dashboard_form") {
    $profile = linkit_get_dashboard_profile();
    $form['link']['link']['#field_suffix'] = '<input type="submit" id="linkit-imce" name="linkit-imce" value="Choose File ..." class="form-submit" />';
    $form['link']['attributes']['#weight'] = 3;
    $form['link']['browser_wrapper'] = array(
      '#type' => 'fieldset',
      '#title' => t('Select From List'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => 2,
      '#attributes' => array(
        'class' => array(
          'linkit_picker',
        ),
      ),
    );
    $views = array();
    if (isset($profile->data['plugins']['entity:node']['enabled']) && $profile->data['plugins']['entity:node']['enabled']) {
      $views[] = 'linkit_picker_node';
      $form['link']['browser_wrapper']['node'] = array(
        '#type' => 'button',
        '#value' => t('Node'),
        '#weight' => 0,
        '#attributes' => array(
          'class' => array(
            'linkit_picker_button',
          ),
        ),
      );
    }
    if (isset($profile->data['plugins']['entity:user']['enabled']) && $profile->data['plugins']['entity:user']['enabled']) {
      $views[] = 'linkit_picker_user';
      $form['link']['browser_wrapper']['user'] = array(
        '#type' => 'button',
        '#value' => t('User'),
        '#weight' => 1,
        '#attributes' => array(
          'class' => array(
            'linkit_picker_button',
          ),
        ),
      );
    }
    if (isset($profile->data['plugins']['entity:taxonomy_term']['enabled']) && $profile->data['plugins']['entity:taxonomy_term']['enabled']) {
      $views[] = 'linkit_picker_term';
      $form['link']['browser_wrapper']['term'] = array(
        '#type' => 'button',
        '#value' => t('Term'),
        '#weight' => 2,
        '#attributes' => array(
          'class' => array(
            'linkit_picker_button',
          ),
        ),
      );
    }
    $form['link']['browser_wrapper']['container'] = array(
      '#prefix' => '<div id="linkit-picker-container">',
      '#suffix' => '</div>',
      '#markup' => _linkit_picker_render_container($views),
      '#weight' => 10,
    );
  }
  if (strstr($form_id, "_node_form")) {
    $form['#attached']['css'][] = drupal_get_path('module', 'linkit_picker') . '/linkit_picker.css';
    $form['#attached']['js'][] = drupal_get_path('module', 'linkit_picker') . '/linkit_picker.js';
  }
}

/**
 * Return all the views that should be used in the container.
 */
function _linkit_picker_render_container($views) {
  $form_value = "";
  foreach ($views as $view) {
    $form_value .= _linkit_picker_get_views($view);
  }
  return $form_value;
}

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

/**
 * Helper function returns view by view name.
 */
function _linkit_picker_get_views($viewname) {
  $output = '';
  $view = views_get_view($viewname);
  if ($view && $view
    ->access('default')) {
    $output .= '<div class="view-container">';
    $output .= $view
      ->get_title();
    $output .= $view
      ->preview('default');
    $output .= '</div>';
  }
  return $output;
}

Functions

Namesort descending Description
linkit_picker_form_alter Implements hook_form_alter().
linkit_picker_views_api Implements hook_views_api().
_linkit_picker_get_views Helper function returns view by view name.
_linkit_picker_render_container Return all the views that should be used in the container.