You are here

entity_share_ui_client.module in Entity Share 7

Entity Share UI Client .module file.

File

modules/entity_share_ui/modules/entity_share_ui_client/entity_share_ui_client.module
View source
<?php

/**
 * @file
 * Entity Share UI Client .module file.
 */

// Include sharing admin functions.
include_once 'entity_share_ui_client.share.admin.inc';

// Include config functions.
include_once 'entity_share_ui_client.config.admin.inc';

/**
 * Implements hook_help().
 */
function entity_share_ui_client_help($path, $arg) {
  switch ($path) {
    case 'admin/help#entity_share_ui_client':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Entity Share UI Client module allows to configure the sharing of contents across different Drupal instances.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_permission().
 */
function entity_share_ui_client_permission() {
  return array(
    'access share contents' => array(
      'title' => t('Access EntityShare'),
      'description' => t('Allows a user to share contents.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function entity_share_ui_client_menu() {
  $items = array();
  $items['admin/config/entity_share/client'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => 'Entity Share Client',
    'description' => 'Configure the endpoints',
    'page callback' => 'entity_share_ui_endpoint_list',
    'access arguments' => array(
      'administer entityshare',
    ),
  );

  // Add a tab for future evolutions.
  $items['admin/config/entity_share/client/endpoint'] = array(
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'title' => 'Endpoints',
  );

  // Endpoints management.
  $items['admin/entity_share/endpoint/%/edit'] = array(
    'page callback' => 'drupal_get_form',
    // 3 for 3rd indice of the path.
    'page arguments' => array(
      'entity_share_ui_endpoint_edit_form',
      3,
    ),
    'access arguments' => array(
      'administer entityshare',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/entity_share/endpoint/add'] = array(
    'title' => 'Add an Endpoint',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'entity_share_ui_endpoint_edit_form',
    ),
    'access arguments' => array(
      'administer entityshare',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/entity_share/endpoint/%/delete'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'entity_share_ui_endpoint_delete_form',
      3,
    ),
    'access arguments' => array(
      'administer entityshare',
    ),
    'type' => MENU_CALLBACK,
  );

  // Technical page for form action.
  $items['admin/content/entity_share'] = array(
    'page callback' => 'entity_share_ui_share_page',
    'page arguments' => array(),
    'access arguments' => array(
      'access share contents',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function entity_share_ui_client_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if ($root_path == 'admin/config/entity_share/client') {
    $item = menu_get_item('admin/entity_share/endpoint/add');
    if ($item['access']) {
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
    }
  }
}

/**
 * Implements hook_node_operations().
 *
 * For the standard content view.
 */
function entity_share_ui_client_node_operations() {
  $operations = array();
  if (user_access('access share contents')) {
    $operations['entity_share:share'] = array(
      'label' => t('Share contents'),
      'callback' => 'entity_share_ui_share_action',
      'callback arguments' => array(),
    );
  }
  return $operations;
}

/**
 * Implements hook_action_info().
 *
 * For modules like admin_views.
 */
function entity_share_ui_client_action_info() {
  return array(
    'entity_share_ui_share_action' => array(
      'type' => 'node',
      'label' => t('Share contents'),
      'configurable' => FALSE,
      'triggers' => array(
        'any',
      ),
      'aggregate' => TRUE,
    ),
  );
}

/**
 * Implements hook_views_default_views_alter().
 *
 * Alter admin_views_node to add the entity share action.
 */
function entity_share_ui_client_views_default_views_alter(&$views) {
  if (isset($views['admin_views_node'])) {

    // Add entity share action to the "Content" view.
    $actions_list = array_keys(actions_list());
    if (in_array('entity_share_ui_share_action', $actions_list)) {
      $handler = $views['admin_views_node']->display['default']->handler;
      if (isset($handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'])) {
        $handler->display->display_options['fields']['views_bulk_operations']['vbo_operations']['action::entity_share_ui_share_action'] = array(
          'selected' => 1,
          'postpone_processing' => 0,
          'skip_confirmation' => 1,
          'override_label' => 0,
          'label' => '',
          'settings' => array(),
        );
      }
    }
  }
}

/**
 * Implements hook_theme().
 *
 * Defines the theming capabilities provided by this module.
 */
function entity_share_ui_client_theme() {
  return array(
    'entity_share_form_choose_endpoint_page' => array(
      'template' => 'templates/entity-share-form-choose-endpoint-page',
      'variables' => array(
        'nodes_table' => NULL,
        'form' => NULL,
      ),
    ),
  );
}