From c4c71f4c77861bd8c96604481f7c87ad9be828e9 Mon Sep 17 00:00:00 2001 From: webchick Date: Tue, 29 Jan 2013 08:06:25 -0800 Subject: [PATCH] Revert "Issue #1891214 by damiankloip: Introduce a generic entity bundle filter handler." Broke HEAD. Temporary rollback. This reverts commit 44cedfab94890c37e3ae7768fc578437ce980213. --- .../Drupal/node/Plugin/views/filter/Type.php | 38 ++++++ core/modules/node/node.views.inc | 2 +- .../Plugin/views/filter/VocabularyVid.php | 37 ++++++ core/modules/taxonomy/taxonomy.views.inc | 2 +- .../views/Plugin/views/filter/Bundle.php | 79 ------------ .../Tests/Entity/FilterEntityBundleTest.php | 117 ------------------ .../views.view.test_entity_type_filter.yml | 82 ------------ 7 files changed, 77 insertions(+), 280 deletions(-) create mode 100644 core/modules/node/lib/Drupal/node/Plugin/views/filter/Type.php create mode 100644 core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php delete mode 100644 core/modules/views/lib/Drupal/views/Plugin/views/filter/Bundle.php delete mode 100644 core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php delete mode 100644 core/modules/views/tests/views_test_config/test_views/views.view.test_entity_type_filter.yml diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/filter/Type.php b/core/modules/node/lib/Drupal/node/Plugin/views/filter/Type.php new file mode 100644 index 00000000000..87f70051d73 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Plugin/views/filter/Type.php @@ -0,0 +1,38 @@ +value_options)) { + $this->value_title = t('Content types'); + $types = node_type_get_types(); + $options = array(); + foreach ($types as $type => $info) { + $options[$type] = t($info->name); + } + asort($options); + $this->value_options = $options; + } + } + +} diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index e83232e16c7..d3fb851458b 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -125,7 +125,7 @@ function node_views_data() { 'id' => 'standard', ), 'filter' => array( - 'id' => 'bundle', + 'id' => 'node_type', ), 'argument' => array( 'id' => 'node_type', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php new file mode 100644 index 00000000000..bfa55a2bd67 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php @@ -0,0 +1,37 @@ +value_options)) { + return; + } + + $this->value_options = array(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + foreach ($vocabularies as $voc) { + $this->value_options[$voc->id()] = $voc->label(); + } + } + +} diff --git a/core/modules/taxonomy/taxonomy.views.inc b/core/modules/taxonomy/taxonomy.views.inc index 0644f82f500..d683d68c8fd 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -145,7 +145,7 @@ function taxonomy_views_data() { 'title' => t('Vocabulary'), 'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'), 'filter' => array( - 'id' => 'bundle', + 'id' => 'vocabulary_vid', ), ); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/filter/Bundle.php b/core/modules/views/lib/Drupal/views/Plugin/views/filter/Bundle.php deleted file mode 100644 index 5a7d6815098..00000000000 --- a/core/modules/views/lib/Drupal/views/Plugin/views/filter/Bundle.php +++ /dev/null @@ -1,79 +0,0 @@ -entityType = $this->getEntityType(); - $this->entityInfo = entity_get_info($this->entityType); - $this->real_field = $this->entityInfo['entity_keys']['bundle']; - } - - /** - * Overrides \Drupal\views\Plugin\views\filter\InOperator::get_value_options(). - */ - public function get_value_options() { - if (!isset($this->value_options)) { - $types = $this->entityInfo['bundles']; - $this->value_title = t('@entity types', array('@entity' => $this->entityInfo['label'])); - - $options = array(); - foreach ($types as $type => $info) { - $options[$type] = $info['label']; - } - - asort($options); - $this->value_options = $options; - } - - return $this->value_options; - } - - /** - * Overrides \Drupal\views\Plugin\views\filter\InOperator::query(). - */ - public function query() { - // Make sure that the entity base table is in the query. - $this->ensureMyTable(); - parent::query(); - } - -} diff --git a/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php deleted file mode 100644 index 031d601c651..00000000000 --- a/core/modules/views/lib/Drupal/views/Tests/Entity/FilterEntityBundleTest.php +++ /dev/null @@ -1,117 +0,0 @@ - 'Filter: Entity bundle', - 'description' => 'Tests the generic entity bundle filter.', - 'group' => 'Views Handlers', - ); - } - - public function setUp() { - parent::setUp(); - - $this->drupalCreateContentType(array('type' => 'test_bundle')); - $this->drupalCreateContentType(array('type' => 'test_bundle_2')); - - $this->entityInfo = entity_get_info('node'); - - $this->entities['count'] = 0; - - foreach ($this->entityInfo['bundles'] as $key => $info) { - for ($i = 0; $i < 5; $i++) { - $entity = entity_create('node', array('label' => $this->randomName(), 'uid' => 1, 'type' => $key)); - $entity->save(); - $this->entities[$key][$entity->id()] = $entity; - $this->entities['count']++; - } - } - } - - /** - * Tests the generic bundle filter. - */ - public function testFilterEntity() { - $view = views_get_view('test_entity_type_filter'); - $this->executeView($view); - - // Test we have all the results, with all types selected. - $this->assertEqual(count($view->result), $this->entities['count']); - - // Test the value_options of the filter handler. - $expected = array(); - - foreach ($this->entityInfo['bundles'] as $key => $info) { - $expected[$key] = $info['label']; - } - $this->assertIdentical($view->filter['type']->get_value_options(), $expected); - - $view->destroy(); - - // Test each bundle type. - foreach ($this->entityInfo['bundles'] as $key => $info) { - // Test each bundle type. - $view->initDisplay(); - $filters = $view->display_handler->getOption('filters'); - $filters['type']['value'] = drupal_map_assoc(array($key)); - $view->display_handler->setOption('filters', $filters); - $this->executeView($view); - - $this->assertEqual(count($view->result), count($this->entities[$key])); - - $view->destroy(); - } - - // Test an invalid bundle type to make sure we have no results. - $view->initDisplay(); - $filters = $view->display_handler->getOption('filters'); - $filters['type']['value'] = drupal_map_assoc(array('type_3')); - $view->display_handler->setOption('filters', $filters); - $this->executeView($view); - - $this->assertEqual(count($view->result), 0); - } - -} diff --git a/core/modules/views/tests/views_test_config/test_views/views.view.test_entity_type_filter.yml b/core/modules/views/tests/views_test_config/test_views/views.view.test_entity_type_filter.yml deleted file mode 100644 index 086afb9ca48..00000000000 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_entity_type_filter.yml +++ /dev/null @@ -1,82 +0,0 @@ -base_table: node -core: '8' -description: '' -disabled: '0' -display: - default: - display_plugin: default - id: default - display_title: Master - position: '0' - display_options: - fields: - nid: - id: nid - table: node - field: nid - relationship: none - type: - id: type - table: node - field: type - relationship: none - group_type: group - admin_label: '' - label: Type - exclude: '0' - alter: - alter_text: '0' - text: '' - make_link: '0' - path: '' - absolute: '0' - external: '0' - replace_spaces: '0' - path_case: none - trim_whitespace: '0' - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: '0' - max_length: '' - word_boundary: '1' - ellipsis: '1' - more_link: '0' - more_link_text: '' - more_link_path: '' - strip_tags: '0' - trim: '0' - preserve_tags: '' - html: '0' - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: '1' - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: '1' - empty: '' - hide_empty: '0' - empty_zero: '0' - hide_alter_empty: '1' - defaults: - fields: '0' - filters: '0' - filters: - type: - id: type - table: node - field: type - relationship: none - value: - all: all - test_bundle: test_bundle - test_bundle_2: test_bundle_2 -human_name: '' -id: test_entity_type_filter -tag: '' -base_field: nid