$profile 2


You can implement hook_system_info_alter() to show modules that are otherwise hidden.

Via the command line, starting in your Drupal site's sites/default/modules directory:

Get raw version
  1. name = Profile Unlock
  2. description = Unlock the core Profile module.
  3. core = 7.x
  4. files[] = profile_unlock.module


Get raw version
  1. <?php
  2. function profile_unlock_system_info_alter(&$info, $file, $type) {
  3. if ($type == 'module' && $file->name == 'profile') {
  4. $info['hidden'] = FALSE;
  5. }
  6. }
  7. ?>

The first example shows the creation of a field collection entity that will be attached to a node that has a field collection field already defined for it through the Manage Fields tab of the node type creation / modification UI. The example shows creating the field collection entity (using the entity_create function of the Entity API, attaching it to a node, and using the Entity API then to set values of fields within the field collection.

Get raw version
  1. <?php
  2. // Code that would be here but is omitted loads a node called $my_node
  3. // Nodes of the type that is $my_node have a field of the field collection
  4. // type called field_text_files, which in turn is defined as having two
  5. // fields called field_source_txt_filename and field_source_txt_content
  6. // Begin by using the entity_create function to create a new entity of
  7. // type field_collection_item. The second parameter to the function
  8. // provides "an array of values to set, keyed by property name".
  9. // In our example, the field in my_node that holds the field collection is
  10. // the field_text_files field.
  12. $fc_item = entity_create('field_collection_item', array('field_name' => 'field_text_files'));
  13. // Now connect / attach the new field collection item to a node that
  14. // we loaded earlier in our code and stored in the $my_node variable.
  15. // The setHostEntity function is provided by the Field Collection module.
  16. $fc_item->setHostEntity('node', $my_node);
  17. // Now, we use the entity_metadata_wrapper function from the Entity
  18. // API to "wrap" the field collection entity in a class that simplifies
  19. // working with the entity.
  20. $fc_wrapper = entity_metadata_wrapper('field_collection_item', $fc_item);
  21. // If we weren't using the entity_metadata_wrapper function, we'd have to
  22. // access and set field values within the field collection entity using this code:
  23. //
  24. // $fc_item->field_source_txt_filename[LANGUAGE_NONE][0]['value'] = $stat['name'];
  25. //
  26. // This code is obviously less readable and also not as friendly to translations
  27. // perhaps.
  29. // Now, we just put a string value into a field on the field collection entity
  30. // The set() method appears to be the preferred way to set values on
  31. // entity fields, as opposed doing an assignment of data to the value() property
  32. $fc_wrapper->field_source_txt_filename->set('my_text_file.txt');
  33. // Put another string value into another field on the field collection entity
  34. $txt_file_content = "A whole bunch of content.";
  35. $fc_wrapper->field_source_txt_content->set($txt_file_content);
  36. // Now save the field collection entity to the database
  37. $fc_wrapper->save(TRUE);
  38. // Now save the node
  39. node_save($my_node);
  40. // As an alternative to node_save, you could use
  41. // field_attach_update('node', $my_node);
  42. // This function from the Field API saves field data for an existing entity but
  43. // doesn't save the entity itself. So, in the code above, the field_text_files field
  44. // that belongs to $my_node would get saved, but the $my_node node would
  45. // not get saved.
  46. ?>

References for functions and methods used in the example above:

setHostEntity at drupalcommerce.org
entity_metadata_wrapper on drupalcontrib.org
LevelTen Tutorial from leveltendesign.com
Documentation for entity metadata wrappers from drupal.org
field_attach_update documentation from api.drupal.org
This example shows updating (loading/editing/saving) an existing field collection in an Entity Wrapper provided by the Entity API module.

Get raw version
  1. <?php
  2. // Load the node by NID
  3. $raw_node = node_load($nid);
  4. // Wrap it with Entity API
  5. $node = entity_metadata_wrapper('node', $raw_node);
  6. // Get the first item from the muli-value field collection
  7. $raw_collection = $node->field_collection->value();
  8. // Wrap it with Entity API
  9. $collection = entity_metadata_wrapper('field_collection_item', $raw_collection);
  10. //dsm the old value
  11. dsm($collection->field_example->value());
  12. // Set a new value on the field_example textfield.
  13. $collection->field_example = 'New value';
  14. // Save the changes to the entity
  15. $collection->save();
  16. ?>