Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
L
libraries
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
libraries
Commits
c365e82b
Commit
c365e82b
authored
Oct 09, 2010
by
Tobias Stoeckler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#919632
by tstoeckler: Add example library info file for testing purposes.
parent
0b9ee13e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
14 deletions
+119
-14
CHANGELOG.txt
CHANGELOG.txt
+1
-0
libraries.api.php
libraries.api.php
+23
-0
libraries.module
libraries.module
+65
-14
tests/example/example.info
tests/example/example.info
+7
-0
tests/libraries.test
tests/libraries.test
+16
-0
tests/libraries_test.module
tests/libraries_test.module
+7
-0
No files found.
CHANGELOG.txt
View file @
c365e82b
...
...
@@ -6,6 +6,7 @@ Libraries x.x-x.x, xxxx-xx-xx
Libraries 7.x-1.x, xxxx-xx-xx
-----------------------------
#919632 by tstoeckler: Add example library info file for testing purposes.
#719896 by tstoeckler, sun: Documentation clean-up and tests improvement.
#542940 by sun: Added initial Drush integration file.
#719896 by tstoeckler, sun: Improved library detection and library loading.
...
...
libraries.api.php
View file @
c365e82b
...
...
@@ -330,3 +330,26 @@ function hook_libraries_info_alter(&$libraries) {
);
$libraries
[
'php_spellchecker'
][
'integration files'
][
'example_module'
]
=
$files
;
}
/**
* Specify paths to look for library info files.
*
* Libraries API looks in the following directories for library info files by
* default:
* - libraries
* - profiles/$profile/libraries
* - sites/all/libraries
* - sites/$site/libraries
* This hook allows you to specify additional locations to look for library info
* files. This should only be used for modules that declare many libraries.
* Modules that only implement a few libraries should implement
* hook_libraries_info().
*
* @return
* An array of paths.
*/
function
hook_libraries_paths
()
{
// Taken from the Libraries test module, which needs to specify the path to
// the test library.
return
array
(
drupal_get_path
(
'module'
,
'libraries_test'
)
.
'/example'
);
}
libraries.module
View file @
c365e82b
...
...
@@ -112,6 +112,49 @@ function libraries_get_libraries() {
return
$directories
;
}
/**
* Looks for library info files.
*
* This function scans the following directories for info files:
* - libraries
* - profiles/$profilename/libraries
* - sites/all/libraries
* - sites/$sitename/libraries
* - any directories specified via hook_libraries_info_file_paths()
*
* @return
* An array of info files, keyed by library name. The values are the paths of
* the files.
*/
function
libraries_info_files
()
{
global
$profile
;
if
(
!
isset
(
$profile
))
{
$profile
=
variable_get
(
'install_profile'
,
'default'
);
}
$config
=
conf_path
();
// Build a list of directories.
$directories
=
module_invoke_all
(
'libraries_info_file_paths'
);
$directories
[]
=
'libraries'
;
$directories
[]
=
"libraries/
$profile
/libraries"
;
$directories
[]
=
'sites/all/libraries'
;
$directories
[]
=
"sites/
$config
/libraries"
;
// Scan for info files.
$files
=
array
();
foreach
(
$directories
as
$dir
)
{
$files
+=
file_scan_directory
(
$dir
,
'/[a-z[a-z0-9_]+.info/'
,
array
(
'key'
=>
'name'
,
'recurse'
=>
FALSE
,
));
}
foreach
(
$files
as
&
$file
)
{
$file
=
$file
->
uri
;
}
return
$files
;
}
/**
* Returns information about registered libraries.
*
...
...
@@ -140,23 +183,31 @@ function libraries_info($library = NULL) {
foreach
(
module_invoke
(
$module
,
'libraries_info'
)
as
$name
=>
$properties
)
{
$properties
[
'module'
]
=
$module
;
$properties
[
'name'
]
=
$name
;
$properties
+=
array
(
'title'
=>
$name
,
'vendor url'
=>
''
,
'download url'
=>
''
,
'path'
=>
''
,
'version callback'
=>
'libraries_get_version'
,
'version arguments'
=>
array
(),
'files'
=>
array
(),
'variants'
=>
array
(),
'versions'
=>
array
(),
'integration files'
=>
array
(),
);
$libraries
[
$name
]
=
$properties
;
}
}
// Gather information from .info files.
foreach
(
libraries_info_files
()
as
$name
=>
$path
)
{
$file
=
"
$path
/
$name
.info"
;
$libraries
[
$name
]
=
drupal_parse_info_file
(
$file
);
}
// Provide defaults.
foreach
(
$libraries
as
$name
=>
&
$properties
)
{
$properties
+=
array
(
'title'
=>
$name
,
'vendor url'
=>
''
,
'download url'
=>
''
,
'path'
=>
''
,
'version callback'
=>
'libraries_get_version'
,
'version arguments'
=>
array
(),
'files'
=>
array
(),
'variants'
=>
array
(),
'versions'
=>
array
(),
'integration files'
=>
array
(),
);
}
// Allow modules to alter the registered libraries.
drupal_alter
(
'libraries_info'
,
$libraries
);
}
...
...
tests/example/example.info
0 → 100644
View file @
c365e82b
; $Id$
; This is an example info file for a library used for testing purposes. It
; contains no actual library information, but, since it is named example.info,
; if Libraries API detects a library named 'example', we know that this file was
; properly detected.
tests/libraries.test
View file @
c365e82b
...
...
@@ -26,6 +26,22 @@ class LibrariesTestCase extends DrupalWebTestCase {
* @todo Better method name(s); split into detection/loading/overloading/etc.
*/
public
function
testLibraries
()
{
// Test a library specified with an .info file gets detected.
$library
=
libraries_info
(
'example'
);
$expected
=
array
(
'title'
=>
'example'
,
'vendor url'
=>
''
,
'download url'
=>
''
,
'path'
=>
''
,
'version callback'
=>
'libraries_get_version'
,
'version arguments'
=>
array
(),
'files'
=>
array
(),
'variants'
=>
array
(),
'versions'
=>
array
(),
'integration files'
=>
array
(),
);
$this
->
assertEqual
(
$library
,
$expected
,
'Library specified with an .info file found'
);
// Test missing library.
$library
=
libraries_info
(
'example_missing'
);
libraries_detect_library
(
$library
);
...
...
tests/libraries_test.module
View file @
c365e82b
...
...
@@ -287,6 +287,13 @@ function libraries_test_libraries_info() {
return
$libraries
;
}
/**
* Implements hook_libraries_info_file_paths()
*/
function
libraries_test_libraries_info_file_paths
()
{
return
array
(
drupal_get_path
(
'module'
,
'libraries_test'
)
.
'/example'
);
}
/**
* Gets the version of an example library.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment