You are here

public function OgComplex::otherGroupsSingle in Organic groups 8

Generating other groups auto complete element.

Parameters

int $delta: The delta of the new element. Need to be the last delta in order to be added in the end of the list.

\Drupal\Core\Entity\EntityInterface|null $entity: The entity object.

int $weight_delta: The delta of the item.

Return value

array A single entity reference input.

1 call to OgComplex::otherGroupsSingle()
OgComplex::otherGroupsWidget in src/Plugin/Field/FieldWidget/OgComplex.php
Adding the other groups widget to the form.

File

src/Plugin/Field/FieldWidget/OgComplex.php, line 294

Class

OgComplex
Plugin implementation of the 'entity_reference autocomplete' widget.

Namespace

Drupal\og\Plugin\Field\FieldWidget

Code

public function otherGroupsSingle(int $delta, ?EntityInterface $entity = NULL, $weight_delta = 10) {
  $selection_settings = [
    'other_groups' => TRUE,
    'field_mode' => 'admin',
  ];
  if ($this
    ->getFieldSetting('handler_settings')) {
    $selection_settings += $this
      ->getFieldSetting('handler_settings');
  }
  return [
    'target_id' => [
      // @todo Allow this to be configurable with a widget setting.
      '#type' => 'entity_autocomplete',
      '#target_type' => $this->fieldDefinition
        ->getFieldStorageDefinition()
        ->getSetting('target_type'),
      '#selection_handler' => 'og:default',
      '#selection_settings' => $selection_settings,
      '#default_value' => $entity,
    ],
    '_weight' => [
      '#type' => 'weight',
      '#title_display' => 'invisible',
      '#delta' => $weight_delta,
      '#default_value' => $delta,
    ],
  ];
}