diff --git a/metatag.metatag.inc b/metatag.metatag.inc index f1ca5e0..9d46a9f 100644 --- a/metatag.metatag.inc +++ b/metatag.metatag.inc @@ -110,13 +110,13 @@ function metatag_metatag_config_instance_info() { $entity_types = entity_get_info(); foreach ($entity_types as $entity_type => $entity_info) { if (metatag_entity_type_is_suitable($entity_type, $entity_info)) { - $info[$entity_type] = array('label' => $entity_info['label'], 'entity' => TRUE); + $info[$entity_type] = array('label' => $entity_info['label']); foreach ($entity_info['bundles'] as $bundle => $bundle_info) { if (count($entity_info['bundles'] == 1) && $bundle == $entity_type) { // Skip default bundles (entities that do not really have bundles). continue; } - $info[$entity_type . ':' . $bundle] = array('label' => $bundle_info['label'], 'entity' => TRUE); + $info[$entity_type . ':' . $bundle] = array('label' => $bundle_info['label']); } } } diff --git a/metatag.module b/metatag.module index 4fa3c62..1758e00 100644 --- a/metatag.module +++ b/metatag.module @@ -1489,19 +1489,21 @@ function metatag_entity_supports_metatags($entity_type = NULL, $bundle = NULL) { * * @param string $entity_type * @param string $bundle + * + * @deprecated */ function metatag_entity_type_enable($entity_type, $bundle = NULL) { - // The bundle was defined. + $disabled = variable_get('default_metatag_config', array()); + if (isset($bundle)) { - variable_set('metatag_enable_' . $entity_type . '__' . $bundle, TRUE); + $disabled["$entity_type:$bundle"] = FALSE; + } + else { + $disabled["$entity_type"] = FALSE; } - // Always enable the entity type, because otherwise there's no point in - // enabling the bundle. - variable_set('metatag_enable_' . $entity_type, TRUE); - - // Clear the static cache so that the entity type / bundle will work. - drupal_static_reset('metatag_entity_supports_metatags'); + variable_set('default_metatag_config', $disabled); + metatag_config_cache_clear(); } /** @@ -1509,19 +1511,21 @@ function metatag_entity_type_enable($entity_type, $bundle = NULL) { * * @param string $entity_type * @param string $bundle + * + * @deprecated */ function metatag_entity_type_disable($entity_type, $bundle = NULL) { - // The bundle was defined. + $disabled = variable_get('default_metatag_config', array()); + if (isset($bundle)) { - variable_set('metatag_enable_' . $entity_type . '__' . $bundle, FALSE); + $disabled["$entity_type:$bundle"] = TRUE; } - // The bundle was not defined. else { - variable_set('metatag_enable_' . $entity_type, FALSE); + $disabled["$entity_type"] = TRUE; } - // Clear the static cache so that the entity type / bundle will work. - drupal_static_reset('metatag_entity_supports_metatags'); + variable_set('default_metatag_config', $disabled); + metatag_config_cache_clear(); } /** @@ -2561,48 +2565,6 @@ function metatag_entity_type_is_suitable($entity_type, $entity_info = array()) { } /** - * Implements hook_node_type_insert(). - * - * When a content type is created, enable it for use with Metatag. - */ -function metatag_node_type_insert($info) { - if (metatag_entity_supports_metatags('node')) { - metatag_entity_type_enable('node', $info->type); - drupal_set_message(t('Metatag support has been enabled for the @label content type.', array('@label' => $info->name))); - } -} - -/** - * Implements hook_node_type_delete(). - * - * When a content type is deleted, remove the corresponding Metatag variable. - */ -function metatag_node_type_delete($info) { - variable_del('metatag_enable_node__' . $info->type); -} - -/** - * Implements hook_taxonomy_vocabulary_insert(). - * - * When a vocabulary is created, enable it for use with Metatag. - */ -function metatag_taxonomy_vocabulary_insert($vocabulary) { - if (metatag_entity_supports_metatags('taxonomy_term')) { - metatag_entity_type_enable('taxonomy_term', $vocabulary->machine_name); - drupal_set_message(t('Metatag support has been enabled for the @label vocabulary.', array('@label' => $vocabulary->name))); - } -} - -/** - * Implements hook_taxonomy_vocabulary_delete(). - * - * When a vocabulary is deleted, remove the corresponding Metatag variable. - */ -function metatag_taxonomy_vocabulary_delete($info) { - variable_del('metatag_enable_taxonomy_term__' . $info->machine_name); -} - -/** * Implements hook_workbench_moderation_transition(). * * Clear a node's caches when its Workbench Moderation state is changed. diff --git a/tests/metatag.helper.test b/tests/metatag.helper.test index 368b6f4..f023ed8 100644 --- a/tests/metatag.helper.test +++ b/tests/metatag.helper.test @@ -37,9 +37,6 @@ class MetatagTestHelper extends DrupalWebTestCase { 'name' => $label, )); - // Enable meta tags for this new content type. - metatag_entity_type_enable('node', $machine_name); - return $content_type; } @@ -117,9 +114,6 @@ class MetatagTestHelper extends DrupalWebTestCase { $vocabulary->weight = mt_rand(0, 10); taxonomy_vocabulary_save($vocabulary); - // Enable meta tags for this new vocabulary. - metatag_entity_type_enable('taxonomy_term', $vocab_name); - return $vocabulary; } diff --git a/tests/metatag.unit.test b/tests/metatag.unit.test index 3f5d0c6..1d7237b 100644 --- a/tests/metatag.unit.test +++ b/tests/metatag.unit.test @@ -68,24 +68,47 @@ class MetatagUnitTest extends MetatagTestHelper { } public function testEntitySupport() { + // Create an empty config for the node types so that we can disable them. + $config = new stdClass(); + $config->instance = 'node:article'; + $config->config = array(); + metatag_config_save($config); + $config = new stdClass(); + $config->instance = 'node:page'; + $config->config = array(); + metatag_config_save($config); + + $test_cases[0] = array('type' => 'node', 'expected' => TRUE); $test_cases[1] = array('type' => 'node', 'bundle' => 'article', 'expected' => TRUE); $test_cases[2] = array('type' => 'node', 'bundle' => 'page', 'expected' => TRUE); $test_cases[3] = array('type' => 'node', 'bundle' => 'invalid-bundle', 'expected' => FALSE); $test_cases[4] = array('type' => 'user', 'expected' => TRUE); - $test_cases[5] = array('type' => 'taxonomy_term', 'bundle' => 'tags', 'expected' => TRUE); - $test_cases[6] = array('type' => 'taxonomy_term', 'bundle' => 'invalid-bundle', 'expected' => FALSE); + $test_cases[5] = array('type' => 'taxonomy_term', 'expected' => TRUE); + $test_cases[6] = array('type' => 'taxonomy_term', 'bundle' => 'tags', 'expected' => TRUE); + $test_cases[7] = array('type' => 'taxonomy_term', 'bundle' => 'invalid-bundle', 'expected' => FALSE); foreach ($test_cases as $test_case) { $test_case += array('bundle' => NULL); $this->assertMetatagEntitySupportsMetatags($test_case['type'], $test_case['bundle'], $test_case['expected']); } - // Enable meta tags for this new content type. metatag_entity_type_disable('node', 'page'); metatag_entity_type_disable('user'); $test_cases[2]['expected'] = FALSE; $test_cases[4]['expected'] = FALSE; + foreach ($test_cases as $test_case) { + $test_case += array('bundle' => NULL); + $this->assertMetatagEntitySupportsMetatags($test_case['type'], $test_case['bundle'], $test_case['expected']); + } + + metatag_entity_type_disable('node', 'article'); + metatag_entity_type_disable('taxonomy_term'); + + $test_cases[0]['expected'] = FALSE; + $test_cases[1]['expected'] = FALSE; + $test_cases[5]['expected'] = FALSE; $test_cases[6]['expected'] = FALSE; + $test_cases[7]['expected'] = FALSE; foreach ($test_cases as $test_case) { $test_case += array('bundle' => NULL); $this->assertMetatagEntitySupportsMetatags($test_case['type'], $test_case['bundle'], $test_case['expected']); @@ -93,7 +116,6 @@ class MetatagUnitTest extends MetatagTestHelper { } function assertMetatagEntitySupportsMetatags($entity_type, $bundle, $expected) { - $entity = entity_create_stub_entity($entity_type, array(0, NULL, $bundle)); return $this->assertEqual( metatag_entity_supports_metatags($entity_type, $bundle), $expected,