diff --git a/field_collection.module b/field_collection.module index 30f175e..6efceac 100644 --- a/field_collection.module +++ b/field_collection.module @@ -140,20 +140,34 @@ class FieldCollectionItemEntity extends Entity { } /** + * Returns the field instance label translated to interface language. + */ + public function translatedInstanceLabel($langcode = NULL) { + if ($info = $this->instanceInfo()) { + if (module_exists('i18n_field')) { + return i18n_string("field:{$this->field_name}:{$info['bundle']}:label", $info['label'], array('langcode' => $langcode)); + } + return $info['label']; + } + } + + /** * Specifies the default label, which is picked up by label() by default. */ public function defaultLabel() { // @todo make configurable. - if ($instance = $this->instanceInfo()) { + if ($this->fetchHostDetails()) { $field = $this->fieldInfo(); + $label = $this->translatedInstanceLabel(); + if ($field['cardinality'] == 1) { - return $instance['label']; + return $label; } elseif ($this->item_id) { - return t('!instance_label @count', array('!instance_label' => $instance['label'], '@count' => $this->delta() + 1)); + return t('!instance_label @count', array('!instance_label' => $label, '@count' => $this->delta() + 1)); } else { - return t('New !instance_label', array('!instance_label' => $instance['label'])); + return t('New !instance_label', array('!instance_label' => $label)); } } return t('Unconnected field collection item'); diff --git a/field_collection.pages.inc b/field_collection.pages.inc index 52c1f48..732e101 100644 --- a/field_collection.pages.inc +++ b/field_collection.pages.inc @@ -120,9 +120,6 @@ function field_collection_item_add($field_name, $entity_type, $entity_id, $revis return ''; } - $title = ($field['cardinality'] == 1) ? $instance['label'] : t('Add new !instance_label', array('!instance_label' => drupal_strtolower($instance['label']))); - drupal_set_title($title); - $field_collection_item = entity_create('field_collection_item', array('field_name' => $field_name)); // Do not link the field collection item with the host entity at this point, // as during the form-workflow we have multiple field collection item entity @@ -130,6 +127,9 @@ function field_collection_item_add($field_name, $entity_type, $entity_id, $revis // That way the link is going to be created when the item is saved. $field_collection_item->setHostEntity($entity_type, $entity, LANGUAGE_NONE, FALSE); + $title = ($field['cardinality'] == 1) ? $instance['label'] : t('Add new !instance_label', array('!instance_label' => $field_collection_item->translatedInstanceLabel())); + drupal_set_title($title); + // Make sure the current user has access to create a field collection item. if (!field_collection_item_access('create', $field_collection_item)) { return MENU_ACCESS_DENIED;