Patch whisks away all CCK fields associated with Features that are Spaces-aware but not enabled in the current Space.

Comments

Grayside’s picture

Status: Active » Needs review

>.>

Grayside’s picture

StatusFileSize
new976 bytes

Fieldgroups too.

Grayside’s picture

StatusFileSize
new972 bytes

Wrong module prefix. Copy and paste errorism!

hefox’s picture

Okay, eye's paining so not making a patch atm but this is what I just altered to it.

For performance sake, I think it should be restrained to edit or be configurable.

   // Why check fieldgroups ? They don't show if no enabled fields generally
    // And they don't match the pattern for key that fields have
    // Don't think they go through hook_field_access either
    $map = features_get_component_map('content');
    $key = $field['type_name'] . '-' . $field['field_name'];
    $use_feature = NULL;
    if (!empty($map[$key])) {
       // This needs to find the enabled module as more than one feature can
      // declare the same. 
      foreach ($map[$key] as $feature) {
        if (module_exists($feature)) {
          $use_feature = $feature;
        }
      }
    }
    if (isset($use_feature)) {
      // Block any access to CCK fields in Features not enabled for the current Space.
      if (!spaces_access_feature('view', $feature)) {
        return FALSE;
      }
    }
    // Make sure node reference fields have at least one enabled type.
    if (!empty($field['referenceable_types'])) {
      $map = features_get_component_map('node');
      $has_accessible_type = FALSE;
      foreach (array_filter($field['referenceable_types']) as $type) {
        if (!empty($map[$type])) {
          $use_feature = NULL;
          foreach ($map[$type] as $feature) {
            if (module_exists($feature)) {
              $use_feature = $feature;
            }
          }
          if (isset($use_feature)) {
            if (spaces_access_feature('view', $use_feature)) {
              $has_accessible_type = TRUE;
              break;
            }
            else {
              continue;
            }
          }
        }
        // If not map or no enabled features, fallback to this.
        if (node_get_types('type', $type)) {
          $has_accessible_type = TRUE;
          break;
        }
      }
      return $has_accessible_type;
    }
  }
  return TRUE;
}
Grayside’s picture

Status: Needs review » Needs work

Good advancement. I'm not sure about integrating the nodereference in this way. There could be solid use cases for using a nodereference field to target nodes outside the current space. Contradicting that use case, this check does not evaluate Views-based referencable types, which is what I usually use in a Spaces environment when I care about limiting the values to local content.

Performance-wise, I'm a bit on the fence. It would be nice to hide the CCK values from the user if you no longer want them to show up.
The results of features_get_component_map() is a static that should be available in memory on full node pages. spaces_access_feature() is cached and also a static. I haven't done actual performance testing, but this check should not be a big impact per field.

Marking as Needs Work to at least reroll with improved basic integration.

Grayside’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

Reroll with some tweaks from #4. I skipped the node reference validation and the suggestion to limit it to edit only pending further discussion.