4 edited tags
| link
3 deleted 222 characters in body
source | link

We have a situation where in different environments we have to manually delete fields. Rather than manually doing that, we want to programmatically deploy the changes. The idea that is being is discussed is to use a custom module which calls the hook_field_delete_instance() hook.

The issue we are having is how to best pass in the content type machine name and the machine name for a single content type. We are understanding that when we reused the field on a separate content type, we are essentially creating an alias on the current content type that points to the original content type holding the field name.

Using the situation below, what is the best way to delete the two fields on the on the basic page only using the hook_field_delete_instance() on a custom module?

Situation:

We have two content types: article and basic page. We created several fields on the article content type that we ended up reusing on the basic page.

Article:

  1. field_art_original_publish_date
  2. field_art_country_tag
  3. field_art_image

Basic Page:

  1. field_art_image (reused from article content type)
  2. field_art_country_tag (reused from article content type)

Update:

So now that i am thinking further on this, i would like 1 hook update for 1 field deletion so that if a hook update fails then i know which fields need attention.

Here is what i have come up with using what @Clive has suggested.

function mymodule_update_7001(&$sandox) {
     mymodule_delete_field('field_art_image', 'page' );
}

function mymodule_update_7002(&$sandox) {
    mymodule_delete_field('field_art_country_tag', 'page');
}

function mymodule_delete_field($field_mn, $ct_mn) {
    $entity_type = "node";

    $field_instance = field_info_instances($entity_type, $field_mn, $ct_mn);
    field_delete_instance($field_instance);

    //setting the batch size to a large number resolves my prior issues
    $batch_size = 20000;
    field_purge_batch(count($field_instance)$batch_size);
}

One issue i have run into is that it is not deleting from the content type. Even when i add field_purge_batch(count($field_instance)) or field_purge_batch(count($field_instance) + 5)), i do not see the field deleted from the content type. Running cron manually gives a cron failed error messages.

Any thoughts?

We have a situation where in different environments we have to manually delete fields. Rather than manually doing that, we want to programmatically deploy the changes. The idea that is being is discussed is to use a custom module which calls the hook_field_delete_instance() hook.

The issue we are having is how to best pass in the content type machine name and the machine name for a single content type. We are understanding that when we reused the field on a separate content type, we are essentially creating an alias on the current content type that points to the original content type holding the field name.

Using the situation below, what is the best way to delete the two fields on the on the basic page only using the hook_field_delete_instance() on a custom module?

Situation:

We have two content types: article and basic page. We created several fields on the article content type that we ended up reusing on the basic page.

Article:

  1. field_art_original_publish_date
  2. field_art_country_tag
  3. field_art_image

Basic Page:

  1. field_art_image (reused from article content type)
  2. field_art_country_tag (reused from article content type)

Update:

So now that i am thinking further on this, i would like 1 hook update for 1 field deletion so that if a hook update fails then i know which fields need attention.

Here is what i have come up with using what @Clive has suggested.

function mymodule_update_7001(&$sandox) {
     mymodule_delete_field('field_art_image', 'page' );
}

function mymodule_update_7002(&$sandox) {
    mymodule_delete_field('field_art_country_tag', 'page');
}

function mymodule_delete_field($field_mn, $ct_mn) {
    $entity_type = "node";

    $field_instance = field_info_instances($entity_type, $field_mn, $ct_mn);
    field_delete_instance($field_instance);

    field_purge_batch(count($field_instance));
}

One issue i have run into is that it is not deleting from the content type. Even when i add field_purge_batch(count($field_instance)) or field_purge_batch(count($field_instance) + 5)), i do not see the field deleted from the content type. Running cron manually gives a cron failed error messages.

Any thoughts?

We have a situation where in different environments we have to manually delete fields. Rather than manually doing that, we want to programmatically deploy the changes. The idea that is being is discussed is to use a custom module which calls the hook_field_delete_instance() hook.

The issue we are having is how to best pass in the content type machine name and the machine name for a single content type. We are understanding that when we reused the field on a separate content type, we are essentially creating an alias on the current content type that points to the original content type holding the field name.

Using the situation below, what is the best way to delete the two fields on the on the basic page only using the hook_field_delete_instance() on a custom module?

Situation:

We have two content types: article and basic page. We created several fields on the article content type that we ended up reusing on the basic page.

Article:

  1. field_art_original_publish_date
  2. field_art_country_tag
  3. field_art_image

Basic Page:

  1. field_art_image (reused from article content type)
  2. field_art_country_tag (reused from article content type)

Update:

So now that i am thinking further on this, i would like 1 hook update for 1 field deletion so that if a hook update fails then i know which fields need attention.

Here is what i have come up with using what @Clive has suggested.

function mymodule_update_7001(&$sandox) {
     mymodule_delete_field('field_art_image', 'page' );
}

function mymodule_update_7002(&$sandox) {
    mymodule_delete_field('field_art_country_tag', 'page');
}

function mymodule_delete_field($field_mn, $ct_mn) {
    $entity_type = "node";

    $field_instance = field_info_instances($entity_type, $field_mn, $ct_mn);
    field_delete_instance($field_instance);

    //setting the batch size to a large number resolves my prior issues
    $batch_size = 20000;
    field_purge_batch($batch_size);
}
    Tweeted twitter.com/StackDrupal/status/717787504645128192
2 added 1115 characters in body
source | link

We have a situation where in different environments we have to manually delete fields. Rather than manually doing that, we want to programmatically deploy the changes. The idea that is being is discussed is to use a custom module which calls the hook_field_delete_instance() hook.

The issue we are having is how to best pass in the content type machine name and the machine name for a single content type. We are understanding that when we reused the field on a separate content type, we are essentially creating an alias on the current content type that points to the original content type holding the field name.

Using the situation below, what is the best way to delete the two fields on the on the basic page only using the hook_field_delete_instance() on a custom module?

Situation:

We have two content types: article and basic page. We created several fields on the article content type that we ended up reusing on the basic page.

Article:

  1. field_art_original_publish_date
  2. field_art_country_tag
  3. field_art_image

Basic Page:

  1. field_art_image (reused from article content type)
  2. field_art_country_tag (reused from article content type)

Update:

So now that i am thinking further on this, i would like 1 hook update for 1 field deletion so that if a hook update fails then i know which fields need attention.

Here is what i have come up with using what @Clive has suggested.

function mymodule_update_7001(&$sandox) {
     mymodule_delete_field('field_art_image', 'page' );
}

function mymodule_update_7002(&$sandox) {
    mymodule_delete_field('field_art_country_tag', 'page');
}

function mymodule_delete_field($field_mn, $ct_mn) {
    $entity_type = "node";

    $field_instance = field_info_instances($entity_type, $field_mn, $ct_mn);
    field_delete_instance($field_instance);

    field_purge_batch(count($field_instance));
}

One issue i have run into is that it is not deleting from the content type. Even when i add field_purge_batch(count($field_instance)) or field_purge_batch(count($field_instance) + 5)), i do not see the field deleted from the content type. Running cron manually gives a cron failed error messages.

Any thoughts?

We have a situation where in different environments we have to manually delete fields. Rather than manually doing that, we want to programmatically deploy the changes. The idea that is being is discussed is to use a custom module which calls the hook_field_delete_instance() hook.

The issue we are having is how to best pass in the content type machine name and the machine name for a single content type. We are understanding that when we reused the field on a separate content type, we are essentially creating an alias on the current content type that points to the original content type holding the field name.

Using the situation below, what is the best way to delete the two fields on the on the basic page only using the hook_field_delete_instance() on a custom module?

Situation:

We have two content types: article and basic page. We created several fields on the article content type that we ended up reusing on the basic page.

Article:

  1. field_art_original_publish_date
  2. field_art_country_tag
  3. field_art_image

Basic Page:

  1. field_art_image (reused from article content type)
  2. field_art_country_tag (reused from article content type)

We have a situation where in different environments we have to manually delete fields. Rather than manually doing that, we want to programmatically deploy the changes. The idea that is being is discussed is to use a custom module which calls the hook_field_delete_instance() hook.

The issue we are having is how to best pass in the content type machine name and the machine name for a single content type. We are understanding that when we reused the field on a separate content type, we are essentially creating an alias on the current content type that points to the original content type holding the field name.

Using the situation below, what is the best way to delete the two fields on the on the basic page only using the hook_field_delete_instance() on a custom module?

Situation:

We have two content types: article and basic page. We created several fields on the article content type that we ended up reusing on the basic page.

Article:

  1. field_art_original_publish_date
  2. field_art_country_tag
  3. field_art_image

Basic Page:

  1. field_art_image (reused from article content type)
  2. field_art_country_tag (reused from article content type)

Update:

So now that i am thinking further on this, i would like 1 hook update for 1 field deletion so that if a hook update fails then i know which fields need attention.

Here is what i have come up with using what @Clive has suggested.

function mymodule_update_7001(&$sandox) {
     mymodule_delete_field('field_art_image', 'page' );
}

function mymodule_update_7002(&$sandox) {
    mymodule_delete_field('field_art_country_tag', 'page');
}

function mymodule_delete_field($field_mn, $ct_mn) {
    $entity_type = "node";

    $field_instance = field_info_instances($entity_type, $field_mn, $ct_mn);
    field_delete_instance($field_instance);

    field_purge_batch(count($field_instance));
}

One issue i have run into is that it is not deleting from the content type. Even when i add field_purge_batch(count($field_instance)) or field_purge_batch(count($field_instance) + 5)), i do not see the field deleted from the content type. Running cron manually gives a cron failed error messages.

Any thoughts?

1
source | link