You are here

protected function CorrespondingReferenceForm::getBundleOptions in Corresponding Entity References 8.4

Gets an array of bundle options to populate in the form.

Return value

array An array of bundle options.

1 call to CorrespondingReferenceForm::getBundleOptions()
CorrespondingReferenceForm::form in src/Form/CorrespondingReferenceForm.php
Gets the actual form array to be built.

File

src/Form/CorrespondingReferenceForm.php, line 191

Class

CorrespondingReferenceForm
Form handler for corresponding reference add and edit forms.

Namespace

Drupal\cer\Form

Code

protected function getBundleOptions() {

  /** @var CorrespondingReferenceInterface $correspondingReference */
  $correspondingReference = $this->entity;
  $correspondingFields = $correspondingReference
    ->getCorrespondingFields();
  $options = [];
  foreach ($this
    ->getReferenceFieldMap() as $entityType => $entityTypeFields) {
    $includeType = FALSE;
    foreach ($entityTypeFields as $fieldName => $field) {
      if (!empty($correspondingFields) && !in_array($fieldName, $correspondingFields)) {
        continue;
      }
      if (!preg_match('/^field_.*$/', $fieldName)) {
        continue;
      }
      $includeType = TRUE;
      foreach ($field['bundles'] as $bundle) {
        $options["{$entityType}:{$bundle}"] = "{$entityType}: {$bundle}";
      }
    }
    if ($includeType) {
      $options["{$entityType}:*"] = "{$entityType}: *";
    }
  }
  ksort($options);
  return $options;
}