You are here

private function SiteSettingsLoader::getValues in Site Settings and Labels 8

Get the values from the entity and return in as simple an array possible.

Parameters

object $entity: Field Entity.

Return value

mixed The values.

1 call to SiteSettingsLoader::getValues()
SiteSettingsLoader::buildSettings in src/SiteSettingsLoader.php
Build the settings array.

File

src/SiteSettingsLoader.php, line 176

Class

SiteSettingsLoader
Class SiteSettingsLoader.

Namespace

Drupal\site_settings

Code

private function getValues($entity) {
  $build = [];
  $fields = $entity
    ->getFields();
  foreach ($fields as $key => $field) {

    /** @var \Drupal\Core\Field\FieldItemInterface $field */

    /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
    $field_definition = $field
      ->getFieldDefinition();

    // Exclude fields on the object that are base config.
    if (!method_exists(get_class($field_definition), 'isBaseField') || !$field_definition
      ->isBaseField()) {
      if (($value = $this
        ->getValue($field)) || $field_definition
        ->getType() == 'boolean') {
        $build[$key] = $value;

        // Add supplementary data to some field types.
        switch ($field_definition
          ->getType()) {
          case 'link':
            $build[$key] = $this
              ->addSupplementaryLinkData($build[$key], $field);
            break;
          case 'image':
          case 'file':
          case 'svg_image_field':
            $build[$key] = $this
              ->addSupplementaryImageData($build[$key], $field);
            break;
        }
      }
    }
  }

  // Flatten array as much as possible.
  if (count($build) == 1) {

    // Pass back single value.
    return reset($build);
  }
  elseif (count($build) == 2 && isset($build['user_id'])) {

    // If site setting is translated, remove meta user_id field.
    unset($build['user_id']);
    return reset($build);
  }
  else {

    // Unable to flatten further, return for array.
    return $build;
  }
}