Hi guys,

I added Views support to the to_do project and it generally works great.

Today I added support for buttons to be included in your view. The field works, except when I click on the Rearrange button (up/down arrows in the Fields box.)

What's happening is that the field is totally ignored and thus not included in the list of fields to move up and down. The problem is not just that I cannot sort the list, it's also that the buttons field is removed at the time I hit Save.

Although that's a 3rd party module, I would think that the problem is likely in the Views handling. I tried several things and it has not helped. All the other to_do fields work great, so I don't see why this one would break.

The one thing that's different from the other fields is that this one has a different database field name than its view name (i.e. 'to_do_button' in the views array versus 'to_do.priority' in the database.)

Thank you.
Alexis

Comments

AlexisWilke’s picture

Title: Rearranging skipping on of the fields » Rearranging skipping one of the fields

Fixed the title. Just to complement, I tried to add the options functions in the class, and it made no difference...

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

It would be cool if you could commit the non-working field or paste your code here.

AlexisWilke’s picture

Status: Postponed (maintainer needs more info) » Active

Dereine,

It is in the to_do project (the 6.x-1.x-dev version).

I would think that just that specific entry would not help as much because you probably will need all the environment of the to_do project to test...

The class itself is very simple:

class to_do_views_handler_field_buttons extends to_do_views_handler_field {
  function init(&$view, $options) {
    parent::init($view, $options);
    $this->additional_fields['nid'] = 'nid';
  }

  function render_name($data, $values) {
    $nid = $values->{$this->aliases['nid']};
    if ($data == TO_DO_STATUS_NOT_STARTED) {
      $action_buttons = drupal_get_form('to_do_start_button_form', $nid);
    }
    else {
      $action_buttons = drupal_get_form('to_do_finished_button_form', $nid);
    }
    return $action_buttons;
  }

  function render($values) {
    $priority = $values->{$this->field_alias};
    return $this->render_link($this->render_name($priority, $values), $values);
  }
};

It derives from this one:

class to_do_views_handler_field extends views_handler_field {
  function init(&$view, $options) {
    parent::init($view, $options);
  }

  function render_link($data, $values) {
    return $data;
  }
}

Declared in two arrays as usual. The handlers:

function to_do_views_views_handlers() {
  return array(
    [...]
      'to_do_views_handler_field_buttons' => array(
        'parent' => 'to_do_views_handler_field',
      ),
    [...]
  );
}

And the views data:

function to_do_views_views_data() {
  $data = array();

  [...]

  $data['to_do']['buttons'] = array(
    'title' => t('Buttons'),
    'help' => t('The action buttons of the To do task'),
    'field' => array(
      'field' => 'priority',
      'handler' => 'to_do_views_handler_field_buttons',
    ),
  );

  [...]

  return $data;
}
dawehner’s picture

'field' => 'priority',
This should be "real field" i think.

AlexisWilke’s picture

Dereine,

No luck.

I found a view example and it looks like the 'real field' needs to be defined right outside of the 'field' array. So I did it that way and it still does not work...

function upload_views_data_alter(&$data) {
  $data['node']['upload_fid'] = array(
    'group' => t('Upload'),
    'title' => t('Attached files'),
    'help' => t('All files attached to a node with upload.module.'),
    'real field' => 'vid',
    'field' => array(
      'handler' => 'views_handler_field_upload_fid',
      'no group by' => TRUE,
    ),
  [...]

Thank you.
Alexis

Letharion’s picture

Status: Active » Postponed (maintainer needs more info)

@AlexisWilke
I see you've gotten out a new version after this issue was touched. Have you worked this out, or do you still need help?

AlexisWilke’s picture

Status: Postponed (maintainer needs more info) » Active

@letharion,

Nope... Not fixed yet. I tried with your latest changes (Nov 8) and it still breaks.

You may want to give it a try. Install To do, create like 3 entries with random data, then create a view with To do nodes. In the fields, enter say Node title, To Do Buttons, Node Body. See that the previous shows you what you'd expect, then click on the up/down arrows of the fields. To Do Buttons does not appear!

Thank you.
Alexis

Letharion’s picture

I can reproduce the problem, but don't know what's wrong.
I'll see if I can figure something out later.

Letharion’s picture

Assigned: Unassigned » merlinofchaos

The problem is that the re-arrange part of the UI assumes that it gets text. The #type of the buttons gets set to "textfield", which breaks.

I don't think it makes sense to support buttons in the re-arrange UI, but a solution would be to pull the label from the button, prefix it with "Button: " or something similar, and display that.

@merlinofchaos
Please comment on how you suggest we solve this, and I'll try to come up with a patch :)

merlinofchaos’s picture

Priority: Minor » Normal
Status: Active » Needs review
StatusFileSize
new4.83 KB

The problem is the field id 'buttons'. Views places all fields on the form in $form[$id].

However, Views places all buttons on the form in $form['buttons']. So on the rearrange form, this data ends up overridden by buttons.

That means 'buttons', along with things like 'override', 'form_id', 'form_token' and 'form_build_id' are not going to work here. We probably just need to move everything from the top level of form into $form['fields'].

A work around is to change the id to something other than buttons, and your code will work.

Since we don't want to make those IDs invalid, here is a patch for the issue against 2.x -- could use some testing to make sure I didn't screw anything up but it seems to work ok.

AlexisWilke’s picture

StatusFileSize
new2.96 KB

I "applied" (by hand) your patch to 3.x since that's what I'm running with now and it worked!

I cannot test 2.x though since I do not have it anywhere.

Thank you.
Alexis

P.S. WARNING: This patch actually loses all the fields on a Save. I guess I only tested the click to see the window and Cancel button without trying to save the result. The fact is that right now this patch loses all the fields. More later...

AlexisWilke’s picture

Okay, I got a fix to my patch in #11. I simply don't change the submit() function. Now I thought that using the #tree would force the system to keep the tree, but it did not... In any event, by not changing the function it was perfectly.

Thank you!
Alexis Wilke

AlexisWilke’s picture

StatusFileSize
new2.54 KB

And just in case, there is a new patch without that last hunk. Thanks.

AlexisWilke’s picture

Title: Rearranging skipping one of the fields » Rearranging fields when a field is named "button" (or some other known UI item)
iamjon’s picture

Status: Needs review » Needs work
StatusFileSize
new59.83 KB
new34.32 KB

I tested merlinofchaos' patch on 2x and I'm quite sure it didn't work.

I go an error upon installing views with the patch (it could be unrelated, attached)

I generated a bunch of todos via devel generate. Made a view from AlexisWilke screenshot and had the button field dissapeared.

AlexisWilke cool module btw.

iamjon’s picture

StatusFileSize
new70.23 KB

i think it's not working in 3x too.

iamjon’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new70.05 KB
new68.58 KB

Who would have figured that you have to actually apply the patch instead of creating a new one.
Anyway, it works for both as advertised

AlexisWilke’s picture

I suppose you mean #13 works for you? 8-)

I have a problem with the v3.x patch at this point. Actually, the whole rearrange fields interface is not working right for me. So I was waiting for an update to see whether it would get fixed.

Anyway, once you confirm that #13 works for you, then I'll check it in.

Thank you.
Alexis

iamjon’s picture

Yea, both 13 and #10 work for me

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to 6.x-2.x and 6.x-3.x -- doesn't apply to 7.x.

dawehner’s picture

Status: Patch (to be ported) » Fixed

Ported to d7 and played a bit with it.

Status: Fixed » Closed (fixed)

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