entity_agree-2.0.x-dev/src/Plugin/views/relationship/AgreementRelationship.php
src/Plugin/views/relationship/AgreementRelationship.php
<?php namespace Drupal\entity_agree\Plugin\views\relationship; use Drupal\Core\Form\FormStateInterface; use Drupal\entity_agree\Plugin\views\AgreementViewsPluginTrait; use Drupal\views\Plugin\views\relationship\RelationshipPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Relationship handler to return the taxonomy terms of nodes. * * @ViewsRelationship("entity_agree_agreement") */ class AgreementRelationship extends RelationshipPluginBase { use AgreementViewsPluginTrait; /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { $relationship = parent::create($container, $configuration, $plugin_id, $plugin_definition); $relationship->agreementManager = $container->get('entity_agree.agreement_manager'); $relationship->entityRepository = $container->get('entity.repository'); return $relationship; } /** * {@inheritdoc} */ public function defineOptions() { return $this->defineAgreementOption(parent::defineOptions()); } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { $form['agreement'] = $this->buildAgreementOptionElement($this->options['agreement']); parent::buildOptionsForm($form, $form_state); } /** * {@inheritdoc} */ public function validate() { return $this->validateAgreement(); } /** * {@inheritdoc} */ public function query() { if (!$agreement = $this->getAgreementEntity()) { return; } $this->ensureMyTable(); $def = $this->definition; $def['table'] = $this->definition['base']; $def['field'] = 'uid'; $def['left_table'] = $this->tableAlias; $def['left_field'] = $this->realField; $def['adjusted'] = TRUE; if (!empty($this->options['required'])) { $def['type'] = 'INNER'; } $def['extra'] = [ ['field' => 'entity_type_id', 'value' => $agreement->getEntityTypeId()], ['field' => 'entity_vid', 'value' => $agreement->getRevisionId()], ]; $join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $def); $alias = $def['table'] . '_' . $this->table; $this->alias = $this->query->addRelationship($alias, $join, $this->definition['base'], $this->relationship); } }