You are here

public function RelationRelationship::buildOptionsForm in Relation 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/relationship/RelationRelationship.php \Drupal\relation\Plugin\views\relationship\RelationRelationship::buildOptionsForm()

Let the user choose r_index.

Overrides RelationshipPluginBase::buildOptionsForm

File

src/Plugin/views/relationship/RelationRelationship.php, line 36
Views relationship support.

Class

RelationRelationship
Relate entities using a Relation endpoint.

Namespace

Drupal\relation\Plugin\views\relationship

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);

  // Check if this relation is entity-to-entity or entity-to-relation /
  // relation-to-entity.
  $endpoints_twice = isset($this->definition['entity_type_left']) && isset($this->definition['entity_type_right']);
  if ($this->definition['directional']) {
    $form['r_index'] = array(
      '#type' => 'select',
      '#options' => array(
        -1 => t('Any'),
        0 => t('Source'),
        1 => t('Target'),
      ),
      '#title' => t('Position of the relationship base'),
      '#default_value' => $this->options['r_index'],
      // check_plain()'d in the definition.
      '#description' => t('Select whether the entity you are adding the relationship to is source or target of @relation_type_label relation.', array(
        '@relation_type_label' => $this->definition['label'],
      )),
    );
  }
  foreach (array(
    'left',
    'right',
  ) as $key) {
    if (isset($this->definition['entity_type_' . $key])) {
      $form['entity_deduplication_' . $key] = array(
        '#type' => 'checkbox',
        '#title' => $endpoints_twice ? t('Avoid @direction @type duplication', array(
          '@direction' => t($key),
          '@type' => $this->definition['entity_type_' . $key],
        )) : t('Avoid @type duplication', array(
          '@type' => $this->definition['entity_type_' . $key],
        )),
        '#default_value' => $this->options['entity_deduplication_' . $key],
        '#description' => t('When creating a chain of Views relationships for example from node to relation and then from relation to node (both via the same relation type) then each node will display on both ends. Check this option to avoid this kind of duplication.'),
      );
    }
  }
}