You are here

protected function MappingForm::getReferenceFieldOptions in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/Form/MappingForm.php \Drupal\bibcite_entity\Form\MappingForm::getReferenceFieldOptions()

Get array of Reference field options.

Return value

array Array of fields options.

1 call to MappingForm::getReferenceFieldOptions()
MappingForm::buildForm in modules/bibcite_entity/src/Form/MappingForm.php
Form constructor.

File

modules/bibcite_entity/src/Form/MappingForm.php, line 138

Class

MappingForm
Format mapping form.

Namespace

Drupal\bibcite_entity\Form

Code

protected function getReferenceFieldOptions() {
  $fields = $this->entityFieldManager
    ->getBaseFieldDefinitions('bibcite_reference');
  $excluded_fields = [
    'id',
    'uuid',
    'langcode',
    'created',
    'changed',
    'revision_id',
    'revision_created',
    'revision_user',
    'revision_log_message',
    'status',
    'revision_default',
    'path',
    'metatag',
  ];
  $options = array_map(function ($field) {

    /** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
    return $field
      ->getLabel();
  }, array_diff_key($fields, array_flip($excluded_fields)));

  // Sort options alphabetically.
  asort($options);

  // But 'Reference type' and 'Title' fields should go first.
  $options = [
    'type' => $options['type'],
    'title' => $options['title'],
  ] + $options;
  return $options;
}