The "Hide" action in the current dev version causes populated fields to be hidden on the node edit form, even if the "Apply action on edit" option is not checked.

The "Disable" action doesn't seem to suffer with the same problem.

This issue seems to be a result of the code committed in #2007746: use hook_field_access() to hide fields of exiting entities, which doesn't appear to include a condition accounting for $settings['action_on_edit'].

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

Can you provide a patch? :)

morbiD’s picture

Yeah, I'm working on it, but I'm actually struggling to understand some of the logic in the code.

Specifically, in this snippet:

<?php
if ($id && empty($entity->is_new)) {
  return $settings['action'] == 'hide' ? FALSE : NULL;
}

if ($settings['action'] == 'hide') {
  // If entity is already saved and not just inserted, deny access, otherwise
  // ignore.
  return $id && empty($entity->is_new) ? FALSE : NULL;
}
?>

It seems to me that the second if condition is only evaluated if the first one evaluates to FALSE, and if the first one does evaluate to FALSE, then return $id && empty($entity->is_new) ? FALSE : NULL; must also evaluate to FALSE and can only ever return NULL. If I'm following it correctly, that's just redundant code...

Also, I don't get why the following snippet is evaluated last in the function:

<?php
if (!$ids && $settings['fallback'] == 'hide') {
  return FALSE;
}
?>

Surely if there are no prepopulate values passed to the form and we're checking the fallback behaviour, then there is no reason to have carried out the previous checks as though prepopulate values had been passed?

I'll post a patch later if I manage to figure it all out.

morbiD’s picture

Status: Active » Needs review
FileSize
1.6 KB

Ok, I *think* I've got it all figured out, so here's a patch.

It seems to work correctly for all combinations of action and fallback settings, but I haven't tested extensively.

RoySegall’s picture

I'm attaching a patch that handle the problem - when the user checked the "apply on edit" check box and i fixed the tests so they could verify that the feature work as expected.

amitaibu’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.