Comments

miro_dietiker’s picture

There is a filter

class TMGMTNodeSourceViewsController extends TMGMTDefaultSourceViewsController {
...
  public function views_data() {
...
    // @todo Remove that once it has a generic implementation in the default
    // controller.
    $data['node']['tmgmt_translatable_types'] = array(
      'title' => t('Translatable types'),
      'help' => t('Filter translatable elements based on their types.'),
      'filter' => array(
        'handler' => 'views_handler_filter_in_operator',
        'real field' => 'type',
        'options callback' => 'tmgmt_source_translatable_item_types',
        'options arguments' => array($this->pluginType),
      ),
    );

It is applied as exposed filter:

$ grep -R "tmgmt_translatable_types" -n .
./sources/node/views/tmgmt_node_source_overview.view.inc:280:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['id'] = 'tmgmt_translatable_types_1';
./sources/node/views/tmgmt_node_source_overview.view.inc:281:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['table'] = 'node';
./sources/node/views/tmgmt_node_source_overview.view.inc:282:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['field'] = 'tmgmt_translatable_types';
./sources/node/views/tmgmt_node_source_overview.view.inc:283:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['ui_name'] = 'Translatable types';
./sources/node/views/tmgmt_node_source_overview.view.inc:284:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['group'] = 1;
./sources/node/views/tmgmt_node_source_overview.view.inc:285:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['exposed'] = TRUE;
./sources/node/views/tmgmt_node_source_overview.view.inc:286:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['expose']['operator_id'] = '';
./sources/node/views/tmgmt_node_source_overview.view.inc:287:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['expose']['label'] = 'Translatable types';
./sources/node/views/tmgmt_node_source_overview.view.inc:288:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['expose']['operator'] = 'tmgmt_translatable_types_1_op';
./sources/node/views/tmgmt_node_source_overview.view.inc:289:$handler->display->display_options['filters']['tmgmt_translatable_types_1']['expose']['identifier'] = 'types';

However it seems we don't filter for supported types as a static filter in the list.

miro_dietiker’s picture

Status: Active » Needs review
StatusFileSize
new1.37 KB

There's some duplicate code regarding the handler for tmgmt_translatable_types.

First let's remove the obsolete definition.
Then we'll need to introduce a new handler to always filter for the permitted types only.

berdir’s picture

Views does support having a fixed limited list + optionally allowing to expose that limited list as an exposed filter.

However, that probably doesn't really work for our case as the limited list is different for each site.

So, what we could do is make that the default behavior for our plugin. Always limit the the translatable types even if nothing is selected and limit to the selection if something is selected. Might need some adjustments in the description/settings to make that obvious.

berdir’s picture

Status: Needs review » Needs work
berdir’s picture

Priority: Normal » Major
cgalli’s picture

Status: Needs work » Needs review
StatusFileSize
new2.09 KB

here we go...

Status: Needs review » Needs work

The last submitted patch, tmgmt_1909824_filter_translatable_types.patch, failed testing.

berdir’s picture

Thanks.

+++ b/sources/node/views/handlers/tmgmt_node_handler_filter_node_translatable_types.incundefined
@@ -0,0 +1,15 @@
+<?php
+
+
+class tmgmt_node_ui_handler_filter_node_translatable_types extends views_handler_filter_in_operator{

Should have a @file docblock that says "Contains classname.".

And the class should have a docblock too that describes what it does in a short sentence.

+++ b/sources/node/views/handlers/tmgmt_node_handler_filter_node_translatable_types.incundefined
@@ -0,0 +1,15 @@
+  function query() {
+
+  $valid_types = array_keys(tmgmt_source_translatable_item_types('node'));
+
+  $this->ensure_my_table();
+
+  $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field",
+    array_values($valid_types), "in");

Missing docblock, just write {@inheritdoc} in it.

Indendation is off, code should be 2 spaces in, the } not.

+++ b/sources/node/views/tmgmt_node.views.incundefined
@@ -116,16 +116,6 @@ class TMGMTNodeSourceViewsController extends TMGMTDefaultSourceViewsController {
     // @todo Remove that once it has a generic implementation in the default
     // controller.
-    $data['node']['tmgmt_translatable_types'] = array(
-      'title' => t('Translatable types'),

The @todo can be removed too.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new22.26 KB
new4.2 KB

Turned out to be not quite that easy ;)

We need both filters. One that always enforces that only translatable types are shown and an exposed filter that allows to select one of the translatable types. I wasn't able to combine this, looks like query() isn't called on exposed filters that have no selection.

Also updated our tests to make sure we have test coverage for this and cleaned them up a bit.

cgalli’s picture

Status: Needs review » Needs work

I am getting this:

Notice: Undefined index: types in views_handler_filter->accept_exposed_input() (line 1260 of /var/www/tmgmt/sites/all/modules/views/handlers/views_handler_filter.inc).

when calling the view. cc all run, no updates neccessary

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new5.24 KB
new23.1 KB

Some improvements on the labels, as discussed with Miro.

berdir’s picture

@cgalli: You need to reset your view back to the default.

cgalli’s picture

Status: Needs review » Reviewed & tested by the community

installed and tested.

both the internal and the exposed filter seem to work.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/sources/node/ui/tmgmt_node_ui.overview.testundefined
@@ -31,20 +30,9 @@ class TMGMTNodeSourceUIOverviewTestCase extends TMGMTBaseTestCase {
+    $this->createNodeType('page', 'Page', TRANSLATION_ENABLED, FALSE);
...
+    $this->createNodeType('untranslated', 'Untranslated', 1, FALSE);

The API defines:
* @param int $language_content_type
* Flag of how the translation should be handled.
I guess it's no more a flag.

+++ b/sources/node/ui/tmgmt_node_ui.overview.testundefined
@@ -81,6 +75,8 @@ class TMGMTNodeSourceUIOverviewTestCase extends TMGMTBaseTestCase {
+    $this->assertNoText($node5->title);
+    $this->assertNoText($node6->title);

I would expect verbose description for what we test like
// Make sure content that is not translatable is not on list.

+++ b/sources/node/views/tmgmt_node.views.incundefined
@@ -59,11 +59,10 @@ class TMGMTNodeSourceViewsController extends TMGMTDefaultSourceViewsController {
     $data['node']['tmgmt_translatable_types'] = array(

@@ -114,11 +114,10 @@ class TMGMTNodeSourceViewsController extends TMGMTDefaultSourceViewsController {
+    $data['node']['tmgmt_translatable_types_exposed'] = array(

i would say
*_all
*_select
As defined with the revised label.

Rest looks fine.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new24 KB
new6.11 KB

Updated the documentation of the flag, added comments to those assertions, renamed the views fields and fixed and re-exported the view.

berdir’s picture

Status: Needs review » Fixed

Committed and pushed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.