You are here

public function Drupal8::addFieldSettings in Realistic Dummy Content 8.2

Same name and namespace in other branches
  1. 7.2 api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::addFieldSettings()
  2. 3.x api/src/Framework/Drupal8.php \Drupal\realistic_dummy_content_api\Framework\Drupal8::addFieldSettings()

Adds field settings if possible.

Parameters

array $return: An array of fields to modify.

string $field: A field name.

array $field_info: Information about the field.

1 call to Drupal8::addFieldSettings()
Drupal8::fieldInfoFields in api/src/Framework/Drupal8.php

File

api/src/Framework/Drupal8.php, line 181

Class

Drupal8
Drupal 8-specific code.

Namespace

Drupal\realistic_dummy_content_api\Framework

Code

public function addFieldSettings(&$return, $field, $field_info) {
  if ($field_info['type'] == 'entity_reference') {
    if (isset($field_info['bundles']) && count($field_info['bundles'])) {
      $bundle = array_pop($field_info['bundles']);
      $config = FieldConfig::loadByName('node', $bundle, $field);
      if ($config) {
        $settings = $config
          ->getSettings();
        if (isset($settings['handler_settings']['target_bundles'])) {
          foreach ($settings['handler_settings']['target_bundles'] as $target) {
            $return[$field]['settings']['allowed_values'][] = array(
              'vocabulary' => $target,
            );
          }
        }
      }
    }
  }
}