コード例 #1
0
ファイル: FieldHelper.php プロジェクト: juampynr/DrupalCampEs
 public static function purgeField(array $field)
 {
     $field = static::readFieldById($field['id']);
     if (empty($field['deleted'])) {
         throw new FieldException("Field not yet marked as deleted.");
     }
     if (!module_exists($field['storage']['module'])) {
         throw new FieldException("The {$field['storage']['module']} module needs to be enabled in order to delete field ID {$field['id']}.");
     }
     $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => TRUE, 'include_inactive' => TRUE));
     if (count($instances) > 0) {
         throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field['field_name'])));
     }
     db_delete('field_config')->condition('id', $field['id'])->execute();
     // Notify the storage engine.
     module_invoke($field['storage']['module'], 'field_storage_purge_field', $field);
     // Clear the cache.
     field_info_cache_clear();
     // Invoke external hooks after the cache is cleared for API consistency.
     module_invoke_all('field_purge_field', $field);
     watchdog('helper', "Field ID {$field['id']} completely removed.");
 }
コード例 #2
0
 public static function mergeFields($old_field_name, $new_field_name)
 {
     $old_field = field_info_field($old_field_name);
     $new_field = field_info_field($new_field_name);
     if (empty($old_field)) {
         throw new FieldException("Field {$old_field_name} does not exist.");
     }
     if (empty($new_field)) {
         throw new FieldException("Field {$new_field_name} does not exist.");
     }
     if ($old_field['type'] != $new_field['type']) {
         throw new FieldException("Cannot merge fields because they are not the same field type.");
     }
     if ($old_field['storage']['type'] !== 'field_sql_storage') {
         throw new FieldException("Unable to change field type for field {$old_field['field_name']} using storage {$old_field['storage']['type']}.");
     }
     if ($new_field['storage']['type'] !== 'field_sql_storage') {
         throw new FieldException("Unable to change field type for field {$new_field['field_name']} using storage {$new_field['storage']['type']}.");
     }
     $instances = field_read_instances(array('field_name' => $old_field_name));
     foreach ($instances as $instance) {
         static::changeInstanceField($instance, $new_field_name);
     }
     // I don't think this is necessary since this will remove all the instances
     // for a field, which deletes the field as well.
     // FieldHelper::deleteField($old_field);
 }