Merge branch 'field_modules' into 7.x-1.x
See related discussion in the farmOS-client project: https://github.com/farmOS/farmOS-client/issues/217
This commit is contained in:
commit
04d5280a14
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by farm_client.
|
||||
*
|
||||
* This file contains no working PHP code; it exists to provide additional
|
||||
* documentation for doxygen as well as to document hooks in the standard
|
||||
* Drupal manner.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup farm_client Farm client module integrations.
|
||||
*
|
||||
* Module integrations with the farm_client module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup farm_client_hooks Farm client's hooks
|
||||
* @{
|
||||
* Hooks that can be implemented by other modules in order to extend farm_client.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provide information about client modules that this module provides.
|
||||
*
|
||||
* @return array
|
||||
* Returns an array of client module information.
|
||||
*/
|
||||
function hook_farm_client_module_info() {
|
||||
return array(
|
||||
'weather' => array(
|
||||
'name' => 'weather',
|
||||
'label' => t('Weather'),
|
||||
'js' => drupal_get_path('module', 'farm_weather') . '/src/FieldModule/Weather/weather.js',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -2,4 +2,5 @@ name = Farm Client
|
|||
description = Integrates the farmOS server and client.
|
||||
core = 7.x
|
||||
package = farmOS
|
||||
dependencies[] = farm_access
|
||||
dependencies[] = farm_api
|
||||
|
|
|
@ -19,3 +19,78 @@ function farm_client_farm_api_oauth2_client() {
|
|||
|
||||
return $clients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function farm_client_menu() {
|
||||
$items = array();
|
||||
|
||||
// Serve client JavaScript files.
|
||||
$items['farm/client/js/%/index.js'] = array(
|
||||
'title' => 'Deliver client module JS',
|
||||
'page callback' => 'farm_client_js_deliver',
|
||||
'page arguments' => array(3),
|
||||
'access callback' => TRUE,
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_farm_info().
|
||||
*/
|
||||
function farm_client_farm_info() {
|
||||
|
||||
// Ask modules for client module info.
|
||||
$client_modules = module_invoke_all('farm_client_module_info');
|
||||
|
||||
// Replace the JavaScript file path with the one that is served by Drupal.
|
||||
foreach ($client_modules as $name => &$client_module) {
|
||||
if (!empty($client_module['js'])) {
|
||||
$client_module['js'] = 'farm/client/js/' . $name . '/index.js';
|
||||
}
|
||||
}
|
||||
|
||||
// Add the client module info to /farm.json.
|
||||
$info = array();
|
||||
if (!empty($client_modules)) {
|
||||
$info['client'] = array(
|
||||
'modules' => $client_modules,
|
||||
);
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback for delivering client JS.
|
||||
*
|
||||
* This will load the JavaScript file for a client module and output the content
|
||||
* as if it were being loaded directly from the web server. This allows the
|
||||
* response to include receive the Access-Control-Allow-Origin and other headers
|
||||
* added by farm_access_init().
|
||||
*
|
||||
* @param string $module
|
||||
* The machine name of the client module.
|
||||
*
|
||||
* @return NULL|int
|
||||
* This function will print the contents of the JavaScript file, if found, and
|
||||
* will not return anything. Otherwise, it will return MENU_NOT_FOUND.
|
||||
*/
|
||||
function farm_client_js_deliver($module) {
|
||||
|
||||
// Ask modules for client module info.
|
||||
$client_modules = module_invoke_all('farm_client_module_info');
|
||||
|
||||
// If the requested module doesn't exist, or if it doesn't provide JS, bail
|
||||
// with a 404.
|
||||
if (!(array_key_exists($module, $client_modules) && !empty($client_modules[$module]['js']) && file_exists($client_modules[$module]['js']))) {
|
||||
return MENU_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Print the contents of the Javascript file and exit.
|
||||
drupal_add_http_header('Content-Type', 'application/javascript; utf-8');
|
||||
print file_get_contents($client_modules[$module]['js']);
|
||||
drupal_exit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue