Commit a979093e authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Issue #3315779 by Artyom Hovasapyan, kay64, FiNeX, kristiaanvandeneynde: Weird...

Issue #3315779 by Artyom Hovasapyan, kay64, FiNeX, kristiaanvandeneynde: Weird behavior. Nodes are appearing in a group when add a member
parent dc17dbce
Loading
Loading
Loading
Loading
+31 −8
Original line number Diff line number Diff line
@@ -28,6 +28,13 @@ abstract class GroupRelationshipToEntityBase extends RelationshipPluginBase {
   */
  protected $pluginManager;

  /**
   * A list of plugins that can serve the configured entity type.
   *
   * @var \Drupal\group\Plugin\Group\Relation\GroupRelationTypeInterface[]
   */
  protected $validPlugins;

  /**
   * Constructs an GroupRelationshipToEntityBase object.
   *
@@ -91,14 +98,10 @@ abstract class GroupRelationshipToEntityBase extends RelationshipPluginBase {
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);

    // Retrieve all of the plugins that can serve this entity type.
    $options = [];
    foreach ($this->pluginManager->getDefinitions() as $plugin_id => $group_relation_type) {
      assert($group_relation_type instanceof GroupRelationTypeInterface);
      if ($group_relation_type->getEntityTypeId() === $this->getTargetEntityType()) {
    foreach ($this->getValidPlugins() as $plugin_id => $group_relation_type) {
      $options[$plugin_id] = $group_relation_type->getLabel();
    }
    }

    $form['group_relation_plugins'] = [
      '#type' => 'checkboxes',
@@ -136,12 +139,14 @@ abstract class GroupRelationshipToEntityBase extends RelationshipPluginBase {

    // Add the plugin IDs to the query if any were selected.
    $plugin_ids = array_filter($this->options['group_relation_plugins']);
    if (!empty($plugin_ids)) {

    // If none were selected, we still need to build a list of plugin IDs to
    // make sure we do not show content using plugins that do not handle the
    // entity type this views plugin was configured for.
    $def['extra'][] = [
      $this->getJoinFieldType() => 'plugin_id',
        'value' => $plugin_ids,
      'value' => $plugin_ids ?: array_keys($this->getValidPlugins()),
    ];
    }

    // Use the standard join plugin unless instructed otherwise.
    $join_id = !empty($def['join_id']) ? $def['join_id'] : 'standard';
@@ -159,4 +164,22 @@ abstract class GroupRelationshipToEntityBase extends RelationshipPluginBase {
    }
  }

  /**
   * Gets a list of plugins that can serve the entity type we're dealing with.
   *
   * @return \Drupal\group\Plugin\Group\Relation\GroupRelationTypeInterface[]
   *   The list of plugins, keyed by their plugin ID.
   */
  protected function getValidPlugins() {
    if ($this->validPlugins === NULL) {
      foreach ($this->pluginManager->getDefinitions() as $plugin_id => $group_relation_type) {
        assert($group_relation_type instanceof GroupRelationTypeInterface);
        if ($group_relation_type->getEntityTypeId() === $this->getTargetEntityType()) {
          $this->validPlugins[$plugin_id] = $group_relation_type;
        }
      }
    }
    return $this->validPlugins;
  }

}