i'm not sure if this functionality already exists: how to remove an existing field / an existing component using features override?

when i delete the field i can't select it as an override so i was wondering if it was possible and how to implement such functionality?

thank you, josef

Comments

dasjo’s picture

i tried to "fake" an override, but the following code doesn't work. the base feature would still list the field as overridden due to removal

  $features_override = new stdClass;
  $features_override->disabled = FALSE; /* Edit this to true to make a default features_override disabled initially */
  $features_override->api_version = 1;
  $features_override->name = 'my_override_feature';
  $features_override->description = '';
  $features_override->component_type = 'field';
  $features_override->component_id = 'my_field';
  $features_override->value = array(
    'additions' => array(),
    'deletions' => array(
      0 => array(
        'keys' => array(
          0 => array(
            'type' => 'array',
            'key' => 'field_instance',
          ),
          1 => array(
            'type' => 'array',
            'key' => 'default_value',
          ),
        ),
      ),
    ),
  );
nedjo’s picture

Hi Josef!

Yeah, this isn't possible currently with Features Override. You could do it in a custom default hook alter. E.g.

function example_field_default_fields_alter(&$items) {
  if (isset($items['my_field_name'])) {
    unset($items['my_field_name']);
  }
}

It would still show up as an override. This is due to a bug in Features. See point 3 in this comment: #1277854-49: Faciliate altering features, e.g., export field display settings separate from field data structure ("One case is adding or removing components...").

dasjo’s picture

hi nedjo, i see, the hook alter we're using right now, but as you stated, unfortunately the component will be marked overridden. would you consider this a feature request of features override then?

nedjo’s picture

I think it has to be fixed in Features. I opened an issue, #1345174: Alter hook implementations lead to false overridden status for features components. I sketched in some tests to detect the bug. If you or anyone else happens to have time to fill in the tests or draft a fix, please go ahead....

dasjo’s picture

great thank you nedjo, i will be following the features issue

nedjo’s picture

Tested a bit more and I was wrong--the info data returned by features_get_features() is altered. So if you implement a default hook alter as in #2, and then unset the element in hook_system_info_alter(), your feature shouldn't show as overridden. Like this:

/**
 * Implements hook_system_info_alter().
 *
 * Unset a removed component.
 */
function example_system_info_alter(&$info, $file, $type) {
  if ($type == 'module' && $file->name == 'original_feature') {
    unset($info['features']['field'][array_search('my_field_name', $info['features']['field'])]);
  }
}
jec006’s picture

Category: support » bug

This now seems addable from the UI, however, the unset is not properly added to the override module.

jec006’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
candelas’s picture

Issue summary: View changes

It would be nice to have this feature :)