- 🇩🇰Denmark Birk
I have a view I can't "reverse" as well, has anyone had any luck getting VBO working with relationships?
(A hack would work for me as well)
- 🇵🇱Poland Graber
Damn, it used to work with relationships before the base_id was introduced. Didn't realize that was broken then and only now noticed this issue. We'd have to map base_id from bulk form keys to the correct entity_id using the relationship in the action processor.
I'm afraid nobody will take the workload to implement it though looking at the issue activity..
If someone really needs a feature that doesn't have many followers I guess the only option is to sponsor the development or just do it themselves.
- 🇩🇰Denmark Birk
I've been looking into this a bit, and it seems relationships is almost supported (and I'm sorry if my observations below is all over the place, I'm just brainstorming out loud).
Like Graber stated the relationship needs to map to the correct keys, which is here: https://git.drupalcode.org/project/views_bulk_operations/-/blob/7a991c4c...
$base_field_values = []; foreach ($batch_list as $item) { $base_field_values[$item[0]] = $item[0]; }
The
item[0]
is the base ID, but the seems theViewsBulkOperationsViewData::getEntity()
already supports relationship and gets the correct entity, it's inserted in$item[3]
.So by simply changing the
$base_field_alias
to the field alias of the relationship it should work.I'm making the assumption that the table alias is
[relationship base]_[relationship_id]
, I'm doing this because I can't find a reliable way of getting the table from a relationship. So if I rewrite the code inViewsBulkOperationsActionProcessor::popuplateQueue()
to this:if (empty($this->bulkFormData['relationship_id'])) { if (isset($this->view->query->fields[$base_field])) { if (!empty($this->view->query->fields[$base_field]['table'])) { $base_field_alias = $this->view->query->fields[$base_field]['table'] . '.' . $this->view->query->fields[$base_field]['alias']; } else { $base_field_alias = $this->view->query->fields[$base_field]['alias']; } } else { $base_field_alias = $base_field; } } else { $viewsData = Views::viewsData(); $relationship = $this->view->getDisplay()->getOption('relationships')[$this->bulkFormData['relationship_id']]; $table_data = $viewsData->get($relationship['table']); $relationship_table_alias = $table_data[$relationship['field']]['relationship']['base'] . '_' . $relationship['table']; $base_field_alias = $relationship_table_alias . '.' . $table_data[$relationship['field']]['relationship']['base field']; }
It seems to work in my particular case.
I know this is a hot mess, it's a hack that did it for my use case. Maybe a proper fix is not that far away, the current project I'm working on just don't allow me to spend the time I need to dig any deeper.
- 🇦🇺Australia sime Melbourne
I was wondering why my user action was not appearing when it there was clearly a base user table in my view through a relationship. Now I have an action that must have no "type" in order to be available to add to bulk operations, and the action itself must go through hoops to work out how to get to the entity IDs it wants to operate on.
I'd like to call this a serious bug.