Commit 89d190a1 authored by fago's avatar fago

#913962 added current path and URL properties for usage with Rules.

parent 248e3efc
......@@ -853,6 +853,11 @@ class EntityMetadataIntegrationTestCase extends DrupalWebTestCase {
foreach ($wrapper as $key => $value) {
$this->assertValue($wrapper, $key);
}
// Test page request related properties.
foreach ($wrapper->current_page as $key => $value) {
$this->assertValue($wrapper->current_page, $key);
}
// Test files.
$file = $this->createFile();
......
......@@ -207,11 +207,26 @@ function entity_metadata_system_get_properties($data = FALSE, array $options, $n
case 'current_date':
return time();
case 'current_page':
// Subsequent getters of the struct retrieve the actual values.
return array();
default:
return variable_get('site_' . $name, '');
}
}
/**
* Callback for getting properties for the current page request.
* @see entity_metadata_system_entity_info_alter()
*/
function entity_metadata_system_get_page_properties($data = array(), array $options, $name) {
switch ($name) {
case 'url':
return $GLOBALS['base_root'] . request_uri();
}
}
/**
* Callback for getting file properties.
* @see entity_metadata_system_entity_info_alter()
......
......@@ -61,6 +61,26 @@ function entity_metadata_system_entity_property_info() {
'getter callback' => 'entity_metadata_system_get_properties',
'type' => 'date',
);
$properties['current_page'] = array(
'label' => t("Current page"),
'description' => t("Information related to the current page request."),
'getter callback' => 'entity_metadata_system_get_properties',
'type' => 'struct',
'property info' => array(
'path' => array(
'label' => t("Path"),
'description' => t("The internal Drupal path of the current page request."),
'getter callback' => 'current_path',
'type' => 'text',
),
'url' => array(
'label' => t("URL"),
'description' => t("The full URL of the current page request."),
'getter callback' => 'entity_metadata_system_get_page_properties',
'type' => 'uri',
),
),
);
// Files.
$properties = &$info['file']['properties'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment