2

I created a custom VBO action to change a value in the selected item. I have the button displayed as "hide item". When I activate it on the item it doesn't seem to fire and change the value at all. I did a test to change the name to xxxxx and visible to 0, but it doesn't look like its working. Maybe my code is wrong?

It does seem like its working as I output the result in the set_message function (in green box in screenshot). 1 indicates that 1 row has been affected, but i still see the item on my View and the name hasn't even changed.

Maybe something is off here?

Module Code:

function office_action_info() {
  return array(
    'action_off' => array(
      'type' => 'entity',
      'label' => t('Hide Item'),
      'configurable' => FALSE,
      'behavior' => array('changes_property'),
      'triggers' => array('any'),
    ),
  );
}

function action_off($entity, $context = array()) {


$blah = db_update('office')
->fields(array(
    'verified' => 0,
    'name' => 'xxxxxxx',
))
->condition('office_id', $entity->office_id, '=')
->execute();


drupal_set_message($blah .'====='. $entity->name .'===='. $entity->office_id);
}

enter image description here

enter image description here

10
  • What's your structure of database table office? Can you show me pictures of it?
    – MrD
    Commented Nov 2, 2015 at 9:15
  • Also, please don't provide screenshot of code; code is simple text.
    – avpaderno
    Commented Nov 2, 2015 at 9:55
  • embeded code. and also gave a view of the database structure with sample data. Commented Nov 2, 2015 at 14:19
  • So since you're working with a custom office entity, perhaps it will have same problems with caching as node? Have you tried entity_get_controller('office')->resetCache(array($entity->office_id));
    – Beebee
    Commented Nov 2, 2015 at 15:27
  • You could also try using the entity api in the action_off function. Simply entity_load then modify the values and then do entity_save.
    – Beebee
    Commented Nov 2, 2015 at 15:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.