1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Implements hook_pathauto().
|
5
|
*/
|
6
|
function field_collection_pathauto($op) {
|
7
|
if ('settings' === $op) {
|
8
|
$settings = array();
|
9
|
$settings['module'] = 'field_collection';
|
10
|
$settings['token_type'] = 'field_collection_item';
|
11
|
$settings['groupheader'] = t('Field collection item paths');
|
12
|
$settings['patterndescr'] = t('Default path pattern (applies to all field collections with blank patterns below)');
|
13
|
$settings['patterndefault'] = '';
|
14
|
// @todo Implement bulk update:
|
15
|
// $settings['batch_update_callback'] = 'field_collection_pathauto_bulk_update_batch_process';
|
16
|
// $settings['batch_file'] = drupal_get_path('module', 'field_collection') . '/field_collection.pathauto.inc';
|
17
|
|
18
|
$settings['patternitems'] = array();
|
19
|
$instances = field_info_instances();
|
20
|
foreach ($instances as $entity_type => $type_bundles) {
|
21
|
foreach ($type_bundles as $bundle => $bundle_instances) {
|
22
|
foreach ($bundle_instances as $field_name => $instance) {
|
23
|
$field = field_info_field($field_name);
|
24
|
if ($field['type'] === 'field_collection') {
|
25
|
// @todo We may need different patterns depending on the.
|
26
|
// host entity type or the host bundle. If so we need to prefix
|
27
|
// field-name with $entity_type . '_' . $bundle . '_' and also need
|
28
|
// to implement our own version of pathauto_pattern_load_by_entity()
|
29
|
// searching for the best matching pattern.
|
30
|
$settings['patternitems'][$field_name] = t('Pattern for all field collection @field-collection paths', array('@field-collection' => $field_name));
|
31
|
}
|
32
|
}
|
33
|
}
|
34
|
}
|
35
|
|
36
|
return (object) $settings;
|
37
|
}
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Create a path alias for a field collection item.
|
42
|
*
|
43
|
* @param object $host_entity
|
44
|
* Entity to which the field collection item belongs.
|
45
|
* @param object $entity
|
46
|
* Field collection item.
|
47
|
* @param string $op
|
48
|
* Operation to perform for pathauto_create_alias(). Can be 'insert', 'update', 'return', or 'bulkupdate'.
|
49
|
*
|
50
|
* @see field_collection_field_update()
|
51
|
*/
|
52
|
function field_collection_pathauto_create_alias($host_entity, $entity, $op, $options = array()) {
|
53
|
module_load_include('inc', 'pathauto');
|
54
|
|
55
|
pathauto_create_alias('field_collection', $op, 'field-collection/' . str_replace('_', '-', $entity->field_name) . '/' . $entity->item_id, array('field_collection_item' => $entity), $entity->field_name);
|
56
|
}
|