This function is only used in FilterPluginBase, so shall we just move it there?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Good idea!

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.phpundefined
@@ -1390,6 +1390,19 @@ function can_group() {
+   * @param $var

probably a string?

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.phpundefined
@@ -1390,6 +1390,19 @@ function can_group() {
+  public function arrayFilterZero($var) {

Would it make sense to have a static function as you don't need any kind of values on the main object. Shouldn't this also be protected?

damiankloip’s picture

FileSize
2.61 KB

Yeah, that makes sense. I just added a static in #1912476: Move views_trim_text to FieldPluginBase as it happens.

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.phpundefined
@@ -617,7 +617,7 @@ function build_group_validate($form, &$form_state) {
+                (is_array($group['value']) && count(array_filter($group['value'], array($this, 'arrayFilterZero'))) == 0)) {

@@ -625,7 +625,7 @@ function build_group_validate($form, &$form_state) {
+              (is_array($group['value']) && count(array_filter($group['value'], array($this, 'arrayFilterZero'))) > 0)) {

you can use static::arrayFilterZero as alternative syntax

damiankloip’s picture

Not sure about protected, will we need to use this externally ever? or in tests?

dawehner’s picture

The reasons why it should be protected are the following: a) It's not something which is really useful in connection with other code, so making it public would make the object even more complicated from the outside and b) if someone needs that functionality it's a one line function to implement for their own, that's unneeded abstraction.

damiankloip’s picture

FileSize
2.6 KB

Fair point, I changed to the static too, that is better.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1912466-6.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
2.6 KB

Forgot to wrap the callables in array_filter in quotes.

This should be good to go now.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

RTBC as long it's green.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.phpundefined
@@ -1390,6 +1390,19 @@ function can_group() {
+  protected static function arrayFilterZero($var) {
+    return trim($var) != "";

I know it's just moving code around but per coding standards this could be single quotes.

I guess this makes sense as a helper function since it's used in two places, but was also wondering about just a closure?

dawehner’s picture

Status: Needs work » Needs review
FileSize
2.62 KB
612 bytes

Ups :)

damiankloip’s picture

Status: Needs review » Reviewed & tested by the community

This was RTBC before that small string quote change, that's the only thing dawehner changed. SO I think this can still be RTBC?

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

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