summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmitaibu2013-05-30 08:16:50 (GMT)
committer Amitaibu2013-05-30 08:16:50 (GMT)
commite2c28119661d0406f72616249a3e5e893d3f789b (patch)
treebf633ce31dc77ebe6738b54ba739222af811cd1d
parent80bee442d825718aa14c1192ba0842f355e77b9b (diff)
Issue #2007746 by Amitaibu: Fixed use hook_field_access() to hide fields of exiting entities.
-rw-r--r--entityreference_prepopulate.module20
1 files changed, 12 insertions, 8 deletions
diff --git a/entityreference_prepopulate.module b/entityreference_prepopulate.module
index 4109a64..06c7ebb 100644
--- a/entityreference_prepopulate.module
+++ b/entityreference_prepopulate.module
@@ -103,9 +103,10 @@ function entityreference_prepopulate_field_attach_form($entity_type, $entity, &$
if ($settings['action'] == 'disable') {
$form[$field_name][$lang]['#disabled'] = TRUE;
}
- elseif ($settings['action'] == 'hide') {
- // We don't hide the field via hook_field_access(), as the
- // default value won't be set.
+ elseif ($settings['action'] == 'hide' && !$id) {
+ // For new entities we don't hide the field via hook_field_access(),
+ // as the default value won't be set. We use hook_field_access() only
+ // on existing ones.
$form[$field_name]['#access'] = FALSE;
}
}
@@ -138,20 +139,23 @@ function entityreference_prepopulate_field_access($op, $field, $entity_type, $en
}
list($id,,$bundle) = entity_extract_ids($entity_type, $entity);
- if ($id) {
- // Entity is already saved.
- return;
- }
-
$instance = field_info_instance($entity_type, $field['field_name'], $bundle);
if (empty($instance['settings']['behaviors']['prepopulate']['status'])) {
return;
}
$settings = $instance['settings']['behaviors']['prepopulate'];
+
if (!empty($settings['skip_perm']) && user_access($settings['skip_perm'])) {
return;
}
+
+ if ($id) {
+ // Entity is already saved. Return FALSE if we need to hide the field,
+ // otherwise ignore.
+ return $settings['action'] == 'hide' ? FALSE : NULL;
+ }
+
$ids = entityreference_prepopulate_get_values($field, $instance);
if (!$ids && $settings['fallback'] == 'hide') {