Commit 74d9cb8e authored by Wolfgang Ziegler's avatar Wolfgang Ziegler
Browse files

remove the unnecessary field_name argument from the add-item path + ensured...

remove the unnecessary field_name argument from the add-item path + ensured generated paths are unique.


Author: fago <nuppla@zites.net>
parent 5e2559bf
......@@ -364,9 +364,10 @@ function field_collection_menu() {
'context' => MENU_CONTEXT_INLINE,
'file' => 'field_collection.pages.inc',
);
$items[$path . '/add/%field_collection_field_name/%/%'] = array(
// Add entity type and the entity id as additional arguments.
$items[$path . '/add/%/%'] = array(
'page callback' => 'field_collection_item_add',
'page arguments' => array($count + 1, $count + 2, $count + 3),
'page arguments' => array($field['field_name'], $count + 1, $count + 2),
// The pace callback takes care of checking access itself.
'access callback' => TRUE,
'file' => 'field_collection.pages.inc',
......@@ -482,11 +483,7 @@ function field_collection_field_info() {
*/
function field_collection_field_get_path($field) {
if (empty($field['settings']['path'])) {
// Provide a sane default using the field name without the 'field' prefix.
if (strpos($field['field_name'], 'field_') === 0) {
return 'field-collection/' . substr($field['field_name'], 6);
}
return 'field-collection/' . $field['field_name'];
return 'field-collection/' . strtr($field['field_name'], array('_' => '-'));
}
return $field['settings']['path'];
}
......@@ -679,7 +676,7 @@ function field_collection_field_formatter_view($entity_type, $entity, $field, $i
if (!empty($settings['description'])) {
$element['#suffix'] .= '<div class="description field-collection-description">' . field_filter_xss($instance['description']) . '</div>';
}
$add_path = $path . '/add/' . strtr($field['field_name'], array('_' => '-')) . '/' . $entity_type . '/' . $id;
$add_path = $path . '/add/' . $entity_type . '/' . $id;
$element['#suffix'] .= '<ul class="action-links action-links-field-collection-add"><li>' . l($settings['add'], $add_path, array('query' => drupal_get_destination())) . "</li></ul>";
}
}
......
......@@ -106,7 +106,7 @@ class FieldCollectionBasicTestCase extends DrupalWebTestCase {
$this->drupalLogin($user);
// Make sure access is denied.
$path = 'field-collection/test_collection/add/field-test-collection/node/' . $node->nid;
$path = 'field-collection/field-test-collection/add/node/' . $node->nid;
$this->drupalGet($path);
$this->assertText(t('Access denied'), 'Access has been denied.');
......@@ -123,11 +123,11 @@ class FieldCollectionBasicTestCase extends DrupalWebTestCase {
$this->assertText($edit['field_text[und][0][value]'], "Added field value is shown.");
$edit['field_text[und][0][value]'] = $this->randomName();
$this->drupalPost('field-collection/test_collection/1/edit', $edit, t('Save'));
$this->drupalPost('field-collection/field-test-collection/1/edit', $edit, t('Save'));
$this->assertText(t('The changes have been saved.'), 'Field collection saved.');
$this->assertText($edit['field_text[und][0][value]'], "Field collection has been edited.");
$this->drupalGet('field-collection/test_collection/1');
$this->drupalGet('field-collection/field-test-collection/1');
$this->assertText($edit['field_text[und][0][value]'], "Field collection can be viewed.");
// Add further 3 items, so we have reached 4 == maxium cardinality.
......@@ -139,7 +139,7 @@ class FieldCollectionBasicTestCase extends DrupalWebTestCase {
$this->drupalGet($path);
$this->assertText(t('Too many items.'), 'Maxium cardinality has been reached.');
$this->drupalPost('field-collection/test_collection/1/delete', array(), t('Delete'));
$this->drupalPost('field-collection/field-test-collection/1/delete', array(), t('Delete'));
$this->drupalGet($path);
// Add form is shown again.
$this->assertText(t('Test text field'), 'Field collection item has been deleted.');
......
Supports Markdown
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