Loading taxonomy_access.module +17 −0 Changes for taxonomy_access.module: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1759,3 +1759,20 @@ function _taxonomy_access_grant_help_table() { return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('grant_help')))); } /** * Implements hook_disable(). * * Removes all options_list callbacks during disabling of the module which were * set in taxonomy_access_field_info_alter(). */ function taxonomy_access_disable() { foreach (field_read_fields() as $field_name => $field) { if ($field['type'] == 'taxonomy_term_reference') { if ($field['settings']['options_list_callback'] == '_taxonomy_access_term_options') { $field['settings']['options_list_callback'] = ''; field_update_field($field); } } } } taxonomy_access.test +56 −0 Changes for taxonomy_access.test: 56 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1562,3 +1562,59 @@ class TaxonomyAccessWeightTest extends DrupalWebTestCase { ); } } /** * Tests that callbacks are cleaned up when the module is disabled. */ class TaxonomyAccessCallbackCleanupTest extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Callback Cleanup', 'description' => 'Test callback cleanup during disabling of module works.', 'group' => 'Taxonomy Access Control', ); } public function setUp() { parent::setUp('taxonomy_access'); } /** * Verifies that the module's callbacks are cleaned up during disable. */ public function testCallbackCleanup() { // The problem only happens on new fields after the module is installed. $content_type = $this->drupalCreateContentType(); // Create a new field with type taxonomy_term_reference. $field_name = drupal_strtolower($this->randomName() . '_field_name'); $field_type = array( 'field_name' => $field_name, 'type' => 'taxonomy_term_reference', 'cardinality' => 1, ); $field_type = field_create_field($field_type); // Add an instance of the field to content type. $field_instance = array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => $content_type->name ); $field_instance = field_create_instance($field_instance); // Trigger hook_disable to see if the callbacks are cleaned up. module_disable(array('taxonomy_access'), TRUE); // Create a user so that we can check if we can access the node add pages. $this->privileged_user = $this->drupalCreateUser(array('bypass node access')); $this->drupalLogin($this->privileged_user); // If the callbacks are not cleaned up we would get a fatal error. $this->drupalGet('node/add/' . $content_type->name); $this->assertText(t('Create @name', array('@name' => $content_type->name)), t('New content can be added')); } } Loading
taxonomy_access.module +17 −0 Changes for taxonomy_access.module: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1759,3 +1759,20 @@ function _taxonomy_access_grant_help_table() { return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('grant_help')))); } /** * Implements hook_disable(). * * Removes all options_list callbacks during disabling of the module which were * set in taxonomy_access_field_info_alter(). */ function taxonomy_access_disable() { foreach (field_read_fields() as $field_name => $field) { if ($field['type'] == 'taxonomy_term_reference') { if ($field['settings']['options_list_callback'] == '_taxonomy_access_term_options') { $field['settings']['options_list_callback'] = ''; field_update_field($field); } } } }
taxonomy_access.test +56 −0 Changes for taxonomy_access.test: 56 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1562,3 +1562,59 @@ class TaxonomyAccessWeightTest extends DrupalWebTestCase { ); } } /** * Tests that callbacks are cleaned up when the module is disabled. */ class TaxonomyAccessCallbackCleanupTest extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Callback Cleanup', 'description' => 'Test callback cleanup during disabling of module works.', 'group' => 'Taxonomy Access Control', ); } public function setUp() { parent::setUp('taxonomy_access'); } /** * Verifies that the module's callbacks are cleaned up during disable. */ public function testCallbackCleanup() { // The problem only happens on new fields after the module is installed. $content_type = $this->drupalCreateContentType(); // Create a new field with type taxonomy_term_reference. $field_name = drupal_strtolower($this->randomName() . '_field_name'); $field_type = array( 'field_name' => $field_name, 'type' => 'taxonomy_term_reference', 'cardinality' => 1, ); $field_type = field_create_field($field_type); // Add an instance of the field to content type. $field_instance = array( 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => $content_type->name ); $field_instance = field_create_instance($field_instance); // Trigger hook_disable to see if the callbacks are cleaned up. module_disable(array('taxonomy_access'), TRUE); // Create a user so that we can check if we can access the node add pages. $this->privileged_user = $this->drupalCreateUser(array('bypass node access')); $this->drupalLogin($this->privileged_user); // If the callbacks are not cleaned up we would get a fatal error. $this->drupalGet('node/add/' . $content_type->name); $this->assertText(t('Create @name', array('@name' => $content_type->name)), t('New content can be added')); } }