Skip to main content
Code format
Source Link
Elin Y.
  • 7.4k
  • 1
  • 41
  • 65

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper
           ->field_collection_parent
           ->field_collection_child
           ->field_child
           ->value();

// UPDATE: If a field accepts multiple values, treat it like an array
// The following line would get the first value of field_collection_child in the 
// first field_collection_parent.
$value = $node_wrapper
           ->field_collection_parent[0]
           ->field_collection_child[0]
           ->value();

// To set/modify the value of field_child
$node_wrapper
  ->field_collection_parent
  ->field_collection_child
  ->field_child
  ->set('Some new value');

// To save the node after modifying
$node_wrapper->save();

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper->field_collection_parent->field_collection_child->field_child->value();

// UPDATE: If a field accepts multiple values, treat it like an array
// The following line would get the first value of field_collection_child in the first field_collection_parent.
$value = $node_wrapper->field_collection_parent[0]->field_collection_child[0]->value();

// To set/modify the value of field_child
$node_wrapper->field_collection_parent->field_collection_child->field_child->set('Some new value');

// To save the node after modifying
$node_wrapper->save();

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper
           ->field_collection_parent
           ->field_collection_child
           ->field_child
           ->value();

// UPDATE: If a field accepts multiple values, treat it like an array
// The following line would get the first value of field_collection_child in the 
// first field_collection_parent.
$value = $node_wrapper
           ->field_collection_parent[0]
           ->field_collection_child[0]
           ->value();

// To set/modify the value of field_child
$node_wrapper
  ->field_collection_parent
  ->field_collection_child
  ->field_child
  ->set('Some new value');

// To save the node after modifying
$node_wrapper->save();
added 170 characters in body
Source Link
Elin Y.
  • 7.4k
  • 1
  • 41
  • 65

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper->field_collection_parent->field_collection_child->field_child->value();

// UPDATE: If a field accepts multiple values, treat it like an array
// The following line would get the first value of field_collection_child in the first field_collection_parent.
$value = $node_wrapper->field_collection_parent[0]->field_collection_child[0]->value();

// To set/modify the value of field_child
$node_wrapper->field_collection_parent->field_collection_child->field_child->set('Some new value');

// To save the node after modifying
$node_wrapper->save();

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper->field_collection_parent->field_collection_child->field_child->value();

// To set/modify the value of field_child
$node_wrapper->field_collection_parent->field_collection_child->field_child->set('Some new value');

// To save the node after modifying
$node_wrapper->save();

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper->field_collection_parent->field_collection_child->field_child->value();

// UPDATE: If a field accepts multiple values, treat it like an array
// The following line would get the first value of field_collection_child in the first field_collection_parent.
$value = $node_wrapper->field_collection_parent[0]->field_collection_child[0]->value();

// To set/modify the value of field_child
$node_wrapper->field_collection_parent->field_collection_child->field_child->set('Some new value');

// To save the node after modifying
$node_wrapper->save();
Source Link
Elin Y.
  • 7.4k
  • 1
  • 41
  • 65

Yes it is possible. Let's say you have a content type with a field collection named field_collection_parent, which has a field collection in it named field_collection_child, which has a field in it named field_child.

// First you need to wrap the node with entity_metadata_wrapper
$node_wrapper = entity_metadata_wrapper('node', $node);

// To get the value of field_child:
$value = $node_wrapper->field_collection_parent->field_collection_child->field_child->value();

// To set/modify the value of field_child
$node_wrapper->field_collection_parent->field_collection_child->field_child->set('Some new value');

// To save the node after modifying
$node_wrapper->save();