Support from Acquia helps fund testing for Drupal Acquia logo

Comments

casey’s picture

Should have tested the changes.

typehints are also useful as a test for improper hook implementations. I found out that hook_views_query_substitutions() was missing an argument and that views_plugin_query_default#query() was passing the wrong argument; itself instead of $view. views_plugin_query_default#execute() invokes the same hook but passes $view and the implementation user_views_query_substitutions() has $view as an argument.

Another, somewhat untidy but not disastrous, thing is that views_handler#init() sets a reference on $view->query, while that property doesn't contain an object yet. So I kept the reference indicator there, but added a comment.

Now I used 'view' and 'view_display' as typehint but it might be nicer to have an interface. You never know if someone wants to use its own view class.

dawehner’s picture

In general this is cool, but doesn't this lead to notices?

casey’s picture

I am not entirely sure where you expect notices from?

dawehner’s picture

If someone else extends

+  function init(view $view, &$options) {

the signature changes. We had this thousand times when porting to drupal7.

casey’s picture

Oww of course. Well then I am not sure if it is a good idea. You decide :)

dawehner’s picture

No idea whether it cause notices or not, but just want to be sure about it :)

casey’s picture

Yes it will. Thats a good thing, but not very much in our case as all contrib modules indeed need to be updated as well.

bojanz’s picture

I think it's too late in the release cycle to break all contrib handler implementations :/

But the patch has plenty of nice fixes that don't (shouldn't) break anything. Let's at least get that in.

bojanz’s picture

Rerolled.

bojanz’s picture

Reverted one wrong change caught by dereine (don't typehint $views)

dawehner’s picture

Status: Needs review » Needs work
+++ b/docs/views.api.phpundefined
@@ -588,7 +588,7 @@ function hook_views_form_submit($form, &$form_state) {
+function hook_views_pre_view(view $view, $display_id, &$args) {

display_id isn't a object, so it shouldn't be changed.

+++ b/includes/handlers.incundefined
@@ -1012,7 +1012,7 @@ class views_many_to_one_helper {
+function views_break_phrase_string($str, $handler = NULL) {

@@ -1065,7 +1065,7 @@ function views_break_phrase_string($str, &$handler = NULL) {
+function views_break_phrase($str, $handler = NULL) {

I personally like the & sign here, because it shows that this will be altered, as php doesn't have a const keyword, but i'm open for doing the change.

bojanz’s picture

Status: Needs work » Needs review

display_id isn't a object, so it shouldn't be changed.

Read the line again, I'm not touching $display_id :)

As for &$handler, the phpdoc above it says:

 * @param $handler
 *   The handler object to use as a base.

so it should be obvious enough.

dawehner’s picture

FileSize
9.33 KB

Word-diff doesn't lie :)

so it should be obvious enough.

Good point

bojanz’s picture

You're right, I suck :)

bojanz’s picture

Reroll.

dawehner’s picture

Status: Needs review » Fixed

Huge thanks here! Commited to 7.x-3.x

bojanz’s picture

Status: Fixed » Needs review
FileSize
1.49 KB

So I'm stupid tonight, which makes me wonder why I'm attempting patches this big.

bojanz’s picture

FileSize
2.06 KB

Removed an old comment as well.

bojanz’s picture

So we had to revert the whole thing....

Here's a patch from scratch. Probably needs work. Sigh.

dawehner’s picture

This is a change from another patch, which shouldn't be done here.

     // We're not changing which display these form values apply to.
     // Run the regular submit handler for this form.
   }
   elseif ($was_defaulted && !$is_defaulted) {
     // We were using the default display's values, but we're now overriding
     // the default display and saving values specific to this display.
-    $display = &$form_state['view']->display[$form_state['display_id']];
+    $display = $form_state['view']->display[$form_state['display_id']];
     $display->handler->options_override($form, $form_state);
     $display->handler->options_submit($form, $form_state);
   }
@@ -2490,7 +2499,7 @@ function views_ui_standard_submit($form, &$form_state) {
     // to go back to the default display.
     // Overwrite the default display with the current form values, and make
     // the current display use the new default values.
-    $display = &$form_state['view']->display[$form_state['display_id']];
+    $display = $form_state['view']->display[$form_state['display_id']];
     $display->handler->options_override($form, $form_state);
     $display->handler->options_submit($form, $form_state);
   }
dawehner’s picture

Status: Needs review » Needs work
+++ b/includes/admin.incundefined
@@ -2034,7 +2034,7 @@ function views_ui_import_validate($form, &$form_state) {
 
-  $form_state['view'] = &$view;
+  $form_state['view'] = $view;

This is still wrong here...

+++ b/includes/admin.incundefined
@@ -2545,7 +2545,7 @@ function views_ui_standard_cancel($form, &$form_state) {
-  $view = &$form_state['view'];

dito

Don't do any risk thing here.

bojanz’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev

This cleanup makes sense in 8.x-3.x.
I realize much of the code will be touched, cleaned-up and reworked, but this is a simple enough (if not frustrating) change to do upfront.

tim.plunkett’s picture

Issue tags: +VDC
dawehner’s picture

Status: Needs work » Closed (duplicate)