Skip to content

Conversation

@agentrickard
Copy link
Owner

This is a work-in-progress.

To my understanding, to make the Workbench Access filter work with Content Moderation, we have to be able to filter on content revisions. This starts that work, but the logic in Drupal\workbench_access\Plugin\views\filter\Section::query() will need to be updated to account for the tables.

Copy link
Collaborator

@larowlan larowlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me - need tests?

@agentrickard
Copy link
Owner Author

Yes. It also breaks if you apply it to Content Revisions, so I need to take some time to write smart tests for it -- though likely just working example Views.

@agentrickard
Copy link
Owner Author

I played around with this a bunch, and I guess I'm confused about what tables we ought to be using.

This filter breaks when used directly with a 'content revision'. If it 'gets the actual value from a content revision' it works fine.

@pavlosdan
Copy link

pavlosdan commented Nov 9, 2018

Had a need for this and looking around the issue queue led me here. @agentrickard thanks for getting the ball rolling. I adapted the code in the getViewsJoin() function as below which got this working for us. I am not sure how to open a PR on an already existing PR so attaching the updated function here.

public function getViewsJoin($entity_type, $key, $alias = NULL) {
    if ($entity_type == 'user') {
      $configuration['taxonomy'] = [
        'table' => 'section_association__user_id',
        'field' => 'user_id_target_id',
        'left_table' => 'users',
        'left_field' => $key,
        'operator' => '=',
        'table_alias' => 'section_association__user_id',
        'real_field' => 'entity_id',
      ];
      return $configuration;
    }
    $fields = array_column(array_filter($this->configuration['fields'], function ($field) use ($entity_type) {
      return isset($field['entity_type']) && $field['entity_type'] === $entity_type;
    }), 'field');
    $table_prefix = $entity_type;
    $field_suffix = '_target_id';

    $entity_type_definition = $this->entityTypeManager->getDefinition($entity_type);
    $entity_revision_table = $entity_type_definition->getRevisionTable();
    $supports_revisions = $entity_type_definition->hasKey('revision') && $entity_revision_table;

    $configuration = [];
    foreach ($fields as $field) {
      $configuration[$field] = [
        'table' => ($supports_revisions && $alias === $entity_revision_table) ? $table_prefix . '_revision__' . $field : $table_prefix . '__' . $field,
        'field' => ($supports_revisions && $alias === $entity_revision_table) ? 'revision_id' : 'entity_id',
        'left_table' => ($supports_revisions && $alias === $entity_revision_table) ? $entity_revision_table : $entity_type,
        'left_field' => ($supports_revisions && $alias === $entity_revision_table) ? $entity_type_definition->getKey('revision') : $key,
        'operator' => '=',
        'table_alias' => $field,
        'real_field' => $field . $field_suffix,
      ];
    }

    return $configuration;
  }

Please let me know your thoughts on this.

@pavlosdan
Copy link

Not sure what went wrong with the code formatting but the piece of code to note is the one in the code box :)

@agentrickard
Copy link
Owner Author

Try using three backticks around the code elements.

You can also run a PR by basing your fork off the views-revisions branch.

@pavlosdan
Copy link

aaaah 3 backticks works. thanks! TIL :)

I've posted a patch here as I wasn't sure: https://www.drupal.org/project/workbench_access/issues/2979637#comment-12851737

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants